Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

TicTacToe user vs computer

 
Ranch Hand
Posts: 424
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im developing an application which represents the popular game of TicTacToe,
its configured for 2 players, my project is to let user play vs computer.
I need guide lines on how to module such behavior.

the game:
In a game of Tic Tac Toe, two players take turns marking an available cell in a 3x3 grid with their respective tokens(either X or O). When one player has placed 3 tokens in a horizontal, vertical, or diagonal row on the grid, the game is over and that player has won. A draw (no winner) occurs when all the spaces on the grid have been filled with tokens and neither player has achieved a win.
 
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not quite clear on what you're asking - is it about how to design such a program, or about how the computer would choose the next move, or about something else?
 
ahmed yehia
Ranch Hand
Posts: 424
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I ve designed my class to work on 1 v 1, and could be modified to involve computer through invoking compMove() when in comp mode for example.
think the problem now is how to implement computer moves.
 
Ulf Dittmer
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you need to come up with how the computer will react to any given board setup. That's not too hard with TicTacToe, as there are only a limited number of situations that can be encountered. Before considering a move you'd probably want to check if the opponent has two in row with the third one open (in which case you'd put the piece on the open field). The corners are important, so it's good to put pieces there if possible (and if the opponents move was to put the first piece in a corner, then the computer needs to put its first piece in the opposing corner). Try to write down all the "rules" you as a human use during a match, and then see if you can translate those to code.
[ January 13, 2007: Message edited by: Ulf Dittmer ]
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic