WinStay_LoseSwitch

AuthorEmmanuel Harish Menon
Submission date2019-07-11 00:24:48.417173
Rating4705
Matches played201
Win rate47.76

Use rpsrunner.py to play unranked matches on your computer.

Source code:

import random
choices = ["R", "P", "S"] #list of choices
winningPairs = {"R": "S", "P": "R", "S": "P"} #the value that the key holds is the pick that will be beaten by the key
botPrevInput = "" #this variable is used to store both the previous input and future input

if input is "":
    botPrevInput = choices[random.randint(0, 2)] #pick randomly
else:
    if input == botPrevInput or botPrevInput == "":
        botPrevInput = choices[random.randint(0, 2)] #pick randomly
    elif winningPairs[input] == botPrevInput: #if the bot lost
        botPrevInput = winningPairs[botPrevInput] #set the next output to be whatever would have lost to me
    elif winningPairs[botPrevInput] == input: #if the bot won
        botPrevInput = botPrevInput #unnecessary

output = botPrevInput #set the output var to be the botPrevInput