In week 4, I did the game code with Vincent. He explained the first part of the coding on his blog, I will explain the final part.
This while loop will spread the seed in the current player’s hand to different parts of the board where first we move the chosen index by one so we will begin inserting the seed starting from the next location in the board.
Next, this part of the code will check if the current index / location is the enemy base/territory. So, if player 1 is in player 2’s territory or if player 2 is in player 1’s territory, player will skip that location and go to the next location/index.
Next, since many things can happen if there is only one seed left in hand, this part of the code does all the processing for those events. First, if the location that we put the last seed in already has a few seedes inside, your turn starts again.
The next part of the code is to process where if the last seed in hand is placed in the hole in the opponent’s side that has no seeds inside, current player’s turn will end.
Next, if the last seed lands on a hole with no seeds on the current player’s side, this code will process the movement of that seed and a seed from opposite the board from the opponent’s side and put those seeds into current player’s home / base.
Lastly, if the last seed in the current player’s hand lands in the current player’s own home/location, choose a hole from his side of the board, and start to play again.
This part of the code adds the number of seeds in the hole by one, while reducing the number of seeds in hand by one.
This part switches current player so that the opponent’s turn can start.