• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

About tic tac toe game (Im not asking for the source code!)

 
Ranch Hand
Posts: 45
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello fellow ranchers !
I had fun making a tic tac toe game. I've got the whole thing running and displaying as it should, taking in coordinates for non-computer players. Initially I had the computer player place moves at random, but thats only fun the two first runs :p
So then I thought I'd implement some basic non random moves.
Can anyone give me some direction, or hints, as to how I'm supposed to do this without making it into a basic table-driven agent involving pre-defining all possible scenarios and actions to take from there ? Thank you very much ! I'm specifically not asking for the final 'answer' or the source code, I want to develop this thing on my own but I welcome help and imput ^^

Thanks a lot !
J
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I presume you're talking about the standard 3 X 3 tic-tac-toe grid. The second player can always force a draw, provided his first move is right: it the first player takes a corner, take the center and if the first player takes the center, take a corner.

That might give you a starting point for your AI, or not
 
Jake Mauve
Ranch Hand
Posts: 45
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks a lot ! =)
but then, there is no way of making a basic Ai without using complex concepts like algorithms and/or non-basic programming concepts (my fluency in java is still very basic and I've just started learning about algorithms, in general, none specifically yet) to avoid using an extensive tree of possibilities/scenario's which even for a 3x3 grid becomes quite large after three moves ? (sorry for the long question :p)
Thanks for the help !
J
 
Ranch Hand
Posts: 541
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
3 X 3 (one player) becomes pretty lame after you know the trade secret as Darryl pointed out. But that is a good starting point, and later you can expand for N X N grid. Don't want to increase complexity for you, but later you might want to look into MinMax algorithm.

I would also suggest, don't go for static/fixed solution which is easy for 3 X 3 grid rather implement in a way to find winning patterns.

Good Luck
 
Bartender
Posts: 4568
9
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, if you want to avoid scanning the whole tree, while still making it vaguely sensible, the first thing I'd suggest is adding some logic so that it can
- detect a one-move win for itself and take it
- detect a one-move win from the opponent and try and stop it.

So in this situation (computer X):
X--
-O-
-O-

it would always go top centre, and in:
XX-
-OO
-O-

It would always go top right

After that, I'd maybe add some simple heuristic rules for other cases. E.g. prefer the centre if available, prefer corners over sides. It won't be perfect, but it won't be terrible.
 
Jake Mauve
Ranch Hand
Posts: 45
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
awesome thanks !
one idea I had, but I don't know if it would help or make things more complicated was to put in three 'boolean' counters. What I mean is,

they would apply to each player individually and serve to indicate how many 'marks' are aligned. So that when "second" for the human player goes true before the cpu's "second" counter, it would only aim to block. If both second counters are true then it would first try place the third (winning) mark or if not, stop the other player from winning (assuming a non tricky situation), but implementing this just seems like extra work that wouldn't necessarily make things easier/simple for me. and if I dont use all three counters, I could at minimum implement just the one to indicate when the human player has two marks aligned for the block and otherwise try to win.
I'll try to implement it and see what happens ^^
thanks again for the help peeps ! x)
Kris
 
reply
    Bookmark Topic Watch Topic
  • New Topic