ASPP / pelita_template

Default template to get started with the Pelita game.
3 stars 25 forks source link

explain by example how the initialization of state in the move function works #36

Closed otizonaizit closed 3 years ago

otizonaizit commented 5 years ago

After mergin #33 , we have state as a dictionary. In the demos it is now routinely initialized as

if state == {}:
   ...

I think this leaves the same questions open that we got from the student when that code looked like this:

if state is None:
    ...

namely, when is the condition True during the game? Of course we can explain in the docs that state is an empty dictionary and you can initialize it how you want and when you want. Still, I think that in the demos the condition should be something like:

if bot.round == 1 and bot.turn == 0:
    ...

which makes it clear when the state gets initialized. The downside of my proposal is that if one wants to write a test for the "second" bot, i.e. when bot.turn==1, then the state may need to be initialized manually beofrehand and passed into the move function during the test, instead of having the condition if state == {} take care of it automatically. My opinion is that we can have tests for the "second" bot where we show how to initialize the state, maybe even showing that it is good practice to first test bot.turn==0 and only after that test the bot.turn==1 case, by using the modified state coming from the first call to the move function.

Follow up here for a discussion...

lschwetlick commented 3 years ago

I think the switching bots #43 and new documentation #46 adress this. Can be closed?

Debilski commented 3 years ago

Yeah, closing for now. I don’t think we have a really good solution for the points that have been raised. Testing the second bot with an empty state dict with the expectation that it this will initialise the state is also wrong. The code may work, but the implicit assumption in the move function will always be that state == {}bot.round == 1 and bot.turn == 0.

I’ll see if I can improve the code comments some more.