aspose file tools*
The moose likes Game Development and the fly likes TicTacToe user vs computer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Game Development
Bookmark "TicTacToe user vs computer" Watch "TicTacToe user vs computer" New topic
Author

TicTacToe user vs computer

ahmed yehia
Ranch Hand

Joined: Apr 22, 2006
Posts: 424
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.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42906
    
  69
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

Joined: Apr 22, 2006
Posts: 424
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
Marshal

Joined: Mar 22, 2005
Posts: 42906
    
  69
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: TicTacToe user vs computer