Tic Tac Toe AI
Moderator:Moderators
can someone explain to me how to do a tic tac toe AI?(im using vb.net, but if you could just explain it to me somehow)
You find all the permutations left in the game and use the next move which results in the highest number of possible wins for you (while making sure your move won't automatically make the other player win).
Say you have a game with (AI as O):
Permutations under it are:
You'd choose the latter since it doesn't give a win to the other player.
Say you have a game with (AI as O):
Code: Select all
XOX
OXX
O**
Code: Select all
XOX
OXX
OOX
Code: Select all
XOX
OXX
OXO
First, I use VB6 but it's the same concept...
Well, I'm not very advanced in VB6, at all, but couldn't you do something like...
1. Check to see if you can win...
2. Check if the opponent is going to win...
3. Pick a spot...idk really, random or maybe based on a Tic-Tac-Toe guide? Like, a corner, adjacent corner, ajacent corner, open spot between for win or w/e
Hope that helps! Doubt it but you never know.
Well, I'm not very advanced in VB6, at all, but couldn't you do something like...
1. Check to see if you can win...
Code: Select all
- If Btn1.Caption = "x" Then
- If Btn2.Caption = "x" Then
- Btn3.Caption = "x" (Probably use a function, this is an example.)
- Msg = Msgbox("I win!")
- Yada Yada
- End If
- Repeat for all surrounding buttons
- Repeat for all buttons
Code: Select all
- If Btn1.Caption = "o" Then
- If Btn2.Caption = "o" Then
- Btn3.Caption = "x" (Probably use a function, this is an example.)
- Yada Yada
- End If
- Repeat for all surrounding buttons
- Repeat for all buttons
Hope that helps! Doubt it but you never know.
- Edutainment
- Posts:423
- Joined:Tue Feb 20, 2007 8:33 pm
- Location:Ontario, Canada
Tic Tac Toe strategy here: http://www.chessandpoker.com/tic_tac_toe_strategy.html
Re: Tic Tac Toe AI
use the
xxx
xxx
ooo
way of coding, although I'd just make it one string xxxxxxooo
the invincible tic tac toe strategy is easy to learn (just google it). Then just code in every situation
xxx
xxx
ooo
way of coding, although I'd just make it one string xxxxxxooo
the invincible tic tac toe strategy is easy to learn (just google it). Then just code in every situation
- hackmodford
- Portablizer Extraordinaire
- Posts:651
- Joined:Fri Aug 21, 2009 10:44 am
- Location:Michigan
- Contact:
Re: Tic Tac Toe AI
I made a tic tac toe game a long time ago with AI.
This is basically what I did if I remember right. I just coded for every possible move. And then to make the computer stupid I would add a little randomness so that it couldn't win or draw every time.
This is basically what I did if I remember right. I just coded for every possible move. And then to make the computer stupid I would add a little randomness so that it couldn't win or draw every time.