Sorry, your browser does not support Java.

This web page is a Java applet to play the child's game of Tic-Tac-Toe (also known as Ticktacktoe, X's and O's, Naughts and Crosses).  Click the mouse on a position of your choice.  You are the magenta X's, and you move first.  The computer has the blue O's.  To win, you must have a complete horizontal line, a complete vertical line, or a complete diagonal line.  There can be several diagonals.  Winning lines are shown in red.

For instructions on how best to play the game ... ask a child!  The only weird part is that the number of rows and columns can be different.  The computer plays a reasonably good game but can be easily beaten on a small game board.  The first person to move can't lose ... unless they make a mistake.  We are often blinded by our own planning.  If the board has three rows and five columns, you concentrate so much on winning in one direction that you don't see the computer's move in another direction until the game is over.  As the board gets larger, you have more trouble seeing all the possibilities.  The computer's algorithm doesn't miss an opportunity.


If this web page begins with an error message saying that your browser does not support Java, then either your computer doesn't have Java, or Java is not enabled.  If you see an empty rectangle where the applet should be, then you have Java but need a newer browser or a newer version of Java.  For Internet Explorer 5 or later, Firefox, Mozilla, and Netscape 7.x or later on Windows, you may download the Sun Java run-time environment (JRE) from http://www.java.com/getjava/ on Sun's web site.  This program was written on and tested against Sun Java 1.4.

The source code for this applet is available, even though writing a similar Java program is an assignment for students, and I'm sure that some students won't do their own homework.  (Hint: six special cases for traversing lines in the game board can be replaced by one generalized method using starting positions and directions.)  You may also download the application as a ZIP archive with the executable Java class files and the documentation in Adobe Acrobat PDF format.  More programming assignments and solutions can be found on my "Computer Programming Examples" web page.

Copyright (c) 2004 by Keith Fenske.  Released under the GNU General Public License (GPL).