carykh / PrisonersDilemmaTournament

Watch This Place's awesome video about iterated Prisoner's Dilemma for context! https://www.youtube.com/watch?v=BOvAbjfJ0x0
MIT License
205 stars 160 forks source link

How can I check what the opponent has done the last two rounds? #22

Closed nobody5050 closed 3 years ago

nobody5050 commented 3 years ago

I know I have to use ‘history’ but I’m unsure how to go about converting the array into something I can humanly understand.

Errorcrafter commented 3 years ago

game_ln = history.shape[1]
recent_moves = history[1,(game_ln-2):game_ln]
``` this gives you an array, idk much other than that
Bip901 commented 3 years ago

history[1, -1] returns what the opponent did in the last round (0 means defect, 1 means cooperate) history[1, -2] returns what the opponent did in the second last round And so on.

history[1, 0] returns what the opponent did in the first round history[1, 1] returns what the opponent did in the second round And so on.

Changing the first 1 to a 0 returns what you did in those rounds instead. Make sure to check if (history.shape[1] > 0): [checks if there's at least one item in the history] before accessing those indices.

nobody5050 commented 3 years ago

Sweet, thanks!

Bip901 commented 3 years ago

Sure thing. You may close this issue if it was resolved.

nobody5050 commented 3 years ago

One more thing before closing it, when we get the game length, does that include the current round or does it count every round except for the one we’re currently calculating?

LaTrissTitude commented 3 years ago

you can also use negative indexing: history[1,(game_ln-2):game_ln] == history[1,-2:]

LaTrissTitude commented 3 years ago

the history only includes previous turns

nobody5050 commented 3 years ago

the history only includes previous turns

So if I’m querying the history’s length on round 50 for example, I’m going to get a length of 49?

LaTrissTitude commented 3 years ago

yep

nobody5050 commented 3 years ago

Alright, cool