Need to implement AI in TicTacToe
-
Hi, I am developing TicTacToe in which i finished working functionlity where 2 people will play. Now i want to add AI to my game what can be the best algorithm to do that. One more thing any piece of algorithm or any starting code would be very nice. Now just a real question lets say Player selected one box. Now its Computer turn. It has 8 possible moves how would you implement that can you give any idea in algorithm shape or Pseudocode please. I would probably not write code to evaluate each state individually, I'd write a state evaluator that checked for winning moves, blocking moves, and then potential moves based on difficulty. :confused: thanks
-
Hi, I am developing TicTacToe in which i finished working functionlity where 2 people will play. Now i want to add AI to my game what can be the best algorithm to do that. One more thing any piece of algorithm or any starting code would be very nice. Now just a real question lets say Player selected one box. Now its Computer turn. It has 8 possible moves how would you implement that can you give any idea in algorithm shape or Pseudocode please. I would probably not write code to evaluate each state individually, I'd write a state evaluator that checked for winning moves, blocking moves, and then potential moves based on difficulty. :confused: thanks
An obvious way is to write a system where it chooses moves randomly or semi randomly ( prefer the middle, then prefer the corners, etc, or whatever you think ) and remembers which moves lead to it winning. Obviously, some basic 'finish the row if I can win this turn' code also makes sense to have.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
Hi, I am developing TicTacToe in which i finished working functionlity where 2 people will play. Now i want to add AI to my game what can be the best algorithm to do that. One more thing any piece of algorithm or any starting code would be very nice. Now just a real question lets say Player selected one box. Now its Computer turn. It has 8 possible moves how would you implement that can you give any idea in algorithm shape or Pseudocode please. I would probably not write code to evaluate each state individually, I'd write a state evaluator that checked for winning moves, blocking moves, and then potential moves based on difficulty. :confused: thanks
I dont think you will need much in the line of AI. you could simply calculate all available moves and assign a weight to each move and choose the best one. You could even use some kind of probability to "see ahead" to try to guess what the opponents best moves may be given a certain move.
-
Hi, I am developing TicTacToe in which i finished working functionlity where 2 people will play. Now i want to add AI to my game what can be the best algorithm to do that. One more thing any piece of algorithm or any starting code would be very nice. Now just a real question lets say Player selected one box. Now its Computer turn. It has 8 possible moves how would you implement that can you give any idea in algorithm shape or Pseudocode please. I would probably not write code to evaluate each state individually, I'd write a state evaluator that checked for winning moves, blocking moves, and then potential moves based on difficulty. :confused: thanks
there're only 9! (363k) potential games. Brute force is a viable option.
-- You have to explain to them [VB coders] what you mean by "typed". their first response is likely to be something like, "Of course my code is typed. Do you think i magically project it onto the screen with the power of my mind?" --- John Simmons / outlaw programmer
-
there're only 9! (363k) potential games. Brute force is a viable option.
-- You have to explain to them [VB coders] what you mean by "typed". their first response is likely to be something like, "Of course my code is typed. Do you think i magically project it onto the screen with the power of my mind?" --- John Simmons / outlaw programmer
Agreed! Not very elegant but certainly viable.
-
Hi, I am developing TicTacToe in which i finished working functionlity where 2 people will play. Now i want to add AI to my game what can be the best algorithm to do that. One more thing any piece of algorithm or any starting code would be very nice. Now just a real question lets say Player selected one box. Now its Computer turn. It has 8 possible moves how would you implement that can you give any idea in algorithm shape or Pseudocode please. I would probably not write code to evaluate each state individually, I'd write a state evaluator that checked for winning moves, blocking moves, and then potential moves based on difficulty. :confused: thanks
I got to the same point a couple of years ago. As already stated, brute force (check every move possible) is viable in TTT as the number of moves is quite small. You might also like to read up on AI algo's like AlphaBeta - there is LOADS of reading online about AI. My head got a bit swallowed up by it all and thats why I never got any further with my TTT game. But I did learn a hell of alot anyway.