Noughts And Crosses / Tic-Tac-Toe







You are X ( Computer is O )
You are O ( Computer is X )

You go first
Computer goes first
Computer plays aggressively
Computer resigns if losing


Results of
games so far



Remember scores between visits to this page


The program

This program plays the game of Noughts and Crosses ( or Tic-Tac-Toe as it is known in the USA ) using a simple JavaScript program embedded in this HTML file.

If you search the Web for Noughts and Crosses or Tic-Tac-Toe games you will be quite surprised to find how many there are, however, there seems to be two games in particular that have been taken from tutorial books on JavaScript and Java that are nothing more than the example programs re-badged and included on many owner's pages.

This program, I am proud to say, was developed from scratch and is not derived in any way from any example code obtained elsewhere.

The primary goals in writing this program were to -

  • Learn the JavaScript language and its nuances

  • Produce a program that was entirely JavaScript based and self contained

  • Produce a program that was highly efficient ( and quick ) when determining which moves to make and detecting when the conclusion to a game had been reached

  • Create a playing strategy for the computer oponent whereby it would always win or force a draw which could be efficiently implemented

  • Produce a program that was user friendly and enjoyable to play

  • Utilise Cookies to remember the score and other settings between games

I believe I have met those goals [ although there is some work to do on the computer opponent's aggressive strategy ] and, as well as playing Noughts and Crosses, this program clearly demonstrates the power of JavaScript.

The game

The normal rules of Noughts and Crosses ( or Tic-Tac-Toe ) apply; the player and computer take it in turn to place an O or an X on the board. When three O's or three X's are placed in a line ( left-to-right, top-to-bottom or diagonally ) the game is won. If neither three O's or three X's are in a line and there is no space left on the board then the game is drawn.

The player can chose to be either O's or X's and can chose to go first or let the computer start. If the computer is to go first then the Start Game or Start Again button must be clicked to commence a game.

The computer will normally play quite well but may be beaten unless the Computer plays aggressively option is selected when it will always play to win or force a draw [ this is not fully implemented yet and the computer can still be beaten ].

The computer can also be told to resign early if it realises that it can't win or draw and you can resign ( if there is no possibility of winning or drawing ) by clicking the Resign button. The Start Again button can be used to abandon a current game and start a new one.

If you have enabled the saving of cookies in your browser and have selected the Remember scores between visits to this page option; the scores after each game and your current game play selections will be stored when you leave this page and will be restored when you return to this page within two months ( the scores and settings will be lost if you do not return to this page within two months ).

You can examine the settings assigned to the cookie used for this page ( which is named $OXOscore ), and any others used on this site, by using the Cookie Editor provided.





Associated Articles

  The Cookie Editor



Site Navigation

  Home Page
  What's New
  Search
  Add Bookmark
  Have Your Say
  Guestbook




First published sometime before Friday the 10th of September, 1999
Last upload was on Tuesday the 23rd of September, 2003 at 19:28:10