This file explains the empirical modelling version of the OXO game. (NB: Other names for this game include Noughts & Crosses and XOX).


This model was produced for the COMICAL project, which is an empirical modelling project demonstrating the advantages of the techniques for use in education.


OXO is a simple game played on a 3x3 grid. Each player takes it in turns to place one of their counters (O or X) in one of the nine squares. The aim is to get a line of three of your counters either horizontally, vertically or diagonally.


The idea of this model is to have several cognitive layers which will be introduced sequentially to build up an understanding of the model, how it was designed and how empirical modelling is used to implement the game.

Initially only layer 1 is displayed. To incrementally add layers click on the cyan button at the top left corner of the screen titled "NEXT LAYER".


The first layer introduces the concept of lines on the grid. Each winning line is represented by a different coloured line. These are animated to more clearly depict the winning lines.
To start the animation click on the window.

The winning lines can be changed in the tkeden window. The variable which stores the lines is lines. This is a two dimensional array (i.e. lines[][]). The first index will describe which line to change. The second index describes which point to change. For example the first line is described as lines[1] = [1,2,3];. The squares/positions on the grid are numbered from left to right, from top to bottom. This can be changed, for example, to lines[1] = [1,8,3]; which is a line making a V shape on the board


This layer introduces the concept of pieces. Xs and Os can be placed on the board at random. There are no rules at this point. Counters can be overwritten or erased. Several identical counters can be placed in a row (i.e. you do not have to take turns in placing a counter). To lay an O, click the left mouse button in the desired square. To lay an X click the right mouse button. To erase an X or an O click the middle mouse button.

There is the concept of winning. There are panels to the right of the board. These display the state of such variables as x_won (has X won yet), o_won (has O won yet), draw (is the board full and neither player has won) and full (are all the positions on the board filled with counters).

The rules for who has won can be changed by re-defining the winning and draw eden definitions in the tkeden input window. Currently a player has won whenever at least one winning line is full or just their counters. These variables remain correct even when a winning line is re-defined.


This window starts to introduce the artificial inteligence into the model. Each position on this board displays a value. This is a score for that square. These scores are calculated by considering each possible winning line which goes through that square. When considering a possible winning line, it looks at how many counters of each type are on the line already. It then gives that line a score.
The pseudo code for this evaluation function is as follows:

if two of your counters are on that line and one blank
you can win by going there

return 100
else if opponent has two counters in that line and there is one blank
your opponent will win by going there

return 40
else if one of your counters on the line and no others
you will make a line of two

return 10
else if one of their counters on the line and none of yours
stop their line early

return 6
else if there are no counters on that line at all
return 4
else if there is one counter of each on that line
at least it is possible to go there

return 1

The score for one square will be the total of the scores for each winning line which that square is part of. The square with the highest score is the best square to lay a counter in that turn.

If the board looks like


Lets take it to be Os turn and consider the sqaure marked C. There are three possible winning lines through this square: horizontally, vertically and diagonally. Each of these lines will be assigned a value and the value of the square will be the sum of these three values. Lets look at these three values in turn.
There is one O on this line which is one of yours. Therefore going in square C will mean a line of 2. This scores 10.
There are no counters on this line. Therefore going in square C will start a new line. This scores 4.
There are two of Os opponents counters on this line. Therefore if not going in square C will allow X to go there and win the game. This score 40.
The value for the square marked C then is the total of these three scores which is 54.


Layer 4 is the final layer introducing the concept of having turns and abiding other strict rules of play.

The window labled 'Play' shows the scores the computer evaluated on its turn. The computer moves very quickly so you cannot see these values. The square it chose is highlighted by a red square.

The window labled 'Gamestate' is the window you actually play in. To place counters use the same mouse buttons as before but on this board instead. There are three extra buttons. The green button entitled "INITIALISE" will clear the board and start a new game. The yellow button initially titled "O TO PLAY" can be clicked to change who will start, O or X. The cyan button initially titled "Computer On" is used to turn the computer play on or off. The white panel bellow these buttons displays whose turn it is to play.

If the computer is playing, it will be X and the user will be O.

To play without the computer playing, use the left mouse button to place an O and the right mouse button to place an X.

NB: You can still cheat by clicking on the status board. This is blatant cheating as clicking in that layer of the model does not constitute playing the game.


Change the lines

This effectively makes new games with the computer using the same strategy, but human players will not be able to rely on memory of positions, but only on strategy.

Some good examples to try are:


To save you typing in these long definitions, some possible values for the lines variable are provided as lines0 and lines1 etc. Assign values to lines using, for example lines = lines0;.

Beat the computer

With its normal strategy with the normal winning lines, it is possible to beat the computer. See if you can beat it.