Jump to content



Photo

Paper-Scissor-Rock ... heh another one


  • Please log in to reply
8 replies to this topic

#1 enaiman

enaiman

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 1,922 posts

Posted 27 August 2008 - 02:59 AM

Well this is my Paper-Scissor-Rock script. I felt challenged by the idea and here is the result.
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:

AutoIt         
#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


Attached File  RPS.zip   15.91KB   281 downloads

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)








#2 Andreik

Andreik

    Bishop

  • Active Members
  • PipPipPipPipPipPip
  • 2,503 posts

Posted 27 August 2008 - 10:19 AM

I like it. Nice design. ;)
When the words fail... music speaks

#3 rasim

rasim

    Gray Scripter

  • Active Members
  • PipPipPipPipPipPip
  • 1,708 posts

Posted 27 August 2008 - 10:48 AM

enaiman
Very nice, my friend. I like it. ;)
OS: Windows XP SP3, AutoIt version: 3.3.0.0Posted Image My Projects: Free_Resources | Splitter | wgetGUI | UnRARIt | USBMon | CDROM-Control | Volume Serial Changer | WinTrayPosted Image My UDFs: _ScreenSetting | ListView_Progress | ContextHelp | ToolTip_UDF | UnRAR | Zip32 | BassMod | ShellTreeView | GuiHotKey | 7ZipPosted Image My Examples: TrayIcon_Click | SystemTray_Refresh | _ListView_Sort | CPUmonLike above scripts? Please rate the topic Posted Image

#4 enaiman

enaiman

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 1,922 posts

Posted 27 August 2008 - 10:52 PM

Thank you very much for your comments rasim and Andreik ;) I really appreciate.

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)


#5 Fr3shY

Fr3shY

    Seeker

  • Active Members
  • 12 posts

Posted 02 September 2008 - 12:09 PM

Nice program. Tried playing it, but got destroyed by the CP.

Good work, keep it up ;)

~Fr3shY

#6 AlucardTnuoc

AlucardTnuoc

    Seeker

  • New Members
  • 2 posts

Posted 30 September 2008 - 12:03 AM

Do you want us to win more then 15 times, or beat him say 8 to 7,

#7 enaiman

enaiman

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 1,922 posts

Posted 30 September 2008 - 02:12 AM

Anything is good :)

If computer's moves would have been random then the winning chance would be 33%, tie - 33% and lose - 33%. If you beat it 8 to 7 then its winning percentage will be better than the previous 33% = my script's purpose is fulfilled >_<
I've been playing with it for a while and I've got beaten everytime the number of games was big enough (usually over 20 games).

It can be beaten if the code is analized and a careful sequence of moves is built before playing the game (I made this script but I doubt I can be able to write such a sequence).
Anyway, good luck :idiot:

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)


#8 pieeater

pieeater

    Prodigy

  • Active Members
  • PipPipPip
  • 184 posts

Posted 10 May 2011 - 12:42 AM

ahh this gave me a headache trying to beat it, awesome job :unsure: i had it in a pattern at game 40 but that was to late:(
Spoiler

#9 enaiman

enaiman

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 1,922 posts

Posted 10 May 2011 - 05:36 AM

hehe :unsure: glad you liked it :>

You can see from the script that it's nothing fancy and nothing advanced. Just tried to prevent the user from playing the same thing over and over again.
Of course you can "spot" the behaviour, it takes some pretty good effort to guess how it's going to play (that was my job to make it more difficult) ;)

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users