youknowwho4eva Posted August 25, 2008 Share Posted August 25, 2008 I created a nifty rock paper scissors game, thought I would share my latest results. FYI the O is rock, the -- is paper, and the X is scissors. and instead of Rock Paper Scissors Shot, or 123 shot, its Ready Set Shot. See if you can beat it 2 out of 3. I know most of the #includes are not needed, I just always use a bunch of them so i don't have to worry about having the right ones in there. I know the math looks random but there is a method to the madness, kinda.expandcollapse popup#include <GUIConstantsEx.au3> #include <ButtonConstants.au3> #Include <GuiListView.au3> #Include <GuiListBox.au3> #include <ListboxConstants.au3> #include <WindowsConstants.au3> #include <Array.au3> #Include <File.au3> #include <Inet.au3> #Include <GuiButton.au3> #Include <Misc.au3> $compi = @HOUR $compi2 = @MIN / 3 $compi3 = @SEC $prev = "" GUICreate("Rock Paper Scissors", 150, 200) $Prompt = GUICtrlCreateLabel("Are you ready?", 40, 30) $start = GUICtrlCreateButton("Start!!", 50, 50, 50, 20) $r = GUICtrlCreateButton("O", 20, 75, 30, 20) $p = GUICtrlCreateButton("--", 60, 75, 30, 20) $x = GUICtrlCreateButton("X", 100, 75, 30, 20) GUISetState(@sw_show) While 1 $msg = GUIGetMsg() Select Case $msg = $start $comptest = ($compi + $compi2)/$compi3 If $comptest < -1 or $comptest = @error Then $comp = "Paper " ElseIf $comptest > 1 Then $comp = "Rock " ElseIf $comptest > -1 and $comptest < 1 Then $comp = "Scissors" EndIf GUICtrlSetData($prompt, "Ready!!") GUICtrlSetPos($Prompt, 55, 30) Sleep(2000) GUICtrlSetData($prompt, "Set!!") GUICtrlSetPos($Prompt, 65, 30) Sleep(3000) GUICtrlSetData($prompt, "Shot!!") GUICtrlSetPos($Prompt, 60, 30) $time = @SEC + 2 Do $msg = GUIGetMsg() If $msg = $x Then GUICtrlCreateLabel("Player picked: Scissors", 20, 100) GUICtrlCreateLabel("Computer picked: " & $comp, 20, 130) Select Case $comp = "Rock " $compi = $compi - 1 Case $comp = "Scissors" $compi = $compi - 1 Case $comp = "Paper " $compi = $compi + 2 Case $prev = "Rock " $compi2 = $compi2 - 1 Case $prev = "Scissors" $compi2 = $compi2 - 1 Case $prev = "Paper " $compi2 = $compi2 + 2 EndSelect $compi3 = 1 $prev = "Scissors" ElseIf $msg = $p Then GUICtrlCreateLabel("Player picked: Paper ", 20, 100) GUICtrlCreateLabel("Computer picked: " & $comp, 20, 130) Select Case $comp = "Rock " $compi = $compi - 1 Case $comp = "Scissors" $compi = $compi - 2 Case $comp = "Paper " $compi = $compi + 2 Case $prev = "Rock " $compi2 = $compi2 - 1 Case $prev = "Scissors" $compi2 = $compi2 - 1 Case $prev = "Paper " $compi2 = $compi2 + 2 EndSelect $compi3 = 2 $prev = "Paper " ElseIf $msg = $r Then GUICtrlCreateLabel("Player picked: Rock ", 20, 100) GUICtrlCreateLabel("Computer picked: " & $comp, 20, 130) Select Case $comp = "Rock " $compi = $compi - 1 Case $comp = "Scissors" $compi = $compi - 2 Case $comp = "Paper " $compi = $compi + 2 Case $prev = "Rock " $compi2 = $compi2 - 1 Case $prev = "Scissors" $compi2 = $compi2 - 1 Case $prev = "Paper " $compi2 = $compi2 + 2 EndSelect $compi3 = .5 $prev = "Rock " EndIf Until $msg = $x or $msg = $p or $msg = $r or $time = @SEC If $time = @SEC Then MsgBox (0, "Time","Times Up") EndIf GUICtrlSetData($prompt, "Are you ready?") GUICtrlSetPos($prompt, 40,30) Case $msg = $gui_event_close Exit EndSelect WEnd Giggity Link to comment Share on other sites More sharing options...
Andreik Posted August 25, 2008 Share Posted August 25, 2008 You can add a label and write who is winner. When the words fail... music speaks. Link to comment Share on other sites More sharing options...
youknowwho4eva Posted August 25, 2008 Author Share Posted August 25, 2008 (edited) I was planning on maybe putting a "I win 2 of 3" or "You win 2 of 3" also, I didn't do a bunch of testing after changing the beginning to base the first move off of the time.... I shoulda tested to see if that causes issues in the accuracy of the guess of your next move. How'd it fair against you? Edit: I just changed the beginning to $compi = @HOUR/24 $compi2 = @MIN/60 $compi3 = @SEC/60 and it beat me 8 of 10 with 2 ties Edited August 25, 2008 by youknowwho4eva Giggity Link to comment Share on other sites More sharing options...
youknowwho4eva Posted August 25, 2008 Author Share Posted August 25, 2008 expandcollapse popup#include <GUIConstantsEx.au3> #include <ButtonConstants.au3> #Include <GuiListView.au3> #Include <GuiListBox.au3> #include <ListboxConstants.au3> #include <WindowsConstants.au3> #include <Array.au3> #Include <File.au3> #include <Inet.au3> #Include <GuiButton.au3> #Include <Misc.au3> $cturn = 0 $pturn = 0 $compi = @HOUR/24 $compi2 = @MIN/60 $compi3 = @SEC/60 $prev = "" GUICreate("Rock Paper Scissors", 150, 200) $Prompt = GUICtrlCreateLabel("Are you ready?", 40, 30) $start = GUICtrlCreateButton("Start!!", 50, 50, 50, 20) $r = GUICtrlCreateButton("O", 20, 75, 30, 20) $p = GUICtrlCreateButton("--", 60, 75, 30, 20) $x = GUICtrlCreateButton("X", 100, 75, 30, 20) $player = GUICtrlCreateLabel(" ", 10, 100) $computer = GUICtrlCreateLabel(" ", 10, 115) $results = GUICtrlCreateLabel(" ", 20, 130) GUISetState(@sw_show) While 1 $msg = GUIGetMsg() Select Case $msg = $start $comptest = ($compi + $compi2)/$compi3 If $comptest < -1 or $comptest = @error Then $comp = "Paper " ElseIf $comptest > 1 Then $comp = "Rock " ElseIf $comptest > -1 and $comptest < 1 Then $comp = "Scissors" EndIf GUICtrlSetData($prompt, "Ready!!") GUICtrlSetPos($Prompt, 55, 30) Sleep(2000) GUICtrlSetData($prompt, "Set!!") GUICtrlSetPos($Prompt, 65, 30) Sleep(3000) GUICtrlSetData($prompt, "Shot!!") GUICtrlSetPos($Prompt, 60, 30) $time = @SEC + 2 Do $msg = GUIGetMsg() If $msg = $x Then GUICtrlSetData($player,"Player picked: Scissors") GUICtrlSetData($computer,"Computer picked: " & $comp) Select Case $comp = "Rock " $compi = $compi - 1 Case $comp = "Scissors" $compi = $compi - 1 Case $comp = "Paper " $compi = $compi + 2 Case $prev = "Rock " $compi2 = $compi2 - 1 Case $prev = "Scissors" $compi2 = $compi2 - 1 Case $prev = "Paper " $compi2 = $compi2 + 2 EndSelect $compi3 = 1 $prev = "Scissors" If $comp = "Scissors" Then GUICtrlSetData($results, "Tie") ElseIf $comp = "Rock " Then $cturn = $cturn + 1 GUICtrlSetData($results, "I get 1") Else $pturn = $pturn + 1 GUICtrlSetData($results, "Dang you got 1") EndIf ElseIf $msg = $p Then GUICtrlSetData($player, "Player picked: Paper ") GUICtrlSetData($computer, "Computer picked: " & $comp) Select Case $comp = "Rock " $compi = $compi - 1 Case $comp = "Scissors" $compi = $compi - 2 Case $comp = "Paper " $compi = $compi + 2 Case $prev = "Rock " $compi2 = $compi2 - 1 Case $prev = "Scissors" $compi2 = $compi2 - 1 Case $prev = "Paper " $compi2 = $compi2 + 2 EndSelect $compi3 = 2 $prev = "Paper " If $comp = "Paper " Then GUICtrlSetData($results, "Tie") ElseIf $comp = "Scissors" Then $cturn = $cturn + 1 GUICtrlSetData($results, "I get 1") Else $pturn = $pturn + 1 GUICtrlSetData($results, "Dang you got 1") EndIf ElseIf $msg = $r Then GUICtrlSetData($player, "Player picked: Rock ") GUICtrlSetData($computer, "Computer picked: " & $comp) Select Case $comp = "Rock " $compi = $compi - 1 Case $comp = "Scissors" $compi = $compi - 2 Case $comp = "Paper " $compi = $compi + 2 Case $prev = "Rock " $compi2 = $compi2 - 1 Case $prev = "Scissors" $compi2 = $compi2 - 1 Case $prev = "Paper " $compi2 = $compi2 + 2 EndSelect $compi3 = .5 $prev = "Rock " If $comp = "Rock " Then GUICtrlSetData($results, "Tie") ElseIf $comp = "Paper " Then $cturn = $cturn + 1 GUICtrlSetData($results, "I get 1") Else $pturn = $pturn + 1 GUICtrlSetData($results, "Dang you got 1") EndIf EndIf Until $msg = $x or $msg = $p or $msg = $r or $time = @SEC If $cturn = 2 Then GUICtrlSetData($Player, "You Lose") GUICtrlSetData($computer, "I Win") GUICtrlSetData($results, "You pay for dinner") $cturn = 0 $pturn = 0 ElseIf $pturn = 2 Then GUICtrlSetData($Player, "You Win") GUICtrlSetData($computer, "I lose...") GUICtrlSetData($results, "You got Lucky") $cturn = 0 $pturn = 0 EndIf If $time = @SEC Then MsgBox (0, "Time","Times Up") EndIf GUICtrlSetData($prompt, "Are you ready?") GUICtrlSetPos($prompt, 40,30) Case $msg = $gui_event_close Exit EndSelect WEnd Giggity Link to comment Share on other sites More sharing options...
Andreik Posted August 25, 2008 Share Posted August 25, 2008 (edited) I write a script like yours: expandcollapse popupGlobal $SELECTED = 0 Global $COMPUTER_COUNT = 0 Global $HUMAN_COUNT = 0 Dim $MOVE[3] $MOVE[0] = "Rock" $MOVE[1] = "Paper" $MOVE[2] = "Scissors" $GUI = GUICreate("Game",100,200,-1,-1,0x16C80000,0x00000181) $START = GUICtrlCreateButton("START",30,5,40,20) $rock = GUICtrlCreateButton("O",10,30,20,20) $paper = GUICtrlCreateButton("-",40,30,20,20) $scissors = GUICtrlCreateButton("X",70,30,20,20) $comp = GUICtrlCreateLabel("",5,100,90,20) $human = GUICtrlCreateLabel("",5,125,90,20) $additional = GUICtrlCreateLabel("Are you ready?",5,150,90,40,0x01) GUISetState() While 1 $MSG = GUIGetMsg() If $MSG = $START Then $select = "" GUICtrlSetData($additional,"Set") $TIME = TimerInit() Do $MSG = GUIGetMsg() If $MSG = $rock And $SELECTED <> 1 Then $select = $MOVE[0] $SELECTED = 1 ElseIf $MSG = $paper And $SELECTED <> 1 Then $select = $MOVE[1] $SELECTED = 1 ElseIf $MSG = $scissors And $SELECTED <> 1 Then $select = $MOVE[2] $SELECTED = 1 EndIf Until TimerDiff($TIME) >= 3000 If $select = "" Then GUICtrlSetData($additional,"Times up") $COMPUTER_COUNT += 1 EndIf $SELECTED = 0 $comp_select = $MOVE[Random(0,2,1)] GUICtrlSetData($comp,"Computer: " & $comp_select) GUICtrlSetData($human,"Human: " & $select) If $select = $comp_select Then GUICtrlSetData($additional,"Draw game") ElseIf $select = "Paper" and $comp_select = "Rock" Then GUICtrlSetData($additional,"You are winner") $HUMAN_COUNT += 1 ElseIf $select = "Rock" And $comp_select = "Paper" Then GUICtrlSetData($additional,"I am winner") $COMPUTER_COUNT += 1 ElseIf $select = "Paper" and $comp_select = "Scissors" Then GUICtrlSetData($additional,"I am winner") $COMPUTER_COUNT += 1 ElseIf $select = "Scissors" and $comp_select = "Paper" Then GUICtrlSetData($additional,"You are winner") $HUMAN_COUNT += 1 ElseIf $select = "Rock" And $comp_select = "Scissors" Then GUICtrlSetData($additional,"You are winner") $HUMAN_COUNT += 1 ElseIf $select = "Scissors" and $comp_select = "Rock" Then GUICtrlSetData($additional,"I am winner") $COMPUTER_COUNT += 1 EndIf Sleep(5000) GUICtrlSetData($comp,"") GUICtrlSetData($human,"") GUICtrlSetData($additional,"You:" & $HUMAN_COUNT & @CRLF & "Me:" & $COMPUTER_COUNT) ElseIf $MSG = -3 Then Exit EndIf WEnd Edited August 25, 2008 by Andreik When the words fail... music speaks. Link to comment Share on other sites More sharing options...
youknowwho4eva Posted August 25, 2008 Author Share Posted August 25, 2008 (edited) When I first ran yours I didn't realize when it said set, that I was supposed to click a button, I was waiting for go. So it errored. Then after that it stores your button in there It remains that selection. I scored, and my score didn't go up. Edit: your's also appears to be random. For Mine I tried to make it so it guessed fairly accurately what you where going to pick. I went with, most people go in order, Rock to Paper to Scissors. If the user chooses Rock, it becomes likely the computer will go with scissors, especially if before Rock user choose Scissors. Edited August 25, 2008 by youknowwho4eva Giggity Link to comment Share on other sites More sharing options...
Andreik Posted August 25, 2008 Share Posted August 25, 2008 Look at my edit now. When the words fail... music speaks. Link to comment Share on other sites More sharing options...
youknowwho4eva Posted August 25, 2008 Author Share Posted August 25, 2008 Ha, so if you don't select anything the computer wins a point. How bout a timer so the user knows They have a set time, and they can click before time runs out. I was thinking of putting a timer on mine. I'm also thinking of making mine so it stores more history to add into the math and make it read patterns better. For Humans, Random is difficult, No matter how random we try to be, human nature prefers patterns. Just ask the developers of Big Blue. It Read peoples patterns to beat them in chess. But then it had a lot more variables to go by then we do with Rock Paper Scissors best of 3. Now if it stored previous matches in the computer, then it could learn better, and eventually win 95% of the time. (Have to account for Murphy's law) Giggity Link to comment Share on other sites More sharing options...
Andreik Posted August 25, 2008 Share Posted August 25, 2008 (edited) Ha, so if you don't select anything the computer wins a point. How bout a timer so the user knows They have a set time, and they can click before time runs out. I was thinking of putting a timer on mine. I'm also thinking of making mine so it stores more history to add into the math and make it read patterns better. For Humans, Random is difficult, No matter how random we try to be, human nature prefers patterns. Just ask the developers of Big Blue. It Read peoples patterns to beat them in chess. But then it had a lot more variables to go by then we do with Rock Paper Scissors best of 3. Now if it stored previous matches in the computer, then it could learn better, and eventually win 95% of the time. (Have to account for Murphy's law)If you want to follow some models and if you have time you can create a little artificial intelligence bot that follow in time player chooses and find some models. But still more then 80% from turns I don't think if computer can win if follow some patterns. Edited August 25, 2008 by Andreik When the words fail... music speaks. Link to comment Share on other sites More sharing options...
youknowwho4eva Posted August 25, 2008 Author Share Posted August 25, 2008 I was counting on that it would guess wrong maybe 20% of the time, but it would have to guess wrong twice in one game to lose. Even at random it has a 66.6666% chance of not giving up a point. So it could guess wrong (Tie) and not lose, and just add that to the math. something like if player is down 1 to 0 player tends to use rock 60% Scissors 20 and Paper 20 so Rock would be used, but I would want to expand that to if player is down 1 to 0, player previously used Rock, Computer Previously used Paper, Player has played 15 games this session, ect. to get as exact a guess as possible. Giggity Link to comment Share on other sites More sharing options...
Andreik Posted August 25, 2008 Share Posted August 25, 2008 (edited) I was counting on that it would guess wrong maybe 20% of the time, but it would have to guess wrong twice in one game to lose. Even at random it has a 66.6666% chance of not giving up a point. So it could guess wrong (Tie) and not lose, and just add that to the math. something like if player is down 1 to 0 player tends to use rock 60% Scissors 20 and Paper 20 so Rock would be used, but I would want to expand that to if player is down 1 to 0, player previously used Rock, Computer Previously used Paper, Player has played 15 games this session, ect. to get as exact a guess as possible.I don't think if your algorithm is good. You cannot predict that a player tends to use rock 60%, scissors 20% and paper 20 %. And how you calculate if use a random method is 66.66% chance of not giving up a point.My idea is next:If you try to use a model is probably to guess next player move but for this you must create a special algorithm to log all player moves and is possible that player give to computer a model and then trick computer intended.If you use random chooses is very hard to know next move of computer and I think that a player select a random choose not a strategically choose. Edited August 25, 2008 by Andreik When the words fail... music speaks. Link to comment Share on other sites More sharing options...
youknowwho4eva Posted August 25, 2008 Author Share Posted August 25, 2008 I get the 66.6666% from, if its a tie, no point given, if its a win, no point given, if its a lose point give. odds are 2:3 that a point will not be given, or 66.6666%. And my plan is for it to store a variable each turn that is added to an average to decide what to go with. When you get yours the way you want, and I get mine the way I want, we will battle them and see which program can oust the other :-P. Giggity Link to comment Share on other sites More sharing options...
Andreik Posted August 25, 2008 Share Posted August 25, 2008 I get the 66.6666% from, if its a tie, no point given, if its a win, no point given, if its a lose point give. odds are 2:3 that a point will not be given, or 66.6666%. And my plan is for it to store a variable each turn that is added to an average to decide what to go with. When you get yours the way you want, and I get mine the way I want, we will battle them and see which program can oust the other :-P.I very curious now. I wait until you finish your script what you want to do and I want to see if is significant better.Bully for you! When the words fail... music speaks. Link to comment Share on other sites More sharing options...
youknowwho4eva Posted August 25, 2008 Author Share Posted August 25, 2008 As soon as I have enough time to not only figure out the math I want to put in there but also put it in there :-P Giggity Link to comment Share on other sites More sharing options...
jvanegmond Posted August 26, 2008 Share Posted August 26, 2008 2 wins. 1 tie. github.com/jvanegmond Link to comment Share on other sites More sharing options...
youknowwho4eva Posted August 26, 2008 Author Share Posted August 26, 2008 You won twice? or it did? I did find one way to easily beat it yesterday, so I put a random in there until I have time to play with it more. Giggity Link to comment Share on other sites More sharing options...
jvanegmond Posted August 26, 2008 Share Posted August 26, 2008 I won twice, randomly.. Anyway, I played around a bit with an algorithm to decide what choice the computer would make. The algorithm isn't really fancy, but the rest of the code is pretty neat. expandcollapse popupGlobal $OPT_DEBUG_MESSAGEBOX = False ; Change to true if you wish to notify the end user when an exception occurs Global $SHOT_DEFAULT = 0 Global $SHOT_ROCK = 1 Global $SHOT_CISSORS = 2 Global $SHOT_PAPER = 3 Dim $mShots[1] _Shot_Add($SHOT_ROCK) _Shot_Add($SHOT_ROCK) _Shot_Add($SHOT_CISSORS) _Shot_Add($SHOT_PAPER) _Shot_DisplayAll() _Shot_PredictNext() Func _Shot_Add($pShot) If $pShot <> $SHOT_ROCK And $pShot <> $SHOT_PAPER And $pShot <> $SHOT_CISSORS Then _ThrowException("Tried to add non-valid shot") Return 0 Else $lShotlength = UBound($mShots) ReDim $mShots[$lShotlength+1] $mShots[$lShotlength] = $pShot Return 1 EndIf EndFunc Func _Shot_PredictNext() $lPrediction = $SHOT_DEFAULT ;; Code to calculate next move $lTotalRock = 0 $lTotalCissor = 0 $lTotalPaper = 0 $lShotlength = UBound($mShots)-1 For $lIndex = 1 to $lShotlength Switch $mShots[$lIndex] Case $SHOT_ROCK $lTotalRock += 1 Case $SHOT_CISSORS $lTotalCissor += 1 Case $SHOT_PAPER $lTotalPaper += 1 EndSwitch Next If $lTotalRock > $lTotalCissor AND $lTotalRock > $lTotalPaper Then $lPrediction = $SHOT_ROCK ElseIf $lTotalCissor > $lTotalRock AND $lTotalCissor > $lTotalPaper Then $lPrediction = $SHOT_CISSORS ElseIf $lTotalPaper > $lTotalCissor AND $lTotalPaper > $lTotalRock Then $lPrediction = $SHOT_PAPER EndIf ;; End code to calculate next move If $lPrediction = $SHOT_DEFAULT Then _ThrowException("Could not predict next move") EndIf ConsoleWrite("Predict next shot as: " & _Shot_TranslateToString($lPrediction) & @CRLF) Return $lPrediction EndFunc Func _Shot_Display($pIndex) ConsoleWrite("Shot " & $pIndex & " = " & _Shot_TranslateToString($mShots[$pIndex]) & @CRLF) EndFunc Func _Shot_DisplayAll() $lShotlength = UBound($mShots)-1 For $lIndex = 1 to $lShotlength _Shot_Display($lIndex) Next EndFunc Func _Shot_TranslateToString($pShot) $lShotString = "" Switch $pShot Case $SHOT_DEFAULT $lShotString = "#DEFAULT#" Case $SHOT_ROCK $lShotString = "Rock" Case $SHOT_CISSORS $lShotString = "Cissors" Case $SHOT_PAPER $lShotString = "Paper" Case Else _ThrowException("Could not translate shot index " & $pShot & " to string.") EndSwitch Return $lShotString EndFunc Func _ThrowException($pException) If $OPT_DEBUG_MESSAGEBOX Then MsgBox(0, "An exception occured", $pException & @CRLF) EndIf ConsoleWrite("Exception: " & $pException & @CRLF) EndFunc github.com/jvanegmond Link to comment Share on other sites More sharing options...
jvanegmond Posted August 26, 2008 Share Posted August 26, 2008 Some sample output the code would give: Shot 1 = Rock Shot 2 = Rock Shot 3 = Cissors Shot 4 = Paper Predict next shot as: Rock Shot 1 = Rock Shot 2 = Cissors Shot 3 = Paper Exception: Could not predict next move Predict next shot as: #DEFAULT# Exception: Tried to add non-valid shot Shot 1 = Rock Shot 2 = Rock Shot 3 = Cissors Predict next shot as: Rock github.com/jvanegmond Link to comment Share on other sites More sharing options...
youknowwho4eva Posted August 26, 2008 Author Share Posted August 26, 2008 I see your going with what the user uses most often as what they are most likely to use the next time. I'm thinking of making an extended list with a code like system. If the user is down 1 to 0 and the user previously used rock. the last time this same situation arose he used paper. send scissors. maybe add in there total time of play. something like the last 3 times he was in this situation he used paper, odds are he's going to try to trick you and use rock. send paper. The more variables the more accurate the guess, as long as the variables are relevant to the guess. almost any way you do it though the user can figure out what the computer is going to guess, so throw a random in there to keep them guessing Giggity Link to comment Share on other sites More sharing options...
jvanegmond Posted August 26, 2008 Share Posted August 26, 2008 (edited) Yes, the algorithm I wrote is more something I came up with quickly. I had intended the code as a good base on which you could easily expand on. I see what you mean with using patterns. It is very interesting logic, and Rock Paper Scissors is a very good game to start with. Very advanced Poker bots also work in this way. I'll see if I can come up with something basic, if you haven't already. Edited August 26, 2008 by Manadar github.com/jvanegmond Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now