codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:



Javascript Tic Tac Toe

Article by: Premshree Pillai (10/10/2002)
Bookmark us now! Add to Favourites
Email a friend!Tell a friend
Sponsored by: Neil Matthews Hypnotherapy, Wilmslow
Summary: Play against the computer and learn a crafty bit of Javascript with this simple game.
Viewed: 27322 times Rating (375 votes): 
 5 out of 5
 Rate this Article  Read Comments  Post Comments

Javascript Tic Tac Toe



View Online Demo
Download Project (11KB)

The game is written in JavaScript and works with IE 5+/NS 6+.

The Rules of the game are simple :You win if you get a complete row or complete column or any complete diagonal.

The game has been written in such a way that, the computer always tries to block the player's path. This is how the Game works :

First select who plays first. When the computer plays it's first move, it tries to place its token("0") in a diagonal position. In the course of the game, the computer analyses the number of rows, columns and diagonals with maximum number of the player's token("1"). If the computer already has a token in a particular row/column/diagonal, it gives that particular row/column/diagonal a low preference.

Thus it analyses the row/column/diagonal with maximum player's token and then places it's token in one of the empty spaces in that row/column/diagonal. A row/column/diagonal which is full is given low preference.

We'll put the main javascript here on the page, but to experiment with the entire project, we recommend downloading the zip file above and seeing how the various elements interweave.

Select All Code







CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
Rate this article:     Poor Excellent
View highlighted Comments
User Comments on 'Javascript Tic Tac Toe'
Posted by :  Archive Import (Priscilla Molina) at 19:52 on Sunday, November 17, 2002
It's very good!!
Posted by :  Archive Import (Jan) at 13:16 on Sunday, December 22, 2002
Thanks for the game, I love it. Its just what I have been looking for my site.
Posted by :  Archive Import (rylon) at 12:43 on Friday, May 09, 2003
can sum1 send it to me where i dont have to take out or enter stuff i am useing geocities pagebuilder(i im 14 trying to learn how to make a cool site for my friends)
Posted by :  Archive Import (Dan) at 05:18 on Tuesday, July 29, 2003
If you select centre, centre top, top right, centre right you win every time!
Posted by :  k111 at 14:31 on Friday, January 16, 2004
i cant make it work in "Ready to Program" which i need it to work for my assignment...can u help me??


To post comments you need to become a member. If you are already a member, please log in .

 











Recent Forum Threads
• Re: Insert Contents of .txt file into a .html page
• Re: Perl regular expression problem.
• Re: Problems in login using WWW::Mechanize
• searching for gd::graph guide
• Re: ARRAY OF HASHMAPS
• Adv. Regexp or Otherwise
• Adv. Regexp or Otherwise
• I need help pleasee! My project is about using I/o Stream
• Help Running VB script in Windows 2003


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2008