Tic Tac Toe AI
I''m going to be making a Tic Tac Toe clone in C++ and I''m wondering, how am I going to do the AI? Also, I have never programmed any AI at all.
There''s no town drunk here, we all take turns.
Velocity Gaming Force
go through every single move the computer can do and at every move go through every possiblity that the opponent can do. If any of the opponents moves make you loose don''t do them. then do the same thing backwards and see if there is any move that the computer can do that will force the computer to win no matter what. Look like two moves ahead and you will be fine.
sorry I don''t have much time to explain now, did any of that make sense to you?
I must''ve told you a million times, don''t over-exaggerate.
sorry I don''t have much time to explain now, did any of that make sense to you?
I must''ve told you a million times, don''t over-exaggerate.
I sort of get it but wouldn''t that take like 30 if statements?
[offtopic]
I like your sig by the way
[/offtopic]
There''s no town drunk here, we all take turns.
Velocity Gaming Force
[offtopic]
I like your sig by the way
[/offtopic]
There''s no town drunk here, we all take turns.
Velocity Gaming Force
Heh, if you do that it''ll be impossible for the player to win. I did a TicTacToe game with AI just a few weeks ago. Its harder than it seems
quote:Original post by DarkWhoppy
Heh, if you do that it''ll be impossible for the player to win. I did a TicTacToe game with AI just a few weeks ago. Its harder than it seems
Can you explain to me what you did? Or at least post a piece of your source?
There''s no town drunk here, we all take turns.
Velocity Gaming Force
Ekim_Gram:
I'm guessing the logic for a game like Tic-Tac-Toe (aka knots and crosses for them brits ) will take quite a few if statements, or comparisons between arrays to enforce the AI rules.
However, you should be able to cut back on the repition of things with a few recursive calls.
Anyway, try googling about for some examples of how to do the AI. (I'd suggest how to do it but I gave up on that one along time ago, found something more interesting to work on at the time )
[edited by - Kevlar-X on August 13, 2003 12:40:15 AM]
I'm guessing the logic for a game like Tic-Tac-Toe (aka knots and crosses for them brits ) will take quite a few if statements, or comparisons between arrays to enforce the AI rules.
However, you should be able to cut back on the repition of things with a few recursive calls.
Anyway, try googling about for some examples of how to do the AI. (I'd suggest how to do it but I gave up on that one along time ago, found something more interesting to work on at the time )
[edited by - Kevlar-X on August 13, 2003 12:40:15 AM]
there are many ways to program an AI for tic tac toe.
One way is to have a list of all possible board positions and then associate with each one the correct next move for each. This is good but not fun to write. (of course there is a lot of symmetry to tic tac toe so many variations are just the same but with the board rotated)
You can do a recursive tree structure that automatically puts a numerical value for each level based on the chances of a win... its cool to accomplish if you are interested in AI in and of itself.
You could also just go through each square at a time and then afterwards randomly fill the board in many times. Use a stat for each square and the one with the highest amount of wins for the computer gets selected.
whatever floats your boat.
One way is to have a list of all possible board positions and then associate with each one the correct next move for each. This is good but not fun to write. (of course there is a lot of symmetry to tic tac toe so many variations are just the same but with the board rotated)
You can do a recursive tree structure that automatically puts a numerical value for each level based on the chances of a win... its cool to accomplish if you are interested in AI in and of itself.
You could also just go through each square at a time and then afterwards randomly fill the board in many times. Use a stat for each square and the one with the highest amount of wins for the computer gets selected.
whatever floats your boat.
quote:Original post by Kevlar-X
(aka knots and crosses for them brits )
lol, its Naughts and Crosses. close though
An ASCII tetris clone... | AsciiRis
[threadjacking]Yeah, those brits! So like can I be british if I grew up in a british commonwealth country? Even only if until I was 10?[/threadjacking]
I made a tic tact toe game once except it was in VB and it had a very stupid AI. it''s on Vbcode.com. search for it. They have a few cool tic-tac-toe games.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement