Skip to main content
GameDev.net gamedev.net
🔒 Locked

Tic Tac Toe Question

Started by the_cobbinator Dec 28, 2002 at 11:03 AM 6 replies 900+ views
Original Post
the_cobbinator
the_cobbinator
I am working on a tic tac toe game in VB6, and am wondering if anyone has any ideas on how to write the AI. the_cobbinator
the_cobbinator
Stuart Miller
Stuart Miller
One method that is commonly used is to rate the positions by order of priority.

for example, if you had the board numbered like so:

0 1 2
3 4 5
6 7 8

.. the most important positions are

4
0,2,6,8
1,3,5,7

i.e. the center, followed by the corners, followed by the rest.

Use a random number generator to select the position from the groups on each move, or select depending on the players move.

Simple huh...

Stuart M
Beer Hunter
Beer Hunter
Stuart Miller - Okay, I take a corner. The AI takes the center. I take the opposite corner. The AI takes another corner, ensuring my victory. Oops.

My approach is:
- If a winning move is available, use it.
- If the player could win on the next turn, block it.
- Otherwise, confer with a predefined list of moves (testing with rotations and reflections too).
Dreddnafious Maelstrom
Dreddnafious Maelstrom
its a very simple game with a limited number of moves.
i've developed tic tac toe ai that either wins or ties every time.(and it only took about two hours)

the general overview goes:

first move; if the player takes center take a corner, else computer takes center.

the rest of the moves;

if the player can win on his next move then block, if the computer can win on his move then win,
otherwise if the player takes a corner, take any available position adjacent to the corner. if the player takes a non-corner, select any corner adjacent to the non-corner. presto-bango-voila, undefeatable AI.(if i recall correctly there was one series of moves that would allow a victory but i patched it with a single if/then statement)

best of luck


Dreddnafious Maelstrom

"If I have seen further, it was by standing on the shoulders of Giants"

Sir Isaac Newton

[edited by - Dreddnafious Maelstrom on December 28, 2002 6:56:12 PM]
"Let Us Now Try Liberty"-- Frederick Bastiat
IADaveMark
IADaveMark
There are tons of examples in the Articles & Resources section.

Dave Mark - President and Lead Designer
Intrinsic Algorithm -
"Reducing the world to mathematical equations!"
RIPPL Sports - NFL Statistical Analysis and Prediction System
Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit<
Popolon
Popolon
Isn''t the best way to solve this problem just using a simple search tree? This is a simple enough problem to be able to explore the full tree, and therefore, you can have a "perfect" player.
the_cobbinator
the_cobbinator
Thank you for contributing, All of you really helped

the_cobbinator
the_cobbinator

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.