Day 4, Testing the Code

Day 4, Testing the Code

In this meeting as well as during day 5, we focused on finalizing, troubleshooting, testing, and improving our code. We had to focus on several main issues that were challenging to work out in our code. The most challenging was the process of getting the correct colors to switch after a player input their turn. In Othello, when a player places a tile, they switch any of the tiles that they have captured from their opponent, which can happen in any direction as long as it is bounded by two tiles of the player’s color.

In our code, we had to determine the best way to check every direction around a chosen cell to ensure that:

  1. it was adjacent to a tile of the opposite color
  2. in the direction of the tile of the opposite color, there was a tile of its own color

When these conditions were met, the code would then backtrack along that direction and switch the opponent’s tiles in that series to capture them for the player who made the turn. One particular challenge for this process was figuring out the logic required to check in the diagonal directions around each placed tile. In a section of the code for switching tiles, shown below, it shows how we worked through this challenge. For a given selection, we checked along the diagonal direction (up and right). First, if it found an empty cell, it would stop checking that direction, otherwise if it found one of its own color, then it would go backwards along that direction, switching the tiles to the player’s color.

diagonal-code

Once we had the code working for each player’s turn, we implemented a counter to check if the board had been filled, which would denote the end of the game at which point the board would display which player had won the game. Additionally, we added some aesthetic features such as a startup animation which would play each time the game began.

group4