This is an old revision of the document!
Homework 3 - Tic Tac Toe
In this homework, you will implement some functionality which will allow you to design a completely functional tic-tac-toe AI. The latter will be part of homework 4.
About Tic Tac Toe
Tic Tac Toe is usually played on a 3 by 3 board, marking positions by each player in rounds. Our game is slightly different:
- it can be played on a square board of any size larger or equal to 5.
- A player wins if it has marked a line, column or diagonal of 5 consecutive positions in a row.
Example of a winning position for X
on a 5×5 board:
X...0 0X.0. ..X0. ...X. .0..X
Example of a winning position for 0
on a 7×7 board:
.X...X. ...0... ...0... .X.0..X 0..0..0 ...0... ...X...
Coding conventions
- In your project template,
X
is encoded as the first player (One
), and0
, asTwo
. - A
Board
is encoded as a List of Lists of positions (i.e. a matrix), where a position can beOne
,Two
orEmpty
. We make no distinction in the code between a position and a player, althoughEmpty
cannot be seen as a valid player. This makes the code slightly easier to write.