Coronavirus (Covid-19): Latest updates and information
Skip to main content Skip to navigation

Definitive script for OXO

The variables and definitions that make up the OXO-model are as follows:

o is -1	// values to indicate what token is on the square
u is 0	// u means that a square is unoccupied
x is 1
board is concatxo(allsquares)
// concatxo converts -1,0,1 into chars  'O','.','X' and concatenates
// with appropriately specified newlines to create a board display
// display models the visual image associated with a physical disposition of tokens

allsquares is [s1,s2,s3,s4,s5,s6,s7,s8,s9]	//  list of all squares on the board
nofsquares is allsquares#		// # denotes the length of a list
lin1 is [s1,s2,s3]			// explicit enumeration of triples
lin2 is [s4,s5,s6]			// that define the lines
alllines is [lin1, lin2, lin3, lin4, lin5, lin6, lin7, lin8]
noflines is alllines#
linesthru1 is [lin1, lin4, lin7]		// explicit enumeration of lines through a square
linesthru2 is [lin1, lin5]
linesthru is [linesthru1, linesthru2, ..., linesthru9]
//geometry describes the relationships between squares that determine oxo lines

nofx is nofpieces(allsquares, x)
nofo is nofpieces(allsquares, o)
full is (nofo + nofx == nofsquares)
xwon is checkxwon(alllines)
owon is checkowon(alllines)
draw is !xwon && !owon && full
status is (xwon ? "X wins " :  "") || (owon ? "O wins " : "") || (draw ? "Draw " : "") || ""

// status  explains how a particular position is interpreted by an oxo watcher

square is .... 	// possible values are s1 / s2 / s3 / s4 /s5 / s6 / s7 /s8 / s9
availsquare is allsquares[square]==u
cursqval is sqval(linesthru[square])
// sqval() associates a value with a particular square in a particular oxo position
// sqvals evaluates squares (without lookahead) from the perspective of an oxo player

maxindex is findmaxindex(allsquares)
// findmaxindex determines the square with the highest evaluation in a given position
// play is derived from sqvals by "contemplating each square in turn"

startplayer is ....	// possible values are o / x
x_to_play is (!end_of_game) && (startplayer==x  && nofo==nofx) || nofo > nofx
o_to_play is (!end_of_game) && (startplayer==o  && nofo==nofx) || nofx > nofo
end_of_game is xwon || owon || draw
// gamestate determines who (if anyone) is to move in the current position