Programming Battleship on a TI-84

TIME : 2016-01-07
Programming Battleship on a TI-84

Use matrices. They are effectively a ready-made grid, which is exactly what the game needs.

Matrices run from [A] to [J], and [J] is usually free since almost nobody else uses it. You reference a single cell with row and column: [J](2,3) is the element in row two, column three.

To store a value, use the store command:

3->[J](2,3)

Size the matrix to a 10 by 10 board from inside a program with:

{10,10}->dim([J])

From there you store numbers to mark water versus ship, write a routine that lets the player choose a coordinate to fire at, and add a display that draws the board. That is the whole game.