Author | iggi |
Submission date | 2019-02-05 10:03:14.948205 |
Rating | 5284 |
Matches played | 256 |
Win rate | 51.17 |
Use rpsrunner.py to play unranked matches on your computer.
import random
if not input:
moves = ["R", "P", "S"] # possible outputs
beatenBy = {"R": "P", "P": "S", "S": "R"} # list of outcomes with string index
oHistory = [] # opponent's play historyy
round = 0 # number of rounds played
move = random.choice(moves) # first play is random
else:
oHistory.append(input)
stats = {"R": 0, "P": 0, "S": 0}
if round<10:
move = random.choice(moves) # first play are random to populate the history
else:
for x in range(0, round-1): # find the probobility of plays after the iput is played
if input == oHistory[x]:
stats[oHistory[x+1]] += 1
if stats["R"] > stats["S"] and stats["R"] > stats["P"]:
move = "P" # if R is most probable play P
elif stats["P"] > stats["S"] and stats["P"] > stats["R"]:
move = "S" # if P is most probable play S
else:
move = "R" # if S is most probable play R
output = move
round += 1