;******************************************************** ; pokerlogictester.au3 ; Tests logic of pokerlogic.au3 ; Ensures correct hand assignment and points ; By: JFish ; 2015 ;********************************************************/ ; hand tester #include #include #include ;********************************************* ; ["AH","KH","QH","JH","10H"] ; royal flush ; ["9C","8C","7C","6C","5C"] ; straight flush ; ["5D","5C","5H","5S","9D"] ; four of a kind ; ["6D","6C","6H","AC","AD"] ; full house ; ["6D","7D","10D","2D","AD"] ; flush ; ["5D","6H","7C","8S","9D"] ; straight ; ["6D","6H","6C","2S","AD"] ; trips ; ["6D","6S","10D","10H","AC"] ; two pair ; ["3D","3S","10D","4D","JC"] ; one pair ; ["5D","2D","8S","JD","AH"]; high card ;********seven card test hands***************** ; ["AH","KH","QH","JH","10H","3D","8S"] ; royal flush ; ["9C","8C","7C","6C","5C","JS","3H"] ; straight flush ; ["5D","5C","5H","5S","9D","JS","7D"] ; four of a kind ; ["6D","6C","6H","AC","AD","8D","3C"] ; full house ; ["6D","7D","10D","2D","AD","4H",7C"] ; flush ; ["5D","6H","7C","8S","9D","KS","10H"] ; straight ; ["6D","6H","6C","2S","AD","7H","JC"] ; trips ; ["6D","6S","10D","10H","AC","8D","4C"] ; two pair ; ["3D","3S","10D","2D","JC","AC","7S"] ; one pair ; ["5D","2D","8S","JD","AH","7H","KS"]; high card ;********************************************** ; test one of each type of hand with five cards global $oneOfEachFiveCards[10][5]=[["AH","KH","QH","JH","10H"],["9C","8C","7C","6C","5C"],["5D","5C","5H","5S","9D"],["6D","6C","6H","AC","AD"],["6D","7D","10D","2D","AD"],["5D","6H","7C","8S","9D"],["6D","6H","6C","2S","AD"],["6D","6S","10D","10H","AC"],["3D","3S","10D","4D","JC"],["5D","2D","8S","JD","AH"]] ; test one of each type of hand with seven cards global $oneOfEachSevenCards[10][7]=[["AH","KH","QH","JH","10H","3D","8S"],["9C","8C","7C","6C","5C","JS","3H"],["5D","5C","5H","5S","9D","JS","7D"],["6D","6C","6H","AC","AD","8D","3C"],["6D","7D","10D","2D","AD","4H","7C"],["5D","6H","7C","8S","9D","KS","10H"],["6D","6H","6C","2S","AD","7H","JC"],["6D","6S","10D","10H","AC","8D","4C"],["3D","3S","10D","2D","JC","AC","7S"],["5D","2D","8S","JD","AH","7H","KS"]] ; compare hands of same type (i.e. trips, pairs, etc) to make sure scoring is working properly - a mix of 5 and 7 card hands as well global $like_compares_royalflush[3][7]=[["AD","KD","QD","JD","10D","7H","2D"],["KH","JD","QH","6D","10H","JH","AH"],["AC","KC","QC","JC","10C","7C","9C"]] global $like_compares_straightflush[3][7]=[["5D","2D","3D","4D","AD","7H","KD"],["KH","JD","QH","6D","9H","10H","JH"],["5D","6D","7D","8D","AD","7H","9D"]] global $like_compares_straightflush[3][7]=[["5D","2D","3D","4D","AD","7H","KD"],["KH","JD","QH","6D","9H","10H","JH"],["5D","6D","7D","8D","AD","7H","9D"]] global $like_compares_fourofkind[3][5]=[["4H","4D","4C","4S","8H"],["5H","5D","5S","5C","7H"],["5H","5D","5S","5C","JH"]] global $like_compares_fullhouse[3][7]=[["5D","5S","5H","3D","3H","7H","KS"],["KD","KS","KC","6D","6H","6C","9S"],["4D","4H","4S","JD","JH","8H","AS"]] global $like_compares_flush[3][7]=[["5D","2D","8D","JD","AH","7H","KD"],["KH","JD","7H","6D","4H","3H","9H"],["5D","2D","8D","JD","AD","7H","KD"]] global $like_compares_straight[3][7]=[["5D","6D","8S","7D","4H","JH","KS"],["AD","2D","4S","5D","3H","10H","9S"],["AD","QD","KS","JD","10H","8H","4S"]] global $like_compares_trips[4][5]=[["AH","AC","AS","4C","7D"],["2S","2D","2C","8H","JS"],["4H","4S","4H","5H","JD"],["4H","4S","4H","8H","JD"]] global $like_compares_twopairs[4][5]=[["10D","10C","3S","3H","6C"],["5D","5S","2S","2H","KC"],["7H","7S","9D","4S","4C"],["7H","7S","10D","4S","4C"]] global $like_compares_pairs[4][5]=[["4D","4S","7S","8C","JH"],["9H","9D","AS","QC","6S"],["AD","AS","3H","5C","8D"],["AD","AS","3H","9C","8D"]] global $like_compares_highcards[3][7]=[["5D","2D","8S","JD","AH","7H","KS"],["KD","JD","7S","6D","4H","3H","9S"],["9D","QD","7S","5D","3H","8H","AS"]] $testResultsFile=FileOpen(@ScriptDir&"\testresults.txt",2) FileWriteLine($testResultsFile,"The date and time of the test: " & _NowCalc() &@crlf) ;******************************************************* ; The headers are used to write to the console and text file to separate results ;******************************************************** ; headers for all types $fiveCardSectionHeader="*******FIVE CARD TEST********" $sevenCardSectionHeader="*******SEVEN CARD TEST********" ; comparison headers $royalflushcompareHeader="*****COMPARE ROYAL FLUSHES ******" $straightflushcompareHeader="*****COMPARE STRAIGHT FLUSHES ******" $fullhousecompareHeader="*****COMPARE FULL HOUSES ******" $fourofkindcompareHeader="*****COMPARE FOUR OF KIND******" $flushcompareHeader="*******COMPARE FLUSHES**********" $straightcompareHeader="*******COMPARE STRAIGHTS**********" $tripscompareHeader="*******COMPARE TRIPS**********" $twopaircompareHeader="*******COMPARE TWO PAIRS********" $paircompareHeader="*******COMPARE PAIRS********" $highcardcompareHeader="*******COMPARE HIGH CARD********" ;************************************************************** ; a full battery of tests ;************************************************************ ; these first two test one of each hand with either 5 or 7 cards _testFiveCardHands($oneOfEachFiveCards,$fiveCardSectionHeader) _testSevenCardHands($oneOfEachSevenCards,$sevenCardSectionHeader) ;**************************************************************** ; these all compare like hands (i.e. pairs, full houses, etc) so you can check scoring ; some use seven cards and some use five ;****************************************************************** ;_testSevenCardHands($like_compares_royalflush,$royalflushcompareHeader) ;_testSevenCardHands($like_compares_straightflush,$straightflushcompareHeader) ;_testFiveCardHands($like_compares_fourofkind,$fourofkindcompareHeader) ;_testSevenCardHands($like_compares_fullhouse,$fullhousecompareHeader) ;_testSevenCardHands($like_compares_flush,$flushcompareHeader) ;_testSevenCardHands($like_compares_straight,$straightcompareHeader) ;_testFiveCardHands($like_compares_trips,$tripscompareHeader) ;_testFiveCardHands($like_compares_twopairs,$twopaircompareHeader) ;_testFiveCardHands($like_compares_pairs,$paircompareHeader) ;_testSevenCardHands($like_compares_highcards,$highcardcompareHeader) ;******************************************************************** ; Test as many ramdom nands as you want with either 5 or 7 cards. ; first parameter must be 5 or 7. Second parameter is the number ; of random hands to generate and test ;******************************************************************** ;_randomHands(5,100) ; Close the file FileClose($testResultsFile) ; generic function to test any five cards and write to a file and the console func _testFiveCardHands($handsArray,$sectionheader) FileWriteLine($testResultsFile,$sectionheader) consolewrite(@crlf&$sectionheader&@crlf) for $a=0 to UBound($handsArray)-1 global $hand[5]=[$handsArray[$a][0],$handsArray[$a][1],$handsArray[$a][2],$handsArray[$a][3],$handsArray[$a][4]] _evaluatehand($hand) $resultString="This is the test hand: " & $hand[0]&" "&$hand[1]&" "&$hand[2]&" "&$hand[3]&" "&$hand[4] &@crlf & _ $text &@crlf & _ "points: "&$points&@crlf & _ "kicker score: "&$kickerScore&@crlf ConsoleWrite($resultString) FileWrite($testResultsFile,$resultString) Next EndFunc ; generic function to test any seven cards and write to a file and the console func _testSevenCardHands($handsArray,$sectionheader) FileWriteLine($testResultsFile,$sectionheader) consolewrite(@crlf&$sectionheader&@crlf) for $a=0 to UBound($handsArray)-1 global $hand[7]=[$handsArray[$a][0],$handsArray[$a][1],$handsArray[$a][2],$handsArray[$a][3],$handsArray[$a][4],$handsArray[$a][5],$handsArray[$a][6]] _evaluatehand($hand) $resultString="This is the test hand: " & $hand[0]&" "&$hand[1]&" "&$hand[2]&" "&$hand[3]&" "&$hand[4]&" "&$hand[5]&" "&$hand[6] &@crlf & _ $text &@crlf & _ "points: "&$points&@crlf & _ "kicker score: "&$kickerScore&@crlf ConsoleWrite($resultString) FileWrite($testResultsFile,$resultString) Next EndFunc ; this function will let you test as many random hands as you want with either 5 or 7 cards func _randomHands($numCards,$numHands) if $numHands<=0 then MsgBox("","","You need to have at least 1 hand") Else if $numCards <> 5 and $numCards <> 7 Then MsgBox("","","Hands must be 5 or 7 cards") else for $a=1 to $numHands global $hand[$numCards] $shuffleddeck=_shuffleDeck() ;_ArrayDisplay($shuffleddeck) for $cardsinhand=0 to UBound($hand)-1 _ArrayPush($hand,$shuffleddeck[$cardsinhand]) Next ;_ArrayDisplay($hand) if $numCards=5 then _evaluatehand($hand) $resultString="This is the test hand: " & $hand[0]&" "&$hand[1]&" "&$hand[2]&" "&$hand[3]&" "&$hand[4]&@crlf & _ $text &@crlf & _ "points: "&$points&@crlf & _ "kicker score: "&$kickerScore&@crlf ConsoleWrite($resultString) FileWrite($testResultsFile,$resultString) ElseIf $numCards=7 then _evaluatehand($hand) $resultString="This is the test hand: " & $hand[0]&" "&$hand[1]&" "&$hand[2]&" "&$hand[3]&" "&$hand[4]&" "&$hand[5]&" "&$hand[6] &@crlf & _ $text &@crlf & _ "points: "&$points&@crlf & _ "kicker score: "&$kickerScore&@crlf ConsoleWrite($resultString) FileWrite($testResultsFile,$resultString) EndIf Next EndIf EndIf EndFunc ; This function creates and a deck and randomly shuffles it func _shuffleDeck () ; this array has all the cards that will go into a shuffled deck global $cards[52] = ["AH", "KH","QH","JH","10H","9H","8H","7H","6H","5H","4H","3H","2H","AD", "KD","QD","JD","10D","9D","8D","7D","6D","5D","4D","3D","2D","AC","KC","QC","JC","10C","9C","8C","7C","6C","5C","4C","3C","2C","AS","KS","QS","JS","10S","9S","8S","7S","6S","5S","4S","3S","2S"] ; the deck array tha will hold the shuffled cards global $deck[52] dim $counter = 1 while $counter <=52 dim $randomNumber = Random (0,51,1) while _arraySearch ($deck, $cards[$randomNumber]) == -1 _ArrayPush($deck, $cards[$randomNumber],1) $counter = $counter +1 WEnd WEnd return $deck EndFunc