![]() |
|
This thread is locked; no one can reply to it.
![]() ![]() |
1
2
|
tic tac toe game |
senthil kumar
Member #8,490
April 2007
|
hi, Im developing tic tac toe game in which i had tried most algorithms. Still i like to have a complex algo to make the player defeated. Anyone could give me any idea about it Also I try to zoom out the squares of tictactoe when it loads but i failed to do so. |
LennyLen
Member #5,313
December 2004
![]() |
Quote: Also I try to zoom out the squares of tictactoe when it loads but i failed to do so. Can you explain better? Posting some code would also help.
|
raja peter
Member #7,835
October 2006
|
i think you want to stretch the image loaded. use stretch_sprite() luv, raja |
senthil kumar
Member #8,490
April 2007
|
raja, I thought you are on leave and will be in church today (rajesh) ....:-/ |
raja peter
Member #7,835
October 2006
|
luv, raja |
Tobias Dammers
Member #2,604
August 2002
![]() |
Tic tac toe isn't hard, and there is an optimal strategy. Due to the limited number of possible moves, it shouldn't be hard to find, and it should be even easier to program it. --- |
gnolam
Member #2,030
March 2002
![]() |
Just make sure the computer can play itself. That could save the world some day. -- |
kentl
Member #2,905
November 2002
|
There are only 9! number of ways to play Tic Tac Toe (362880). So you could create a recursive algorithm which plays perfect. |
ImLeftFooted
Member #3,935
October 2003
![]() |
Let me see if I can do this from memory... If you go first, do:
If you go second, use these rules for deciding moves:
[/list] "General"
[/list] Quote: There are only 9! number of ways to play Tic Tac Toe If you make a logical algorithm (instead of recursive), the steps are quite a few less. Pretend for example you are player 2 and player 1 just made his first move to the center square. It appears you have 8 moves, but in reality you only have 2. |
piccolo
Member #3,163
January 2003
![]() |
the algorithm your looking for is called the MIn Max algorithm.
wow |
kentl
Member #2,905
November 2002
|
Dustin Dettmer said: If you make a logical algorithm (instead of recursive), the steps are quite a few less. Pretend for example you are player 2 and player 1 just made his first move to the center square. It appears you have 8 moves, but in reality you only have 2. Sure there are lots of ways to solve the problem. But as the worst case is to search through 9! combinations we're dealing with a trivial problem. I think we can all agree that if you go first taking the center is the way to go. This because that position interfer (for the enemy) or enables (for you) a solution from each of the 8 remaining positions. That way we have reduced the problem to a 8! search which is only 40320 combinations to look through at the second move. Piece of cake for a modern computer! After that we're dealing with a 7! search, which is 5040 game states. And so on. I would say that this is a typical case where brute force search is a nice solution. Picollos suggestion to use Min-Max is what I would suggest as well. There is a nice tutorial here: http://ai-depot.com/articles/minimax-explained/ |
piccolo
Member #3,163
January 2003
![]() |
in tic tac toe and the game i post above the min max algorithm is the best. its a no brainier that for a game like chest the min max algorith will have to be moded so it dose not take all day. but:-X he is not coding chess is he;) edit: i should have read all of it wow |
kentl
Member #2,905
November 2002
|
Quote:
edit: i should have read all of it
Yes I do agree with you. Still Dustins algorithm and other "hand crafted" algorithms are nice and fun to think about. [Edit] The more I think about it the more I like a hand crafted algorithm specifically for Tic Tac Toe. I still feel that a search is a clean and nice solution to the problem and that it's easier to not mess up and introduce a human error. But if we can do it without a search that's pretty appealing too. |
Matthew Leverton
Supreme Loser
January 1999
![]() |
Quote: That way we have reduced the problem to a 8! search which is only 40320 combinations to look through at the second move. Piece of cake for a modern computer! After that we're dealing with a 7! search, which is 5040 game states. And so on. First, there's not even 9! solutions because most winning solutions don't even go 9 moves. Plus, if you consider that many of the games are just mirror images of each other, that number drops drastically. There's only three possible opening moves (corner, side, middle), not nine. The rest of the board can be played relative to the first middle+corner piece. But figuring all that out is more difficult than just going through 9!. Quote: I think we can all agree that if you go first taking the center is the way to go. This because that position interfer (for the enemy) or enables (for you) a solution from each of the 8 remaining positions. Starting on the corner isn't bad either. For instance: X - - X - - X - - X - - X - X X - X X X X - - - - 0 - - 0 - - 0 - - 0 - - 0 0 - 0 0 - - - - - - - - X 0 - X 0 - X 0 - X 0 - X I find that above game is the easiest way to beat stupid people. After the first couple of moves, the rest of the moves are obvious. So I agree with Dustin; writing a brute force is actually more difficult than an impossible-to-beat AI. |
kentl
Member #2,905
November 2002
|
Quote: First, there's not even 9! solutions because most winning solutions don't even go 9 moves. Plus, if you consider that many of the games are just mirror images of each other, that number drops drastically. Yeah sure. It gives a rough estimation though and it's enough to conclude that the problem isn't very hard and that search algorithm could be used, like Min-Max (without Alfa-Beta pruning as it's not necessary). Quote: So I agree with Dustin; writing a brute force is actually more difficult than an impossible-to-beat AI. I'm leaning more towards this as well now that I've thought more about it (as I wrote above). But if you've got the Min-Max algorithm implemented in a generic and robust way already, then that's what I'd use. Quote: Starting on the corner isn't bad either. For instance: X - - X - - X - - X - - X - X X - X X X X I find that above game is the easiest way to beat stupid people. I can see that's a sneaky way to fool people who aren't used to the game, I don't necessarily think they're stupid though. It would be interesting to see all paths to a certain victory. That is, if there are more paths than one. If there's only one it feels logical that it should start in the center position. If there are multiple they're center and one of the corners. |
piccolo
Member #3,163
January 2003
![]() |
when programing the AI for tic tac toe you want to maximize the lanes for ubtaing a win wining. That is why you alway play in the middle first. in 1|2|3 ----- 4|5|6 ----- 7|8|9 when you play at 5 you can win at: 1,5,9 : 3,5,7 : 4,5,6 : 2,3,8. its greater then all other first moves. edit: wow |
Matthew Leverton
Supreme Loser
January 1999
![]() |
Quote: when programing the AI for tic tac toe you want to maximize the lanes for ubtaing a win wining. That is why you alway play in the middle first. In theory, yes. But not all victories are equal. You want to pick the route that produces the most wins. That might not be equivalent to picking the first move that produces the most number of winning possibilities. Starting in a corner might fool people more often. (I don't know.) If it does, then starting in the corner could possibly be better, despite it leading to fewer winning paths. Regardless of which approach has a higher probability of winning, letting the AI use multiple starting locations will feel more natural and will probably end up stumping the player more often (if he can be stumped at all). |
Paul whoknows
Member #5,081
September 2004
![]() |
Hahaha! I have easily won most online tic tac toe games using Matthew's strategy, only a few tied games tough. ____ "The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner. |
piccolo
Member #3,163
January 2003
![]() |
My teacher says then when programing Game AI you must all way assume the player play well and make the best moves all the time. you will lose playing the first move in the corner when playing an AI. But if you want to give the 2nd player a chance you can random the first move then apply the AI algorithm to the rest of the game. wow |
Matthew Leverton
Supreme Loser
January 1999
![]() |
Show me how starting in the corner guarantees a loss. And your teacher is incorrect. Humans aren't computers. They can be tricked. Sometimes a gamble pays off. The best AI is not one that always picks the "best" (in your sense of the word) route. For example, let's say Move A gives you 4 paths of winning and 2 paths of losing; Move B gives you 5 paths of winning and 1 path of losing. Move B is better, right? No, you cannot answer that. More information is needed. Maybe one of those paths in Move A is very clever and tricks most players. The probability of winning by Move A goes up. And that is what you should care about. The total number of winning paths is irrelevant if they are all so obvious, a blind man would see them. |
piccolo
Member #3,163
January 2003
![]() |
well ill say that if the you play in the corner you can not win playing someone who is good you can say the same for the middle as well. if both players play well the game will always end up in a tie. wow |
LennyLen
Member #5,313
December 2004
![]() |
Quote: well ill say that if the you play in the corner you can not win play some who is good you can say the same for the middle as well. Is that supposed to be "If you play in the corner you can't win. Play some one who's good, and you can say the same for the middle as well" or "If you play in the corner, you can't win playing someone who is good. You can say the same for the middle as well." The first seems to be what you mean, as it's closer to what you wrote, but it's also wrong. Now please try to use grammar in the future to avoid such ambiguities. It's what it's for.
|
anonymous
Member #8025
November 2006
|
Sorry to break the fun, but doesn't 3*3 tic-tac-toe always end in draw if both players make the best moves? |
LennyLen
Member #5,313
December 2004
![]() |
Quote: Sorry to break the fun, but doesn't 3*3 tic-tac-toe always end in draw if both players make the best moves? Yes. However, not everyone will always make the best moves, especially if they are used to the first player always starting at a particular position. So, stirring things up a little can throw people off, and cause them to make mistakes.
|
Arthur Kalliokoski
Second in Command
February 2005
![]() |
Couldn't you represent the chosen squares as bits in a 32 bit int? Each side would use 16 bits, high & low halves. | | |X | ----------- | | |O |X ----------- O| | | | (unused X bits) (valid X bits) (unused O bits) (valid O bits) would be 0000 0000 00 010 001 000 0000 0000 00 000 010 100 so that the top 3 squares would be the most significant "valid" bits, next row etc. Then you could store these in a two int struct that would have the sought pattern (sorted for binary search) with an optimal bit pattern for the next move (one more bit set than the sought int). You could have several optimal moves if possible for variety, set the most significant unused bits for "not possible" flags, e.g. if X started in a corner there'd be only 3 possible (1 optimal) move. They all watch too much MSNBC... they get ideas. |
|
1
2
|