We want to create a simple battleship game using embedded systems knowledge we've acquired. Two players will be able to player battleship online using our hardware and cloud.
The game is a simple imitation of battleship game. 2 players must compete to sink all of the opponents ship. Each player will have a 4 by 4 board. The player will then place their own ship on the board. When the battle phase begins, each player must try to sink the opponent's ship by firing at a chosen tile on the opponent's board (without knowing if the opponent ship will be there). If the fire hit the ship, the player could then fire another shot. The first player to sink all of the opponent's ship wins.
How it Works
First the cloud will be waiting for both player to push the button on the PCBs to start the game. After both player's pressed the button within a certain time duration, the cloud will try to start the game and send a start signal to both player's PCB. The start signal will also contain the amount and size of ship for each player to place. The player then needs to place the ship on their own board. After all the ships were placed, a message containing all of the ship's location will be sent back to the cloud. After the cloud have received both player's ship location, a player will be chosen at random to get the first turn. The turn message, as well as the game end message and fire result message will be sent to each player's PCB. When the PCB receive a turn message, it will check if there are any fire results to be displayed. It will then determine if the game has ended. If not, then the player with the turn would be able to fire at the opponent's board. When the tile to be fired was selected (pressed), a message with the fire location will be send to the cloud to determine if the fire hit or miss. The cloud will then reply with a message containing the result of a fire, as well as whose turn it is. This continues until the game ends. Here, the cloud will send a game end messaged with the fire result message.
- The algorithm/design for the ship placement was quite complex (as we do it on the PCB and then send all of the locations to the cloud no sending the location one by one)
- SD Card instability slowed down our progress
- Some keys on the keyboards were not working properly
What we Learned
- While doing design work, one has to pay special attention to detail
- A lot of time has to be given for debugging - finishing the design/code takes about half the time of the completion
- Breadboards have unstable connections which should be taken into consideration
- Team work is important
What's next for Ship wars
- More stable OTAFU
- Easier ship placement interactions (might also use the accelerometer)
- Display if all of the tile of the ship were fire and if the ship'd sunk.
- Code optimization
- Make sure there is no cheating! (by sending fake signals to the cloud etc.)
- Port the system completely to the PCBs (currently we are using the dev boards)
- implement two i2c lines, so one of the lines won't be flushed by the polling communication between neotrellis board and the PCBs.
We use the SAMW25 module with Nodered server and MQTT for cloud-PCB communication. The main components for each player are listed below
- SAMW25 module
- two 4x4 neotrellis board
- buzzer & buttons
- FDTI (for firmware update)
To compile the code on player 1 or player 2 see comments on wifihandler.h