This week's book giveaway is in the Server-Side JavaScript and NodeJS forum.
We're giving away four copies of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques and have Mario Casciaro & Luciano Mammino on-line!
See this thread for details.
Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

TicTacToe user vs computer

 
Ranch Hand
Posts: 424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43026
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43026
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
He's giving us the slip! Quick! Grab this tiny ad!
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic