A new feature called ‘fog of war’ is to be added to the Skeleton Program. Fog of war means that each player will only be shown the location of a piece belonging to their opponent if that piece is near one of their own pieces. A piece is near another piece if it is two or fewer cells away on the grid.
The player will still be shown the terrain that is in all the tiles.
Figures 7 to 11 show an example of how the fog of war feature should work.
Figure 7 shows the current positions of Player One’s pieces.
In Figure 8 the shaded tiles are those that are two or fewer cells away from Player One’s baron piece.
In Figure 9 the shaded tiles are those that are two or fewer cells away from Player One’s serf piece.
Figure 10 shows the positions of Player One’s pieces and the positions of Player
Two’s pieces.
Figure 11 shows what Player One should see when they are shown the grid when the fog of war feature has been implemented.
Player Two’s baron piece can be seen because it is within two cells of Player One’s serf piece.
Player Two’s LESS piece can be seen because it is within two cells of both Player One’s serf piece and Player One’s baron piece.
Player Two’s serf piece can be seen because it is within two cells of Player One’s baron piece.
Player Two’s PBDS piece cannot be seen because it is not within two cells of any of Player One’s pieces.
What you need to do
Task 1 Create a new subroutine GetFogOfWar in the HexGrid class.
The new subroutine should take the index of a tile in Tiles and return False if the player whose turn it is has any piece which is two or fewer cells away from that tile as the tile is not hidden because of fog of war. Otherwise, it should return True as this tile is hidden because of fog of war.
Task 2 Modify the GetPieceTypeInTile subroutine in the HexGrid class so that it uses the GetFogOfWar subroutine to determine if this tile is affected by fog of war.
If the contents of this tile would be hidden because of fog of war, it should return the string consisting of a single space character.
If the contents would not be hidden because of fog of war, the existing functionality of the GetPieceTypeInTile subroutine should not be changed.
Task 3 Test that the changes you have made work:
run the Skeleton Program
choose to load a game
enter the filename game1.txt
keep pressing the Enter key until the grid has been shown at the start of Player Two’s first turn.