Sorry, your browser does not support Java.

This web page is a Java applet to play the pencil-and-paper game of "Dots and Boxes", also known as "Lines and Boxes".

The game board is a rectangular grid.  Dots are shown for the corners of the board squares.  Players take turns drawing the lines that surround each square: top, left, right, and bottom.  The player who completes a square by clicking on the fourth line gets that square.  At the end of the game, the player with the most squares wins.

Your squares are shown in black and the computer's squares are shown in white.

You may change the number of rows and columns.  The difficulty level may be selected as "easy" (computer moves randomly) or "medium" (computer tries to complete squares with three lines, and avoids squares with two lines).  More difficult levels have not been implemented, although the program does contain hooks for two additional levels called "hard" and "expert".

Some versions of "Dots and Boxes" force players to take particular moves, such as completing a board square if three lines are already present.  This version has no such restrictions.  As a result, not completing a board square can become a useful strategy towards the end of the game!


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: the rules are very relaxed in this game, so have some fun!  Try to avoid duplicating too many data structures.)  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).