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 159 forks source link

Can you output memory as a dictionary? #55

Closed CreeperLove3000 closed 3 years ago

CreeperLove3000 commented 3 years ago

I'm trying to output memory as a dictionary but memory is staying as a None value, does this mean that memory can't be a dictionary and how can I fix it?

duckboycool commented 3 years ago

What exactly are you expecting as an output? Memory is None until you feed a value into it from with a return. If you meant history, what way would you want it to output?

carykh commented 3 years ago

If you want to store a dictionary in 'memory', don't forget that you have to instantiate it yourself! You also have make sure that dictionary can be read in as parameter, and is being outputted as well.

Here's a simple example of "grimTrigger" written with a dictionary in 'memory':

def strategy(history, memory):

    nextMemory = None
    if memory is not None:
        nextMemory = memory
    else:
        nextMemory = {}
        nextMemory['whatIHadForBreakfast'] = "eggs"
        nextMemory['wasIWronged'] = False

    if history.shape[1] >= 1 and history[1,-1] == 0: # Just got wronged.
        nextMemory['wasIWronged'] = True

    choice = 0 if nextMemory['wasIWronged'] else 1
    return choice, nextMemory