Hey everyone,
So I'm trying to figure out the best way to code the decision-making process of the simple AI I'm implementing. The only way I can think of doing it is going through a list of available moves to make, and checking every single position's row/column/diagonal(in a few cases), and every position in that row/column/diagonal to see what move is the best one.
I'm just wondering if you guys can think of any more efficient ways to accomplish this? I'm stuck with this procedural solution currently, and it just looks hideous - not to mention it's somewhat replicating code that I've already written.
What do you think?
(Sorry if this is in the wrong forum.)
Tic Tac Toe simulator - AI implementation
Page 1 of 15 Replies - 1451 Views - Last Post: 11 July 2012 - 05:32 AM
Replies To: Tic Tac Toe simulator - AI implementation
#2
Re: Tic Tac Toe simulator - AI implementation
Posted 10 July 2012 - 11:01 AM
The approach you described is the traditional way most game AI's work in larger problem space games.
With tic-tac-toe, since the problem space is so much smaller, you can do a lot more heuristics, and look up tables for what the next move should be. Most chess programs use an opening moves lookup table for the early phases of a game. I used to have an old learning assembly on the 6502 book, and it had a tic-tac-toe solution that used a lookup table of moves where the entire table was less than 64 bytes (if I recall correctly). Building the tables was tedious, but the code to lookup the next move was elegant. I wish I didn't give away that book.
With tic-tac-toe, since the problem space is so much smaller, you can do a lot more heuristics, and look up tables for what the next move should be. Most chess programs use an opening moves lookup table for the early phases of a game. I used to have an old learning assembly on the 6502 book, and it had a tic-tac-toe solution that used a lookup table of moves where the entire table was less than 64 bytes (if I recall correctly). Building the tables was tedious, but the code to lookup the next move was elegant. I wish I didn't give away that book.
This post has been edited by Skydiver: 10 July 2012 - 11:10 AM
#3
Re: Tic Tac Toe simulator - AI implementation
Posted 10 July 2012 - 11:53 AM
If you could post some of the "ugly" code segments we could help you make it more efficent/elegant.
But that is the way you would handle AI for tic-tac-toe. You would start by checking all of the moves that would garuntee a win. Then, the ones that would prevent a win. Then all of the ones that would move tward a win.
You could go another step by figuring out all of the possible games that could be played and just make the program play the game that would best fit the game so far. But that would take some time. This is like the solution skydiver gave above.
But that is the way you would handle AI for tic-tac-toe. You would start by checking all of the moves that would garuntee a win. Then, the ones that would prevent a win. Then all of the ones that would move tward a win.
You could go another step by figuring out all of the possible games that could be played and just make the program play the game that would best fit the game so far. But that would take some time. This is like the solution skydiver gave above.
This post has been edited by dartoscoder: 10 July 2012 - 11:54 AM
#4
Re: Tic Tac Toe simulator - AI implementation
Posted 10 July 2012 - 08:22 PM
Would this work? An array that holds a weight/bias for that position.
The array is filled with 0 for a position already filled, and 1 for a vacant square.
A row is checked, if there are opponents the vacant squares are incremented. etc.
The position with a maximum weight can be the next played position.
The array is filled with 0 for a position already filled, and 1 for a vacant square.
A row is checked, if there are opponents the vacant squares are incremented. etc.
The position with a maximum weight can be the next played position.
#5
Re: Tic Tac Toe simulator - AI implementation
Posted 10 July 2012 - 10:35 PM
#6
Re: Tic Tac Toe simulator - AI implementation
Posted 11 July 2012 - 05:32 AM
Thanks very much for all of the replies! I'm not sure I'm looking to create an AI that progressively learns as more games are played, just a simple AI that will have very basic decision making. I suppose I'll just continue with the procedural solution I've been writing, as it seems to be the most straight-forward way to accomplish what I'm aiming to do.
If anyone happens to look back at this post, where should I look to start learning how to make simple graphics that will present this simulator?
Thanks again for all of your help!
If anyone happens to look back at this post, where should I look to start learning how to make simple graphics that will present this simulator?
Thanks again for all of your help!
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote






|