My Tic-Tac-Toe program

Anything related in any way to game development as a whole is welcome here. Tell us about your game, grace us with your project, show us your new YouTube video, etc.

Moderator: PC Supremacists

Post Reply
pythip
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 33
Joined: Sat Apr 24, 2010 11:25 pm

My Tic-Tac-Toe program

Post by pythip »

Hi, I've been working on a Tic-Tac-Toe program, and have it pretty much done, I have AI implemented, so far it looks something like this

Code: Select all

-first I check to see if there is a piece on the center square, if there is not one there then it places one on there. (right now the AI plays second and that is probably the best strategy)
-if there is a piece on the center square, it then puts one on a corner square, (which I think is the best alternative)
-after the first move it then goes into thinking for itself
-it checks to see if enemy pieces are on the horizontal lines, if there is an enemy piece it adds 1 to each square (not including the square a piece is on). 
-it does this check for the vertical, and diagonal lines too.
-it then repeats that process for the ally pieces.
-I then have it find out which square has the highest value and it places a piece on that square.
It's pretty simple ai but it works, well it at least plays the game by itself, I think I may have to do some tinkering to the algorithm to make it a better player though.

other than the AI it is pretty much as you would think a Tic-Tac-Toe program would work.
mary
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 33
Joined: Tue Apr 27, 2010 2:13 pm

Re: My Tic-Tac-Toe program

Post by mary »

with a game like tic-tac-toe can't you just hard code in the best responses, and if there is no response from what you hard coded, then go into the algorithm you have that checks where the best place to go, and I assume you have it check to see if it will win or lose, and places a piece there if it is applicable.
Post Reply