Digital Remake of Connect Four
Step 1: Introduction
In our experiment, we remake the game Connect Four using a CPU made in our CPE 233 class. Throughout the first seven weeks of the quarter, we strive to create this CPU written in VHDL using a program called Vivado. The specific CPU we created is shown in the image attached. We then created the actual Connect Four game and all its features using our RAT assembler. Our RAT assembler program is specific to our class/school and simply uses instructions, registers, and memory to create programs instructions for our CPU.
The rules of Connect Four are simple, place chips into a 7x6 board and try your best to get four or more pieces in a row to win.
Step 2: Features
In our project, we use a BASYS3 board and displayed our game via VGA on a monitor.
- 7 Switches used to select which column you place the chip in.
- 1 Button used to place a chip after you select which column you want to put it in, using the switches.
- 1 Reset Button
- VGA connector
Step 3: RAT Assembly Code
This code is specific to our RAT assembly program and language. It follows basic instructions used to build our game logic, display our game using peripherals, and everything else required to create our game. Attached in this step is our assembly code in a text file.
Step 4: Flow Chart
Our flow chart that describes the steps we followed to create our game. It includes the sequence we followed to keep structure to our game. The flow chart includes subroutines, checks, and states we were in to keep track of what was addressed.
Step 5: Errors Addressed
Some errors we encountered throughout this project varies from the peripherals, modifying the RAT CPU in VHDL, and the game logic itself.
In this project, we were provided with various peripherals that we could use for our project. It included a keyboard driver that allowed us to use computer keys, seven segment display on our Basys3, VGA which allowed us to draw and display our game, a mouse driver, a timer, and other hardware. At first, we chose to use keys on the keyboard to select which column to place each chip in. The keyboard driver was not complete in time and we decided to use switches and buttons on our Basys3 instead. We also chose to display and draw our game using the VGA. The first thing we had to do when implementing the VGA was to change our RAT wrapper in order to display colors and output to the display. A huge error that we had was not testing our VGA as the first thing we did. We later found out that the way we implemented our VGA in our RAT wrapper was incorrect and had to fix it. We fixed the horizontal and vertical sync of the VGA and added the slow clock back into the wrapper. Fixing the VGA helped us tremendously with debugging the game and seeing if our game logic worked.
The largest problems we ran into was implementing the game logic to see which player had won. There were several ways to do this. Here are some of the ways:
- Check the whole board each time a player has placed a chip. This includes checking row by row, column by column, and both diagonal ways.
- Checking the surrounding chips of where the player has placed a chip.
- Check each individual place on the board and checking the surroundings for matches.
What we decided was to first check the whole board each time a player has placed a chip but implemented checking each individual place on the board and checking the surroundings for matches. The first thing we did coming into this project was drawing our flow chart to keep ourselves organized but immediately started the code afterwards. We found out later that this was a terrible idea because implementing the VGA to draw the board was probably the first thing we should have done to debug each check to win (horizontal, vertical, and both diagonals). After working hours and going through our assembly code multiple times to debug our game logic, we decided to toss our method of checking the board and implement a different strategy. We went back to the idea of checking the whole board each time a player had placed a chip because we thought that would be the easiest. We searched through each row for the horizontal check, each column for the vertical check, and both diagonal ways for the diagonal check (positive and negative slopes).
Step 6: Conclusion
In conclusion to our project, recreating Connect Four in assembly language and using our CPU has taught us a lot about using a CPU with a real life application. Although assembly language is basic building blocks of instructions sent to a CPU, it was a difficult process to implement. Modern day higher level software languages have many implemented "instructions" and libraries already created and ready to use. Describing hardware using VHDL and assembly is a very eye-opening experience and makes us appreciate CPU's and other things built in assembly much more. We learned the importance of efficiency afterwards due to the many lines of code in our program. While this could have been programmed much quicker and easier with a higher level language, this assignment really helped us learn more about the foundation of higher level languages (i.e. assembly languages). It forced us to think very logically about what we wanted to do and how to implement it using a concrete structure (i.e. our flowchart).