For some reason the code below does not reset the lists storing the opponent_history and own_history. They will be emptied for the one itteration in which the if clause triggers but are reset to the orignial state in the itteration after. It works for the counter.
So any insights in this would be great since I have no clue to why it happens.
def player(prev_play, opponent_history=[], own_history = [], counter=[0]):
if not prev_play:
print('reset')
del opponent_history, own_history
own_history=[""]
opponent_history = list()
counter[0]=0
opponent_history.append(prev_play)
counter[0]+=1
guess='R'
print(counter[0])
print(own_history[0:10])
print(opponent_history[0:10])
own_history.append(guess)
return guess
Output:
playing mrugesh
reset
1
['']
['']
2
['R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R']
['R', 'P', 'P', 'S', 'R', 'R', 'P', 'P', 'P', 'P']
3
['R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R']
['R', 'P', 'P', 'S', 'R', 'R', 'P', 'P', 'P', 'P']
4
['R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R']
['R', 'P', 'P', 'S', 'R', 'R', 'P', 'P', 'P', 'P']
5
['R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R']
['R', 'P', 'P', 'S', 'R', 'R', 'P', 'P', 'P', 'P']
6
['R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R']
['R', 'P', 'P', 'S', 'R', 'R', 'P', 'P', 'P', 'P']
7
['R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R']
['R', 'P', 'P', 'S', 'R', 'R', 'P', 'P', 'P', 'P']
Final results: {'p1': 0, 'p2': 5, 'tie': 2}
Player 1 win rate: 0.0%