I’m trying to figure out where I went wrong by printing everything, so I noticed that the problem appears to start with “last_three”. Or rather, that’s where I can first tell that the function seems to be running the initial code twice instead of moving on to return the “ideal_response”. Can someone tell me what I’m doing wrong?
My issue likely stems from not fully understanding how the dictionaries’ keys and values are being called here. Namely, the [0][k] thing doesn’t make much sense to me. I understand what the dictionaries are meant to do within the function; what I don’t get that way of calling keys and value pairs. What’s the 0 doing there? Oddly, I can’t seem to find an explanation through google (that’s a first ).
Thanks in advance!
def player(prev_opponent_play,
opponent_history=[],
play_order=[{
"RRR": 0, "RRP": 0, "RRS": 0,
"RPR": 0, "RPP": 0, "RPS": 0,
"RSR": 0, "RSP": 0, "RSS": 0,
"PRR": 0, "PRP": 0, "PRS": 0,
"PPR": 0, "PPP": 0, "PPS": 0,
"PSR": 0, "PSP": 0, "PSS": 0,
"SRR": 0, "SRP": 0, "SRS": 0,
"SPR": 0, "SPP": 0, "SPS": 0,
"SSR": 0, "SSP": 0, "SSS": 0
}]):
if not prev_opponent_play:
prev_opponent_play="R"
opponent_history=["R","R"]
opponent_history.append(prev_opponent_play)
last_two = "".join(opponent_history[-2:])
last_three = "".join(opponent_history[-3:])
print("last3:",last_three)
play_order[0][last_three] += 1
potential_plays = [
last_two + "R",
last_two + "P",
last_two + "S",
]
print("potential plays:",potential_plays)
sub_order = {
k: play_order[0][k]
for k in potential_plays if k in play_order[0]
}
print("suborder:",sub_order)
prediction = max(sub_order, key=sub_order.get)[-1:]
ideal_response = {'P': 'S', 'R': 'P', 'S': 'R'}
return ideal_response[prediction]```