# A Game Winner
Make sure you have all you need before proceeding:
- You understand the concepts of Protobuf.
- Have Go installed.
- The checkers blockchain codebase with the deadline field and its handling. You can get there by following the previous steps or checking out the relevant version (opens new window).
To be able to forcibly terminate games and avoid terminating one game twice, you need to identify games that have been terminated. A good field to add is one for the winner. It needs to contain:
- The rightful winner of a game that reaches completion.
- Or, the winner by forfeit, when a game is expired.
- Or a neutral value when the game is active.
In this exercise a draw is not handled and it would require yet another value to save in winner.
# New information
In the StoredGame
Protobuf definition file:
To have Starport and Protobuf recompile this file use:
Add a helper function to get the winner's address, if it exists. A good place for it is in full_game.go
:
# Update and check for the winner
This is a two-part update. You set the winner where relevant but you also introduce new checks, so that a game with a winner cannot be acted upon.
Start with a new error that you define as a constant:
Then at creation, in the create game message handler, you start with a neutral value:
With further checks when handling a play in the handler:
Check that the game has not finished yet:
Update the winner field, which remains neutral (opens new window) if there is no winner yet:
Handle the FIFO differently depending on whether the game is finished or not:
Just in case, when rejecting a game, in its handler:
Confirm it compiles and you are ready to handle the expiration of games.
# Next up
You have introduced a game FIFO, a game deadline, and a game winner. Time to turn your attention to the next section.