Coding in C the licensed boardgame Battleship with two uno32 kits


  • 2x chipKIT Uno32: Basic Microcontroller Board
  • 2x chipKIT Basic I/O Shield
  • 3x male/male jumper wire.
  • A C compiler
  • A serial communication program


The game begins with both the user and bot sending a negotiation message set with random values. Both side's message values are compared to determine who goes first. Whether its the bot or the user, they send a guess coordinate string that details coordinates for guesses and the other side decides whether they send hit strings and or send guess strings if they miss. The cycle of sending guesses and hits continues until one side has sunken every ship. When the game finishes, the side who wins has their LEDs flashing.

Concepts Used

Encrypted String and Checksums

The way these strings are encrypted are done so by checksums. The simplest way I did this is by XORing every bit after '$' and before '*' in the string, creating 2 ascii hexadecimal characters. The reason I need to encrypt the strings is to keep information between only the user and the bot. As the hashing operation is XORing both parties know to decode the string.

Examples of Encrypted Strings

Negotiation set 1
  • $CHA,37348,117*46
  • $DET,9578,46222*66
Negotiation set 2
  • $CHA,54104,139*45
  • $DET,32990,21382*5e
Negotiation set 3
  • $CHA,62132,70*79
  • $DET,52343,16067*50
Hit string string template="$HIT,row,column,hit or miss(# for ship size)*checksum"
  • $HIT,3,8,1*43
  • $HIT,0,2,0*4b
  • $HIT,5,6,4*4e
Coordinate string string template="$COO,[row],[column],*checksum
  • $COO,0,2*41
  • $COO,5,5*43
  • $COO,1,7*45
State Machines

The entire game is handled with two state machines. One named protocol.c that handles parsing and recording information of the received encrypted message. The other state machine, ArtificialAgent.c, handles the states of the entire game such as guessing coordinates or determining who goes first. The diagrams below describe the states and their conditions labeled in bold.