During this week, we’ve managed to finalize our game logic code. I am going to explain the upper part of the game logic code due to the workload that was split between Jason and me.

In this code block, all the sprites are blit onto the screen. This code block is necessary to be put inside almost every while loop as it’s used to update all the changes from backend logic to frontend sprites.

This code block works by calculating the remaining seeds inside all the small holes. If there are still seeds inside the small holes, the game will continue, else the game ends by comparing which player has the largest value of seeds inside their house.

This block is used to check which player goes during that turn. It works by using the boolean mechanism.

This block marks the playing for turn loop. Basically, this loop is used to execute the code block inside the loop while the player is still able to play for a turn/another turn.

This block is used to check if any legal move is available for the current player. If it’s not available, the turn for that current player will end.

In this code block, the current player will enter the index choosing phase. During this phase, the player must choose one of the available indexes to play from their small holes.

To choose which index to play, it depends on the game mode and who the current player is. If the current player is AI, it will run the commitMove command to get the direction. Else, if it’s human that we are talking about, it will get the index from event.get() mechanism.

To get which index is chosen, it maps the mouse click position to their respective chosen index.

In this if-else statement, the chosen index will be tested to make sure that the index is valid. If the index is valid, the chosen small holes will be emptied and all the seeds inside will be put to the current player.