# Semester project for 36APC course Mastermind game

## 1. SPECIFICATION

Implement Mastermind game on Spartan IIe FPGA mounted on Digilab DIO1 I/O board. Game is being played in following steps.

• First player choose one of 8 possible colours for every single of 4 positions.
• Second player doesn't know the chosen colours and tries to guess them, selecting one colour of 8 possible for each position.
• First player valuates his mate guesses with white and black marks:
• For every correct colour at a wrong place one white mark,
• For every correct colour at the right place one black mark.

Game is finished when the second player correctly guessed colour for all 4 positions that means he scores 4 black marks.

## 2. SOLUTION

Basic game scenario transformed to the Digilab board design is following:

• Input of colours (to guess) by the first player starts after circuit’s reset (BTN1) with switches (SW1 to SW8, indicates the colour). The first one switched on is stored as a colour for first position, pressing BTN5 one moves to a next position. Process is visualized on 7-segment display, symbol 0 identifies colour not yet selected.
• The second player indicates his guesses in a similar way. After pressing BTN5 4 times the guess is done.

Scoring is done automatically after colours’ input phase: first two digits show number of guesses, third is number of white marks, fourth number of black marks. To continue with colours select one needs to press BTN5 again.  When second player scores 4 black marks, game ends. A new one can be started pressing button BTN1 (reset).

We have decided to implement the game using VHDL language and Xilinx ISE development environment in its 5.2 version. Basic overview of realised blocks on RTL level is shown on the following picture.

.
Fig. 1

• display – shows values from color0 to color3 buses on the display, number of guesses and results, generates display multiplex, stores values selected by the first player at the game’s start, calculate the score
• colors – reads the current colour depending on number of BTN5 presses, decides if the circuit is in colour select mode or results display mode
• button – debounces the BTN5 button

Overview of buses, signals and their types:

• color0-color3 – the colour for the particular position 0-3, BCD coded with 3 bytes (with extra colour 0)
• game – game start indicator, zero when first player inputs colours to guess (necessary for resetting the display since the second player must not see the original colours because after one round results the colours inputted in the previous step are shown for a better orientation and game play)
• saved – auxiliary function related with game – indicates if display component saved colours in the memory and they can be rewritten to the zeroes in colours part
• result – indicates if we’re in colour display mode or results display mode
• debounce – BTN 5 signal without bouncing

The final realisation is best described with ISE files. They are part of the solution, packaged in ZIP archive:

## 3. CONCLUSION

The Mastermind game was designed and implemented without larger difficulties. Problem analysis and structure design took 1 hour of project time; the realisation took 11 hours and the documentation phase 1 hour. While implementing the project we have encountered synthesis problems in final stages, problems with clock setup and with time constrains during communication. All problems were solved.