Poker Hand Assessor

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9287
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Poker Hand Assessor

Post by richmond62 » Tue Mar 06, 2018 5:37 pm


bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Poker Hand Assessor

Post by bogs » Tue Mar 06, 2018 10:39 pm

Nice and straight forward solution Richmond.
Image

MaxV
Posts: 1579
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: Poker Hand Assessor

Post by MaxV » Wed Aug 29, 2018 11:45 am

Nice, but the suits? (clubs, diamond, hearts, and spades)
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9287
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Poker Hand Assessor

Post by richmond62 » Wed Aug 29, 2018 11:46 am

Nice, but
Download it and hack it. 8)

MaxV
Posts: 1579
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: Poker Hand Assessor

Post by MaxV » Wed Aug 29, 2018 12:04 pm

richmond62 wrote:
Wed Aug 29, 2018 11:46 am
Nice, but
Download it and hack it. 8)
OK :D
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

MaxV
Posts: 1579
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: Poker Hand Assessor

Post by MaxV » Wed Aug 29, 2018 2:40 pm

Here my poker library:

########CODE to copy and paste with your mouse#######
on MouseUp
#hand notation like:
#1c,2d,3h,4s,13s
put field "hand" into tHand
put analPoint(thand) into field 2
end 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 temp
end 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 test1
end 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 test1
end 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 test1
end 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 th
end 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 tSortedArray
end 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 switch
end 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 temp
end maxcard2
########END OF CODE generated by this livecode app: http://tinyurl.com/j8xf3xq ########
########Code tested with livecode 9.0.0########
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”