on MouseUp #hand notation like: #1c,2d,3h,4s,13s put field "hand" into tHand put analPoint(thand) into field 2end MouseUp
function analPoint tHand sort items of thand numeric by the char 1 to -2 of each repeat with i=1 to 5 put item i of tHand into th[i] end repeat #we must go in order #https://www.pagat.com/poker/rules/ranking.html ###################### #Straight Flush put true into testsuit repeat with i=2 to 5 if the last char of th[i - 1] is not the last char of th[i] then put false into testsuit end repeat if testsuit then #they have the same suit if checkscale(th) then return "Straight Flush: " & maxcard(th,"Straight Flush") end if end if ############################## #Four of a kind put countDup(th) into duplist repeat for each key tKey in duplist if dupList[tKey] = 4 then return "Four of a kind: " & tKey end repeat ############################### #Full House repeat for each key tKey in duplist if dupList[tKey] = 3 then put tkey into FH3 repeat for each key tKey2 in duplist if dupList[tKey2] = 2 then put tkey2 into FH2 return "Full House: " & FH3 & "." & FH2 end if end repeat end if end repeat ############################################## #Flush if testsuit then sort items of thand descending numeric by the char 1 to -2 of each repeat with i=1 to 5 delete the last char of item i of thand end repeat return "Flush: " & thand end if ##################################################### #Straight if checkscale(th) then return "Straight: " & maxcard(th,"Straight") end if ############################# #Three of a Kind repeat for each key tKey in duplist if dupList[tKey] = 3 then put tkey into FH3 return "Three of a Kind: " & FH3 end if end repeat ############################# #Two Pairs repeat for each key tKey in duplist if dupList[tKey] = 2 then put tkey into P1 put 0 into dupList[tKey] repeat for each key tKey2 in duplist if dupList[tKey2] = 2 then put tkey2 into P2 put P1 & comma & P2 into PT sort items of PT descending numeric return "Two Pairs: " & PT end if end repeat end if end repeat ########################### #Pair repeat for each key tKey in duplist if dupList[tKey] = 2 then return "Two Pairs: " & tKey end if end repeat ############################# #Nothing return "Nothing: " & maxcard(th,"Nothing")end analPoint
function countDup th repeat for each element tele in th add 1 to temp[char 1 to -2 of tele] end repeat return tempend countDup function checkScale th #check if it is a scale if checkace(th) and checkKing(th) then put th into th2 #backup put swapace(th) into th #now aces are 14 in value end if #we need to sort again put sortedArray(th) into th put true into test1 repeat with i=2 to 5 if ((char 1 to -2 of th[i-1]) + 1) is not (char 1 to -2 of th[i]) then put false into test1 end repeat return test1end checkscale
function checkAce th put false into test1 repeat for each element tele in th delete the last char of tele if tele = 1 then put true into test1 end repeat return test1end checkace
function checkKing th put false into test1 repeat for each element tele in th delete the last char of tele if tele = 13 then put true into test1 end repeat return test1end checkKing
function SwapAce th repeat with i=1 to 5 if char 1 to -2 of th[i] = 1 then put 14 into char 1 to -2 of th[i] end repeat return thend SwapAce
function sortedArray @pArray # fetch the keys and sort them using the array entry values get the keys of pArray sort lines of it numeric by char 1 to -2 of pArray[each] split it by return # create a new sorted array using the mapped keys put 1 into tNextIndex repeat for each element tIndex in it put pArray[tIndex] into tSortedArray[tNextIndex] add 1 to tNextIndex end repeat return tSortedArrayend sortedArray
function maxcard th, hType switch htype case "Straight" case "Straight Flush" if checkace(th) and checkKing(th) then return "ACE (14)" else return maxcard2(th) end if break case "Nothing" return maxcard2(th) break end switchend maxcard
function maxcard2 th put 0 into temp repeat for each element tele in th if char 1 to -2 of tele > temp then put char 1 to -2 of tele into temp end repeat return tempend maxcard2