Nothing too complicated in logic but the script is "big"
My purpose was to create a script able to beat a human player most of the times. Winning a 2 out of 3 is not concludent because this can be done simply by "luck".
Here is the challenge: try to beat the computer out of more than 15 games. If you do that, try to repeat the performance ... if you beat it again then you can forget about my script, give me a thumbs-down because I was not good enough at coding this, and give yourself a big pat because you're very good at playing this.
I have attached a zip file because of the icons needed - just unzip them in the same folder and enjoy
Here comes the code:
#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 261, 252, 193, 125) GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close") $PlIm = GUICtrlCreateIcon("", 0, 24, 142, 81, 73, BitOR($SS_NOTIFY,$WS_GROUP)) GUICtrlSetImage (-1, @ScriptDir&"\Choose.ICO") $CmpIm = GUICtrlCreateIcon("", 0, 155, 142, 81, 73, BitOR($SS_NOTIFY,$WS_GROUP)) GUICtrlCreateLabel("Player", 48, 120, 33, 17) GUICtrlCreateLabel("Computer", 170, 120, 49, 17) GUICtrlCreateLabel("Games", 8, 8, 37, 17) $gms_tot = GUICtrlCreateLabel("00", 48, 8, 32, 17, BitOR($SS_CENTER,$SS_SUNKEN)) GUICtrlCreateLabel("Player", 94, 8, 33, 17) $pl_sc = GUICtrlCreateLabel("00", 134, 8, 32, 17, BitOR($SS_CENTER,$SS_SUNKEN)) GUICtrlCreateLabel("Computer", 175, 8, 49, 17) $cmp_sc = GUICtrlCreateLabel("00", 223, 8, 32, 17, BitOR($SS_CENTER,$SS_SUNKEN)) $Button1 = GUICtrlCreateButton("Start", 72, 40, 113, 25, $BS_FLAT + $BS_DEFPUSHBUTTON) GUICtrlSetOnEvent(-1, "Button1Click") $Button2 = GUICtrlCreateButton("", 56, 80, 30, 30,$BS_ICON) GUICtrlSetImage (-1, @ScriptDir&"\rocksml.ICO") GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlSetOnEvent(-1, "Button2Click") $Button3 = GUICtrlCreateButton("", 116, 80, 30, 30, $BS_ICON) GUICtrlSetImage (-1, @ScriptDir&"\papersml.ICO") GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlSetOnEvent(-1, "Button3Click") $Button4 = GUICtrlCreateButton("", 172, 80, 30, 30, $BS_ICON) GUICtrlSetImage (-1, @ScriptDir&"\scissorsml.ICO") GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlSetOnEvent(-1, "Button4Click") $Label9 = GUICtrlCreateLabel("", 96, 224, 99, 20) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $pl[500] Global $gms = 0, $plw = 0, $cmpw = 0 Global $counter = 0, $timer = 4 Global $p_ready = 0, $started = 0 Global $seq[3][3] While 1 Sleep(200) If $p_ready = 0 And $started = 1 Then Rotate() EndIf WEnd Func Button1Click() $started = 1 $timer = 4 GUICtrlSetState($Button1, $GUI_DISABLE) GUICtrlSetState($Button2, $GUI_ENABLE) GUICtrlSetState($Button3, $GUI_ENABLE) GUICtrlSetState($Button4, $GUI_ENABLE) GUICtrlSetImage ($PlIm, @ScriptDir&"\Choose.ICO") GUICtrlSetData($Label9, "Waiting ...") EndFunc Func Button2Click() $p_ready = 1 $pl[$gms] = 0 GUICtrlSetImage ($PlIm, @ScriptDir&"\rocksml.ICO") GUICtrlSetState($Button1, $GUI_ENABLE) GUICtrlSetData($Button1, "Start") CompMove() $p_ready = 0 $started = 0 $timer = 4 EndFunc Func Button3Click() $p_ready = 1 $pl[$gms] = 1 GUICtrlSetImage ($PlIm, @ScriptDir&"\papersml.ICO") GUICtrlSetState($Button1, $GUI_ENABLE) GUICtrlSetData($Button1, "Start") CompMove() $p_ready = 0 $started = 0 $timer = 4 EndFunc Func Button4Click() $p_ready = 1 $pl[$gms] = 2 GUICtrlSetImage ($PlIm, @ScriptDir&"\scissorsml.ICO") GUICtrlSetState($Button1, $GUI_ENABLE) GUICtrlSetData($Button1, "Start") CompMove() $p_ready = 0 $started = 0 $timer = 4 EndFunc Func Form1Close() Exit EndFunc Func CompMove() GUICtrlSetState($Button2, $GUI_DISABLE) GUICtrlSetState($Button3, $GUI_DISABLE) GUICtrlSetState($Button4, $GUI_DISABLE) If $gms >1 Then _Record() EndIf Select Case $gms = 0 If Int(Random(1,2)) = 1 Then GUICtrlSetImage ($CmpIm, @ScriptDir&"\rocksml.ICO") Local $cpl = 0 Local $reslt = _CompareRes($pl[$gms], $cpl) Switch $reslt Case 0 GUICtrlSetData($Label9, "Nobody Won") _Update("0") Case 1 GUICtrlSetData($Label9, "Player Win") _Update("1") Case 2 GUICtrlSetData($Label9, "Computer Win") _Update("2") EndSwitch Else GUICtrlSetImage ($CmpIm, @ScriptDir&"\papersml.ICO") Local $cpl = 1 Local $reslt = _CompareRes($pl[$gms], $cpl) Switch $reslt Case 0 GUICtrlSetData($Label9, "Nobody Won") _Update("0") Case 1 GUICtrlSetData($Label9, "Player Win") _Update("1") Case 2 GUICtrlSetData($Label9, "Computer Win") _Update("2") EndSwitch EndIf Case $gms >= 1 And $gms < 3 Switch Int(Random(0,2)) Case 0 GUICtrlSetImage ($CmpIm, @ScriptDir&"\rocksml.ICO") Local $cpl = 0 Local $reslt = _CompareRes($pl[$gms], $cpl) Switch $reslt Case 0 GUICtrlSetData($Label9, "Nobody Won") _Update("0") Case 1 GUICtrlSetData($Label9, "Player Win") _Update("1") Case 2 GUICtrlSetData($Label9, "Computer Win") _Update("2") EndSwitch Case 1 GUICtrlSetImage ($CmpIm, @ScriptDir&"\papersml.ICO") Local $cpl = 1 Local $reslt = _CompareRes($pl[$gms], $cpl) Switch $reslt Case 0 GUICtrlSetData($Label9, "Nobody Won") _Update("0") Case 1 GUICtrlSetData($Label9, "Player Win") _Update("1") Case 2 GUICtrlSetData($Label9, "Computer Win") _Update("2") EndSwitch Case 2 GUICtrlSetImage ($CmpIm, @ScriptDir&"\scissorsml.ICO") Local $cpl = 2 Local $reslt = _CompareRes($pl[$gms], $cpl) Switch $reslt Case 0 GUICtrlSetData($Label9, "Nobody Won") _Update("0") Case 1 GUICtrlSetData($Label9, "Player Win") _Update("1") Case 2 GUICtrlSetData($Label9, "Computer Win") _Update("2") EndSwitch EndSwitch Case Else If $pl[$gms - 2] = $pl[$gms - 1] Then Switch $pl[$gms - 2] Case 0 GUICtrlSetImage ($CmpIm, @ScriptDir&"\papersml.ICO") Local $cpl = 1 Local $reslt = _CompareRes($pl[$gms], $cpl) Switch $reslt Case 0 GUICtrlSetData($Label9, "Nobody Won") _Update("0") Case 1 GUICtrlSetData($Label9, "Player Win") _Update("1") Case 2 GUICtrlSetData($Label9, "Computer Win") _Update("2") EndSwitch Case 1 GUICtrlSetImage ($CmpIm, @ScriptDir&"\scissorsml.ICO") Local $cpl = 2 Local $reslt = _CompareRes($pl[$gms], $cpl) Switch $reslt Case 0 GUICtrlSetData($Label9, "Nobody Won") _Update("0") Case 1 GUICtrlSetData($Label9, "Player Win") _Update("1") Case 2 GUICtrlSetData($Label9, "Computer Win") _Update("2") EndSwitch Case 2 GUICtrlSetImage ($CmpIm, @ScriptDir&"\rocksml.ICO") Local $cpl = 0 Local $reslt = _CompareRes($pl[$gms], $cpl) Switch $reslt Case 0 GUICtrlSetData($Label9, "Nobody Won") _Update("0") Case 1 GUICtrlSetData($Label9, "Player Win") _Update("1") Case 2 GUICtrlSetData($Label9, "Computer Win") _Update("2") EndSwitch EndSwitch Else Switch $pl[$gms -1] Case 0 Select Case _Max2N($seq[0][0], $seq[0][1]) = "1" Select Case _Max2N($seq[0][0], $seq[0][2]) = "1" GUICtrlSetImage ($CmpIm, @ScriptDir&"\papersml.ICO") Local $cpl = 1 Local $reslt = _CompareRes($pl[$gms], $cpl) Switch $reslt Case 0 GUICtrlSetData($Label9, "Nobody Won") _Update("0") Case 1 GUICtrlSetData($Label9, "Player Win") _Update("1") Case 2 GUICtrlSetData($Label9, "Computer Win") _Update("2") EndSwitch ;pl 1 Case _Max2N($seq[0][0], $seq[0][2]) = "2" GUICtrlSetImage ($CmpIm, @ScriptDir&"\rocksml.ICO") Local $cpl = 0 Local $reslt = _CompareRes($pl[$gms], $cpl) Switch $reslt Case 0 GUICtrlSetData($Label9, "Nobody Won") _Update("0") Case 1 GUICtrlSetData($Label9, "Player Win") _Update("1") Case 2 GUICtrlSetData($Label9, "Computer Win") _Update("2") EndSwitch;pl 0 Case _Max2N($seq[0][0], $seq[0][2]) = "0" GUICtrlSetImage ($CmpIm, @ScriptDir&"\papersml.ICO") Local $cpl = 1 Local $reslt = _CompareRes($pl[$gms], $cpl) Switch $reslt Case 0 GUICtrlSetData($Label9, "Nobody Won") _Update("0") Case 1 GUICtrlSetData($Label9, "Player Win") _Update("1") Case 2 GUICtrlSetData($Label9, "Computer Win") _Update("2") EndSwitch;pl 1 EndSelect Case _Max2N($seq[0][0], $seq[0][1]) = "2" Select Case _Max2N($seq[0][1], $seq[0][2]) = "1" GUICtrlSetImage ($CmpIm, @ScriptDir&"\scissorsml.ICO") Local $cpl = 2 Local $reslt = _CompareRes($pl[$gms], $cpl) Switch $reslt Case 0 GUICtrlSetData($Label9, "Nobody Won") _Update("0") Case 1 GUICtrlSetData($Label9, "Player Win") _Update("1") Case 2 GUICtrlSetData($Label9, "Computer Win") _Update("2") EndSwitch;pl 2 Case _Max2N($seq[0][1], $seq[0][2]) = "2" GUICtrlSetImage ($CmpIm, @ScriptDir&"\rocksml.ICO") Local $cpl = 0 Local $reslt = _CompareRes($pl[$gms], $cpl) Switch $reslt Case 0 GUICtrlSetData($Label9, "Nobody Won") _Update("0") Case 1 GUICtrlSetData($Label9, "Player Win") _Update("1") Case 2 GUICtrlSetData($Label9, "Computer Win") _Update("2") EndSwitch;pl 0 Case _Max2N($seq[0][1], $seq[0][2]) = "0" GUICtrlSetImage ($CmpIm, @ScriptDir&"\papersml.ICO") Local $cpl = 1 Local $reslt = _CompareRes($pl[$gms], $cpl) Switch $reslt Case 0 GUICtrlSetData($Label9, "Nobody Won") _Update("0") Case 1 GUICtrlSetData($Label9, "Player Win") _Update("1") Case 2 GUICtrlSetData($Label9, "Computer Win") _Update("2") EndSwitch;pl 1 EndSelect Case _Max2N($seq[0][0], $seq[0][1]) = "0" Select Case _Max2N($seq[0][1], $seq[0][2]) = "2" GUICtrlSetImage ($CmpIm, @ScriptDir&"\rocksml.ICO") Local $cpl = 0 Local $reslt = _CompareRes($pl[$gms], $cpl) Switch $reslt Case 0 GUICtrlSetData($Label9, "Nobody Won") _Update("0") Case 1 GUICtrlSetData($Label9, "Player Win") _Update("1") Case 2 GUICtrlSetData($Label9, "Computer Win") _Update("2") EndSwitch;pl 0 Case Else GUICtrlSetImage ($CmpIm, @ScriptDir&"\papersml.ICO") Local $cpl = 1 Local $reslt = _CompareRes($pl[$gms], $cpl) Switch $reslt Case 0 GUICtrlSetData($Label9, "Nobody Won") _Update("0") Case 1 GUICtrlSetData($Label9, "Player Win") _Update("1") Case 2 GUICtrlSetData($Label9, "Computer Win") _Update("2") EndSwitch;pl 1 EndSelect EndSelect Case 1 Select Case _Max2N($seq[1][0], $seq[1][1]) = "1" Select Case _Max2N($seq[1][0], $seq[1][2]) = "1" GUICtrlSetImage ($CmpIm, @ScriptDir&"\papersml.ICO") Local $cpl = 1 Local $reslt = _CompareRes($pl[$gms], $cpl) Switch $reslt Case 0 GUICtrlSetData($Label9, "Nobody Won") _Update("0") Case 1 GUICtrlSetData($Label9, "Player Win") _Update("1") Case 2 GUICtrlSetData($Label9, "Computer Win") _Update("2") EndSwitch;pl 1 Case _Max2N($seq[1][0], $seq[1][2]) = "2" GUICtrlSetImage ($CmpIm, @ScriptDir&"\rocksml.ICO") Local $cpl = 0 Local $reslt = _CompareRes($pl[$gms], $cpl) Switch $reslt Case 0 GUICtrlSetData($Label9, "Nobody Won") _Update("0") Case 1 GUICtrlSetData($Label9, "Player Win") _Update("1") Case 2 GUICtrlSetData($Label9, "Computer Win") _Update("2") EndSwitch;pl 0 Case _Max2N($seq[1][0], $seq[1][2]) = "0" GUICtrlSetImage ($CmpIm, @ScriptDir&"\scissorsml.ICO") Local $cpl = 2 Local $reslt = _CompareRes($pl[$gms], $cpl) Switch $reslt Case 0 GUICtrlSetData($Label9, "Nobody Won") _Update("0") Case 1 GUICtrlSetData($Label9, "Player Win") _Update("1") Case 2 GUICtrlSetData($Label9, "Computer Win") _Update("2") EndSwitch;pl 2 EndSelect Case _Max2N($seq[1][0], $seq[1][1]) = "2" Select Case _Max2N($seq[1][1], $seq[1][2]) = "1" GUICtrlSetImage ($CmpIm, @ScriptDir&"\scissorsml.ICO") Local $cpl = 2 Local $reslt = _CompareRes($pl[$gms], $cpl) Switch $reslt Case 0 GUICtrlSetData($Label9, "Nobody Won") _Update("0") Case 1 GUICtrlSetData($Label9, "Player Win") _Update("1") Case 2 GUICtrlSetData($Label9, "Computer Win") _Update("2") EndSwitch;pl 2 Case _Max2N($seq[1][1], $seq[1][2]) = "2" GUICtrlSetImage ($CmpIm, @ScriptDir&"\rocksml.ICO") Local $cpl = 0 Local $reslt = _CompareRes($pl[$gms], $cpl) Switch $reslt Case 0 GUICtrlSetData($Label9, "Nobody Won") _Update("0") Case 1 GUICtrlSetData($Label9, "Player Win") _Update("1") Case 2 GUICtrlSetData($Label9, "Computer Win") _Update("2") EndSwitch;pl 0 Case _Max2N($seq[1][1], $seq[1][2]) = "0" GUICtrlSetImage ($CmpIm, @ScriptDir&"\scissorsml.ICO") Local $cpl = 2 Local $reslt = _CompareRes($pl[$gms], $cpl) Switch $reslt Case 0 GUICtrlSetData($Label9, "Nobody Won") _Update("0") Case 1 GUICtrlSetData($Label9, "Player Win") _Update("1") Case 2 GUICtrlSetData($Label9, "Computer Win") _Update("2") EndSwitch;pl 2 EndSelect Case _Max2N($seq[1][0], $seq[1][1]) = "0" Select Case _Max2N($seq[1][1], $seq[1][2]) = "2" GUICtrlSetImage ($CmpIm, @ScriptDir&"\rocksml.ICO") Local $cpl = 0 Local $reslt = _CompareRes($pl[$gms], $cpl) Switch $reslt Case 0 GUICtrlSetData($Label9, "Nobody Won") _Update("0") Case 1 GUICtrlSetData($Label9, "Player Win") _Update("1") Case 2 GUICtrlSetData($Label9, "Computer Win") _Update("2") EndSwitch;pl 0 Case Else GUICtrlSetImage ($CmpIm, @ScriptDir&"\scissorsml.ICO") Local $cpl = 2 Local $reslt = _CompareRes($pl[$gms], $cpl) Switch $reslt Case 0 GUICtrlSetData($Label9, "Nobody Won") _Update("0") Case 1 GUICtrlSetData($Label9, "Player Win") _Update("1") Case 2 GUICtrlSetData($Label9, "Computer Win") _Update("2") EndSwitch;pl 2 EndSelect EndSelect Case 2 Select Case _Max2N($seq[2][0], $seq[2][1]) = "1" Select Case _Max2N($seq[2][0], $seq[2][2]) = "1" GUICtrlSetImage ($CmpIm, @ScriptDir&"\papersml.ICO") Local $cpl = 1 Local $reslt = _CompareRes($pl[$gms], $cpl) Switch $reslt Case 0 GUICtrlSetData($Label9, "Nobody Won") _Update("0") Case 1 GUICtrlSetData($Label9, "Player Win") _Update("1") Case 2 GUICtrlSetData($Label9, "Computer Win") _Update("2") EndSwitch;pl 1 Case _Max2N($seq[2][0], $seq[2][2]) = "2" GUICtrlSetImage ($CmpIm, @ScriptDir&"\rocksml.ICO") Local $cpl = 0 Local $reslt = _CompareRes($pl[$gms], $cpl) Switch $reslt Case 0 GUICtrlSetData($Label9, "Nobody Won") _Update("0") Case 1 GUICtrlSetData($Label9, "Player Win") _Update("1") Case 2 GUICtrlSetData($Label9, "Computer Win") _Update("2") EndSwitch;pl 0 Case _Max2N($seq[2][0], $seq[2][2]) = "0" GUICtrlSetImage ($CmpIm, @ScriptDir&"\rocksml.ICO") Local $cpl = 0 Local $reslt = _CompareRes($pl[$gms], $cpl) Switch $reslt Case 0 GUICtrlSetData($Label9, "Nobody Won") _Update("0") Case 1 GUICtrlSetData($Label9, "Player Win") _Update("1") Case 2 GUICtrlSetData($Label9, "Computer Win") _Update("2") EndSwitch;pl 0 EndSelect Case _Max2N($seq[2][0], $seq[2][1]) = "2" Select Case _Max2N($seq[2][1], $seq[2][2]) = "1" GUICtrlSetImage ($CmpIm, @ScriptDir&"\scissorsml.ICO") Local $cpl = 2 Local $reslt = _CompareRes($pl[$gms], $cpl) Switch $reslt Case 0 GUICtrlSetData($Label9, "Nobody Won") _Update("0") Case 1 GUICtrlSetData($Label9, "Player Win") _Update("1") Case 2 GUICtrlSetData($Label9, "Computer Win") _Update("2") EndSwitch;pl 2 Case _Max2N($seq[2][1], $seq[2][2]) = "2" GUICtrlSetImage ($CmpIm, @ScriptDir&"\rocksml.ICO") Local $cpl = 0 Local $reslt = _CompareRes($pl[$gms], $cpl) Switch $reslt Case 0 GUICtrlSetData($Label9, "Nobody Won") _Update("0") Case 1 GUICtrlSetData($Label9, "Player Win") _Update("1") Case 2 GUICtrlSetData($Label9, "Computer Win") _Update("2") EndSwitch;pl 0 Case _Max2N($seq[2][1], $seq[2][2]) = "0" GUICtrlSetImage ($CmpIm, @ScriptDir&"\rocksml.ICO") Local $cpl = 0 Local $reslt = _CompareRes($pl[$gms], $cpl) Switch $reslt Case 0 GUICtrlSetData($Label9, "Nobody Won") _Update("0") Case 1 GUICtrlSetData($Label9, "Player Win") _Update("1") Case 2 GUICtrlSetData($Label9, "Computer Win") _Update("2") EndSwitch;pl 0 EndSelect Case _Max2N($seq[2][0], $seq[2][1]) = "0" Select Case _Max2N($seq[2][1], $seq[2][2]) = "2" GUICtrlSetImage ($CmpIm, @ScriptDir&"\rocksml.ICO") Local $cpl = 0 Local $reslt = _CompareRes($pl[$gms], $cpl) Switch $reslt Case 0 GUICtrlSetData($Label9, "Nobody Won") _Update("0") Case 1 GUICtrlSetData($Label9, "Player Win") _Update("1") Case 2 GUICtrlSetData($Label9, "Computer Win") _Update("2") EndSwitch;pl 0 Case Else GUICtrlSetImage ($CmpIm, @ScriptDir&"\rocksml.ICO") Local $cpl = 0 Local $reslt = _CompareRes($pl[$gms], $cpl) Switch $reslt Case 0 GUICtrlSetData($Label9, "Nobody Won") _Update("0") Case 1 GUICtrlSetData($Label9, "Player Win") _Update("1") Case 2 GUICtrlSetData($Label9, "Computer Win") _Update("2") EndSwitch;pl 0 EndSelect EndSelect EndSwitch EndIf EndSelect EndFunc Func Rotate () If $timer > 0 Then $timer = $timer - 0.2 EndIf If $counter = 3 Then $counter = 0 $counter +=1 Switch $counter Case 1 GUICtrlSetImage ($CmpIm, @ScriptDir&"\rocksml.ICO") Case 2 GUICtrlSetImage ($CmpIm, @ScriptDir&"\papersml.ICO") Case 3 GUICtrlSetImage ($CmpIm, @ScriptDir&"\scissorsml.ICO") EndSwitch GUICtrlSetData($Button1, "Time left " &Int($timer)) If $timer <= 0 Then GUICtrlSetState($Button1, $GUI_ENABLE) GUICtrlSetData($Button1, "Start") GUICtrlSetData($Label9, "Null Game") $started = 0 EndIf EndFunc Func _CompareRes($plr, $cmp) Select Case $plr = 0 And $cmp = 0 Return 0 ;tie Case $plr = 0 And $cmp = 1 Return 2 ;c win Case $plr = 0 And $cmp = 2 Return 1 ;p win Case $plr = 1 And $cmp = 0 Return 1 Case $plr = 1 And $cmp = 1 Return 0 Case $plr = 1 And $cmp = 2 Return 2 Case $plr = 2 And $cmp = 0 Return 2 ;tie Case $plr = 2 And $cmp = 1 Return 1 ;c win Case $plr = 2 And $cmp = 2 Return 0 EndSelect EndFunc Func _Record() $a = $pl[$gms - 1] $b = $pl[$gms] $seq[$a][$b] += 1 EndFunc Func _Update($who) $gms += 1 GUICtrlSetData($gms_tot, $gms) Switch $who Case 0 Case 1 GUICtrlSetData($pl_sc, GUICtrlRead($pl_sc) + 1) Case 2 GUICtrlSetData($cmp_sc, GUICtrlRead($cmp_sc) + 1) EndSwitch EndFunc Func _Max2N($a1, $a2) Local $max = "" If $a1 > $a2 Then $max = "1" ElseIf $a2 > $a1 Then $max = "2" Else $max = "0" EndIf Return $max EndFunc
RPS.zip 15.91KB
281 downloads






