Author | azeazezaezae |
Submission date | 2020-01-23 18:48:43.295256 |
Rating | 4822 |
Matches played | 207 |
Win rate | 49.28 |
Use rpsrunner.py to play unranked matches on your computer.
if input == "":
ENNEMY_TRANSITIONS = {
'R': {
'R': 0,
'P': 0,
'S': 0,
},
'P': {
'R': 0,
'P': 0,
'S': 0,
},
'S': {
'R': 0,
'P': 0,
'S': 0,
},
}
MY_TRANSITIONS = {
'R': {
'R': 0,
'P': 0,
'S': 0,
},
'P': {
'R': 0,
'P': 0,
'S': 0,
},
'S': {
'R': 0,
'P': 0,
'S': 0,
},
}
WIN = {
'R': 'P',
'P': 'S',
'S': 'R',
}
ennemy_prev = ""
MY_PREV = ""
def guess_from_ennemy_transitions(last):
global ENNEMY_TRANSITIONS
if input == "":
return ("R", 0)
best_val = -1
best_guess = None
for guess in ENNEMY_TRANSITIONS[last]:
if ENNEMY_TRANSITIONS[last][guess] > best_val:
best_val = ENNEMY_TRANSITIONS[last][guess]
best_guess = guess
return (best_guess, best_val)
def update_ennemy_transitions():
global ennemy_prev
if ennemy_prev:
ENNEMY_TRANSITIONS[ennemy_prev][input] += 1
ennemy_prev = input
def guess_from_my_transitions(my_prev):
global MY_TRANSITIONS
if input == "" or my_prev == "":
return ("R", 0)
best_val = -1
best_guess = None
for guess in MY_TRANSITIONS[my_prev]:
if MY_TRANSITIONS[my_prev][guess] > best_val:
best_val = MY_TRANSITIONS[my_prev][guess]
best_guess = guess
return (best_guess, best_val)
def update_my_transitions():
global MY_PREV
if MY_PREV:
MY_TRANSITIONS[MY_PREV][input] += 1
update_ennemy_transitions()
best_guess_from_ennemy, best_val_from_ennemy = guess_from_ennemy_transitions(input)
#
best_guess_from_mine, best_val_from_mine = guess_from_my_transitions(MY_PREV)
update_my_transitions()
if best_val_from_ennemy > best_val_from_mine:
MY_PREV = best_guess_from_ennemy
else:
MY_PREV = best_guess_from_mine
output = WIN[MY_PREV]