An examination of TIC-TAC

An examination of TIC-TAC-TOE like games
by ROBERT C. GAMMILL
The Rand Corporation
Santa Monica, California
INTRODUCTIO~
DRAW STRATEGY.3 In other words, no LOSS STRATEGY
exists. This is because if a LOSS STRATEGY existed, X
could convert it to his own use and make it a WIN
STRATEGY. Thus, to paraphrase the above, between two
perfect players who completely understand an n k TIC-TACTOE game, there can be no LOSS. The only possibilities are
WIN and DRAW. When a game of this class has been
solved, it means that a WIN STRATEGY or DRAW
STRATEGY has been produced. Games for which solutions
exist are characterized by the type of strategy which has
been found. It is well-known that TIC-TAC-TOE is a draw
game. In the material which follows we will examine a
method developed by Erdos and Selfridge4 which provides a
draw strategy for a large number of n k TIC-TAC-TOE
games. First some examination of the properties of n k boards
is needed.
There is a class of games which resemble TIC-TAC-TOE.
These are games where two players alternately put X's and
O's into playing spaces, attempting to get n of their signs in
a row. Well-known games of this class are TIC-TAC-TOE
(3X3) and QUBIC (4X4X4). The boards of these games
form squares, cubes and hypercubes with n playing positions
on a side. We will speak of these games as n k TIC-TAC-TOE
following Citrenbaum. 2
Many games in this class are trivial, such as TIC-TACTOE (n=3, k=2), while others display considerable character. QUBIC (n=4, k=3) is an example of one of the
latter. No solution is known for the game of QUBIC. It is
commercially distributed and a number of computer programs have been written to play it.1,8 Most of those programs
have demonstrated a rather poor understanding of the
intricacies of QUBIC.
In the material which follows we will examine a number
of results which hold for all n k TIC-TAC-TOE games. These
results demonstrate that QUBIC is the smallest unsolved
member of the class. Means will be shown by which a solution
attempt is being undertaken. A computer program which
plays QUBIC will be described and its use in developing
strategies and moving toward a solution will be discussed.
Board properties
It is important to have a number of equations at hand
when examining n k boards. Equation (1) gives the number of
lines in an arbitrary n k board. -
L=
_(n_+_2_)k___n_k
2
(1)
Different points in an n k board will have differing numbers
of lines through them. This makes some points more powerful
than others. We will need to know the number of lines
passing through the most powerful point on the board. When
n is odd, the centermost point of the board is the most
powerful. Equation (2) gives the number of lines through
that center point when n is odd.
n k TIC-TAC-TOE GAMES
Some notation will be needed for a concise exposition.
Table I gives the needed terms. Some of the terminology
(e.g., LOSS) may appear strange unless one accepts our
predeliction for defining the board state from X's point of
VIew.
3k - l
2
LCP= - -
No loss strategy exists
(2)
When n is even, there is a collection of most powerful points.
The number of lines through these points is given by equation (3).
One might think that DRAW STRATEGY should have an
alternative meaning when it is a strategy for X, but it turns
out that X should not be interested in DRAW for these
games. This is because it is known from game theory that, in a
finite two-player perfect information game, either the first
player has a WIN STRATEGY or both players have a
(3)
These equations and many more can be found in Reference 2.
349
From the collection of the Computer History Museum (www.computerhistory.org)
350
National Computer Conference, 1974
This means that equation (7) holds whenj is odd.
TABLE I
MEANING
TERM
V(B j +2 ) = V(B j )
A playing position where an X or 0 may be
placed.
A sequence of n points, which when covered by
LINE
X's will produce win.
Pieces played by first player, also his name.
X
Pieces played by second player, also his name.
o
A configuration of pieces on the board.
STATE
A state where first player (X) has won.
WIN
A state where first player has lost (i.e., 0 wins).
LOSS
A state from which neither WIN nor LOSS
DRAW
can be reached.
STRATEGY
A plan of action for a player.
WIN STRATEGY
A plan (for X) which reaches WIN, no matter
what 0 does.
A plan (for 0) which reaches LOSS, no matter
LOSS STRATEGY
what X does.
DRAW STRATEGY A plan (for 0) which reaches DRAW, no matter
what X does.
POINT
Draw strategies
Erdos and Selfridge4 have devised a strategy by which 0
may achieve draw under certain conditions. In order to
describe the strategy a number of definitions are needed.
Table II defines the Erdos-Selfridge value of a line.
TABLE II-Erdo.s-Selfridge Line Values
Character of line L
VeL)
o
One or more O's (blocked)
empty
1 X, no O's
2 X's, no O's
n X's, no O's
1
2"
V(B) =
x: VeL)
(4)
V(M) =
L
(5)
VeL)
MEL
From the above, the following sequence of equations (6) can
be deduced.
V(Bo) = number of lines on the board = initial board value
= V(Bo) + V(M1 )
=
(7)
If 0 picks his moves so they always have the maximum
possible value (the Erdos-Selfridge strategy) then equations
(9) and (10) are true when j is odd. Equation (9) holds
because placing an 0 on a point (Mi+l) causes all lines
through that point to take value zero. Points contained in
those lines may then have reduced value. No point will have
increased value. Thus, the value of X's next move V(M j +2 )
cannot be greater than the value of O's move V(M j +1 ).
V(Mi+I) ~ V (M j +2 )
V(Bi+2) ::; V(B j )
(9)
(10)
It is clear that a WIN board state must have a value V(B)
which is greater than or equal to 2n , since at least one line
must have n X's in a row. This means that if V(B j ) <2n for
any oddj, 0 can prevent X from winning, since all succeeding
V(B;) wherej is odd will be no greater.
Finally, if the maximum possible value of V(B 1 ) is less
than 2n , 0 can use the Erdos-Selfridge strategy to achieve
draw every time the game is played. The maximum value of
V (B I ) is the number of lines on the board plus the value of
the best possible move. That best move will be the· point
which has the most lines through it. Thus, using equations
(1) through (3) we produce equations (11) and (12), which
specify a test for an n k game being drawn for n odd and n
even respectively.
(if n odd)
(11)
(if n even)
(12)
The smallest interesting game which satisfies these equations
is (n=4, k=2) 4X4 TIC-TAC-TOE. Working out an
example for that game is an instructive exercise.
It should be emphasized that this technique not only
characterizes complete games, but if at any time the board
state value after X's move dips below 2 n , the Erdos-Selfridge
criterion declares that draw has been reached.
The Erdos-Selfridge strategy does not apply to TIC-TACTOE, i.e., the criterion is not satisfied after the first move.
However, it is well-known that TIC-TAC-TOE is a draw
game. Games which are known to have draw strategies are
summarized in Table III.
board value after first move (by X)
V(B:!) = V(B 1 )
=
V(2Jfj +1) + V (M j +2 )
2
4
The value of a board state V(B) is the sum of the values of
all lines on the board (4). The value of a move V (M) is the
sum of the values of the lines passing through that point,
before a piece has been played there (5)
V(B 1 )
-
-
VV"in strategies
V(~~f;.:)
board value after second move (by 0)
(6)
Win strategies are known for a number of n k games. In
most cases these games are so trivial that the strategy need
not be explained. However, 33 TIC-TAC-TOE. has a win
strategy and a simple explanation may be needed. The initial
move should; of course, be in the centermost point, '~vhich is a
member of 13 lines. Thereafter, it is almost impossible for 0
From the collection of the Computer History Museum (www.computerhistory.org)
An Examination of TIC-TAC-TOE Like Games
351
TABLE III-Summary of nk games
n, the number of points in each line
7
6
9
8
10
5
1
6
1
7
1
8
1
9
1
10
1
1
1
2
1
3
1
W
ESD
ESD
ESD
ESD
ESD
ESD
ESD
ESD
ESD
1
4
4
6
9
8
16
10
25
12
36
14
49
16
64
18
81
100
22
W
W
D
ESD
ESD
ESD
ESD
1
13
8
28
64
76
125
109
216
148
343
193
W
W
27
49
W
?
?
?
1
40
16
120
81
272
256
520
625
888
W
W
CW
?
2
4
k=2
k=4
5
4
1
k=1
k=3
4
3
2
E-S number
8
16
Wmeans WIN
DmeansDRAW
ESD
20
ESD
ESD
512
244
729
301
1000
364
?
ESD
ESD
ESD
1296
1400
2401
2080
4096
2952
6561
4040
10000
5368
?
?
?
32
64
Summary of n k games
In Table III are summarized the results which are known
concerning various n k TIC-TAC-TOE games. From the table
it is clear that QUBIC is the smallest game for which no
solution exists.
Two interesting conjectures stem from the table.
(a) Conjecture due to Citrenbaum:2 If n5:k then the game
has a winning strategy. If n>k then it has a draw
strategy.
(b) Conjecture due to Gammill: If the number of lines is
greater than or equal to the number of points in the
board, the game has a win strategy. Otherwise it has a
draw strategy.
2
128
256
512
points
lines
strategy
points
lines
strategy
points
lines
strategy
1024
CW means Citrenbaum WIN
ESD means Erdos-Selfridge DRAW
to achieve draw. Every time X moves, 0 must block on the
opposite side of the cube. If X makes a move that produces
two X's in a line in the cube side, he will also probably have
produ,ced a line of two X's through the center. The simultaneous production of two lines of two X's results in a win,
since 0 cannot block both.
A theorem by Citrenbaum2, page 113, states that if an
n k game has a win strategy, then the same strategy will
apply for k larger than that. The reasoning is that if a winning
strategy can be carried out on a k-dimensional board, it can
be carried out in a sub-cube of a k+ 1 dimensional board, etc.
The extra dimensions simply allow more space for 0 to spread
his responses over, weakening his defense. Thus, we now know
that all n=3, k~3 games have a win strategy.
(n+2)k- n k
?
points
lines
strategy
Succeeding sections will describe methods used in the
attempt to find a solution (strategy) for the game of QUBIC.
QUBIC
In the preceding sections we have shown that QUBIC
is the smallest nontrivial n k TIC-TAC-TOE game. QUBIC
is interesting from a number of points of view. It is a simple
enough game to serve as a fruitful test-bed for ideas in
strategy analysis. By contrast with chess or checkers, it has
such simple rules and structure that the data processing tasks
do not overcome the more interesting (and important)
analysis tasks. However, despite the simplicity of the game
the size of the board state space is sufficient to preclude
brute force analysis (64! by unsophisticated methods). Like
other sophisticated games (e.g. checkers and chess) it has
phases of play which exhibit differing properties and require
rather different kinds of analysis. The three phases of QUBIC
are represented in the table below.
TABLE OF QUBIC PHASES
PHASE
OPENING
MIDDLE
k· r
.
>n Imp les WID
END
Note, from the table, that this means that Citrenbaum
assumes that a draw strategy will be found for QUBIC while
the author assumes a win strategy will be found. Both conjectures are supported by all presently known information.
CHARACTER OF THE PHASE
Usually the first 5 to 7 moves. No direct
threats occur and no defensive play is necessary. Primary goal is gaining control of board
resources (lines and planes) .
Threats and counter threats occur continually. Every move has both an offensive
(threat creation) and defensive (threat
elimination) component.
An unstoppable threat is created by one of
the players. The other player may stall, by
creating mh'10r threats which must be fended
off, but ultimately he is forced into completely defensive play until finally he loses.
From the collection of the Computer History Museum (www.computerhistory.org)
352
National Computer Conference, 1974
In order to examine the analytic tools which are useful in
each of the phases, we must examine some specific features
of QUBIC.
The QUBIC board
1 also shows how the transformations look when applied
in the 42 game. The result of the 192 automorphisms of
QUBIC is that on an empty board all the rich points are
automorphic images of one another, and likewise for all the
poor points. Thus, the first move of the game involves a
simple choice, whether to playa rich or poor point.
The following facts are known about the board.
The opening game
ELEMENT
NUMBER
POINTS
LINES
PLANES
RICH POINTS
POOR POINTS
64
76
18
16
48
Rich points are those that are members of seven different
lines. Poor points are members of only four lines. Rich points
are cube corner and interior points (elements of main diagonals). Rich points capture more lines for a player, so opening
play is usually limited to them.
The QUBIC board is large enough so that brute force
examination of all possible games is not productive. However, many seemingly different games are actually the same,
although rotated, reflected or otherwise transformed. Silver:>
has shown that QUBIC has a group of 192 automorphisms.
This includes the 48 standard axis transformations of the
cube due to rotation and reflection. Added is a factor of 4
more automorphic images due to three "scrambling" transformations. These transformations do violence to the layout
of the cube, but have no effect on the game of QUBIC.
Perhaps the best way to describe them is to show hO\v they
transform a position. If we describe a position using matrix
notation (i, j, k) where the range of indices is 1 to 4, then
Figure 1 gives the transformations. For example, using transformation 1, the position (1,2,3) becomes (2, 1,4). Figure
TRA NSFO RMA TlO NS
( __ means "changes to")
1--2, 2--1, 3-4, 4--3
(inside out exchange)
2
1--4
(outside exchange)
3
2--3, 3--2
4--1
TRANSFORM 1
(inside exchange)
TRANSFORM 2
TRANSFORM 3
Figure I-Scrambling transfOIIflatioui:l applied on a 4X4 square
The 192 automorphisms as well as the fact that differing
sequences of moves can achieve exactly the same board state
cause a dramatic reduction in the number of different board
states which are possible in the QUBIC opening. The following table gives the number of distinct states, when play is
restricted to the rich points, oyer the first five moves. The
tabulated results were produced by computer enumeration.
TABLE
Comparison of number of states for first 5 moves
(on rich points) against number of distinct input
sequences.
MOVE
1
2
3
4
5
NUMBER OF
NUMBER OF
DISTINCT STATES POSSIBLE INPUTS
1
5
20
103
307
16
240
=15X16
3360 = 14X240
43680 =13X3360
524,160= 12 X 43680
It can be seen that the first five moves of QUBIC form a
finite automaton of 436 states (when play is confined to rich
points). Furthermore, if we are d~fining a winning strategy
for the first player (X), then only the best move from each
state where X plays need be defined. This results in only 12
possible states after three moves have been made. Thus, as
more becomes known about the middle game, it should be
possible to find optimal paths through the opening by a process of enumeration.
The end game
The end game is the best understood aspect of TIC-TACTOE games. The end game involves forcing sequences, where
one player makes moves which require a specific reply by the
opponent to prevent a loss. This sequence ultimately culminates in a win by the forcing player. Figure 2 shows two
examples. Example (a) is the simplest form of forcing
sequence, requiring only three moves. Example (b) shows a
common eleven move forcing sequence. The examples are all
planar subparts of the QUBIC board. Forcing situations like
that of example (b) are extremely common. Anytime three
pieces of one player occupy a plane, without interference from
From the collection of the Computer History Museum (www.computerhistory.org)
An Examination of TIC-TAC-TOE Like Games
the opponent, it is likely that an eleven move forcing sequence
can be found. Despite the importance and frequency of
occurrence of this "three-in-a-plane" situation, many QUBIC
players (people and computers) do not know about it. A
classic example is a game listed in Reference 6 shmving a game
played between a person and a computer program (written
by Dalyl). In that game the person creates a situation like
example (b), the program fails to make a defensive (blocking) move, the person fails to use his forced win, and thereafter the computer forces a win. Regrettably this "double
blunder" game has been presented as an example of a skillful
computer beating a person at QUBIC. Competitive play,
like the ACM Computer Chess Tournaments, appears to be
the best way to improve the quality of play.
EXAMPLE (b)
EXAMPLE (a)
Situation
Situation
11 move playing
sequence
3 move playing
sequence
1 5 8 7
10 X 11
3 X X 4
The force language
Citrenbaum 2 and the writer have independently devised
graphical notation systems (languages) for representing and
recognizing a forcing situation. Where Citrenbaum has
achieved slightly greater generality, creating a notation
suitable for representing forcing situations in positional
games (of which n k TIC-TAC-TOE is a subclass), the author
has developed a language especially suited to QUBIC. Unlike
Citrenbaum's notation, the graphical language to be presented here has been implemented in an efficient program for
finding extremely complex forcing sequences. Sequences containing as many as 31 moves have been found. No depth
limit is set. The following table presents the elements of the
language.
TABLE OF LANGUAGE ELEMENTS
ELEMENT
MEANING
@
Line containing n X's
o
353
Unplayed point
Membership (point in line)
Line containing 2 X's, showing
its two unplayed points
Using these elements we are able to describe the forces ,,,,hich
were shown in Figure 2. It is not necessary to show all of the
lines in each plane, only those lines directly involved. Figure
3 shows the representation of the forces from Figure 2. The
number next to each point indicates the order in which
moves occur. Odd numbered moves are X and even moves
are O.
From the graphical force descriptions shown in Figure 3 a
general characterization of all forces can be produced. To
start a force requires at least one line containing two X's. To
continue the force requires intersection with a line containing
one X, or two intersections with an empty line. Figure 4
provides a graphical description of the configurations which
9
6
2
Odd numbered moves are X
Even numbered moves are 0
Figure 2-Two examples of forcing situations and the playing sequence
leading to WIN"
make up forces in part I and examples of some actual forces
in part II.
The ability to describe forces in QUBIC provides a powerful new tool. It appears that the language describes all
possible forces, but no formal proof has been carried out. An
important side effect, not described by the language, is that
the force may not work if any of O's replies (even numbered
moves) are forced into a line where 0 has two pieces. This has
been termed a counter-force by Gilmartin,7 because it forces
X to defend rather than continue the force. The solution to
counter-forces is to avoid them or to order the forcing moves
so that the reply which counter-forces is last, allowing the
winning move to be made next. Gilmartin has also described
an interesting case where forces and counterforces interact in
a complex manner, as shown in Figure 5.
The program
A QUBIC playing computer program has been written
using the methods described in the preceding sections. The
most important features of that program are the following:
(1) A module capable of responding to direct threats,
collecting easy wins, and handling other obvious
tactical situations.
(2) A module capable of finding and playing out a force,
if one exists.
(3) A module capable of evaluating moves in terms of
resources (e.g., lines and planes) controlled, and
ordering those moves in a (best first) plausibility
list. No searching is carried out.
From the collection of the Computer History Museum (www.computerhistory.org)
354
National Computer Conference, 1974
Example (b)
Example (a)
0 0
;!.~-.~
~
X
X
X
X
0 0
X's turn to play (play anywhere)
Figure 3-Graphical representation of Figure 2
Figure 5-Situation where X wins, but every forcing move produces a
counterforce
(4) A module capable of finding forces available for the
opponent. This module finds the most plausible move
(if one exists) which prevents all forces by the
opponent.
This program plays a good game of QUBIC, but of course
that statement cannot easily be verified. The surest method of
verification is competitive play. The program has beaten
many good players, but competition with other good players
(computers or humans) is actively being sought.
Perhaps the most interesting facet of the program is that
it is much more capable of recognizing board states that
contain forcing sequences than is any human being observed
1. GRAPHICAL CONFIGURATIONS OF THE FORCE
(0) FORCE STARTING (i odd)
(b) FORCE CONTINUATION (i, j and k odd)
~
i
6 rj
Pj + 1
~
~
j >i
Pj
P
k+I
Pk-k>i
k >j
(c) FORCE COMPLETION (i, j and k odd)
II.
EXAMPLES OF ACTUAL FORCES
2
~
2
135
1
2
X X2 1
5
X
X 4
4
1 4 3 X
9 X 510
11 8 X
6 2
so far. This has had the interesting result that the program
has taught a number of experienced QUBIC players, including the writer, to playa better game. This is accomplished by the module described under (4), which eliminates
moves that fail to defend against a force threat. So many of
the middle game board states contain forces or force threats,
that games between humans invariably contain a number of
blunders (normally not as obvious as the game mentioned
above from Reference 6). Thus, modules of the program can
serve as analysis tools for human players. It is particularly
useful, for example, to have the program produce the small
set of different moves which will prevent a force by the
opponent and for the human to select that move from the
set that captures maximum resources or threatens the opponent with a force. Up until recently the program had been
organized to act as an independent player (maldng all its
own decisions). As a result of the feeling that in some ways
the program has superior capabilities (e.g. in recognizing
force states) but in others (e.g. strategic reasoning) the human
is better, the program has been reorganized to allow maximum interaction with a human player (i.e., kibitzing).
Where the program formerly would playa game as either
X or 0, now it may play both sides but accept advice from a
human observer. Another mode is for the program to serve
as an adviser (to a human player who is playing one or both
sides) suggesting sets of moves or warning against certain
moves. This can allow the human to act as a QUBIC researcher, and play out a sequence of moves that appears
interesting. When the consequence of a particular move
sequence has become clear, the game can be backed up to the
last point at which X or 0 may have had a stronger move. A
kibitzing or research mode like this might be a valuable
addition to computer chess playing programs, as it could
allow testing and improvement of the program's capabilities
through the posing and solution of sample problems. The use
of these research modes of the program have substantially
advanced our knowledge of the game of QUBIC. Much work
remains to be done, but slo'Nly the game of QUBIC is yielding
its secrets. The time when a solution (strategy) can be
reported appears to be approaching.
Multiplanor
SUMMARY
Figure 4-Graphical force ianguage and example forces
nic TIC-TAC-TOE games have been examined and it has
been demonstrated that QUBIC (43 ) is the smallest non-
From the collection of the Computer History Museum (www.computerhistory.org)
An Examination of TIC-TAC-TOE Like Games
trivial member of this class of games. The knowledge and
methods used in research toward a solution of the game have
been outlined. Finally, a QUBIC playing program which has
been modified for use as a research tool has been described.
REFERENCES
1. Daly, William, Computer Strategies for the Game of Qubic, Masters
Thesis in E.E., MIT, Cambridge, Mass., Jan. 1961.
2. Citrenbaum, Ronald L., Efficient Representations of Optimal Solutions for a Class of Games, Systems Research Center Report SRC69-5, Case Western Reserve University, 1970.
355
3. Blackwell, D. and M. A. Girshick, Theory of Games and Statistical
Decisions, Wiley, New York, 1954, p. 21.
4. Verbal Communication with Prof. Andrezej Ehrenfeucht, Dept. of
Computer Science, U. of Colorado, concerning unpublished paper
by Erdos and Selfridge.
5. Silver, Roland, "The Group of Automorphisms of the Game of 3Dimensional Ticktacktoe," American Mathematical Monthly, Vol.
74, 1967, pp. 247-254.
6. Slagle, James R., Artificial Intelligence: The Heuristic Programming
Approach, McGraw-Hill, New York, 1971, pp. 38-39.
7. Gilmartin, Paul, An Efficient Algorithm for Detecting Forces in
QUBIC, Department of Computer Science, University of Colorado,
January 1973 (unpublished paper).
8. King, Paul F., A Computer Program for Positional Games, Report
1107, Jennings Computing Center, Case Western Reserve University.
From the collection of the Computer History Museum (www.computerhistory.org)
From the collection of the Computer History Museum (www.computerhistory.org)