Author | James Stanley |
Submission date | 2018-05-24 18:35:53.020440 |
Rating | 4901 |
Matches played | 288 |
Win rate | 48.96 |
Use rpsrunner.py to play unranked matches on your computer.
# http://jes.xxx/
import random
markov = {}
state = ['$', '$']
def str_state(state):
return ' '.join(state)
def play():
moves = ['R', 'P', 'S']
if str_state(state) in markov:
moves = markov[str_state(state)]
expect = random.choice(moves)
response_to = {
'R': 'P',
'P': 'S',
'S': 'R',
};
return response_to[expect]
if len(input):
if str_state(state) in markov:
markov[str_state(state)].append(input)
else:
markov[str_state(state)] = [input]
state.append(input)
while len(state) > 2:
state.pop(0)
output = play()