• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Jake Mauve
Ranch Hand
Posts: 45
Java
  • Mark post as helpful
  • send pies
  • 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
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Likes 2
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Saurabh Pillai
Ranch Hand
Posts: 541
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
 
Matthew Brown
Bartender
Posts: 4568
9
  • Likes 2
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!