TIC TAC TOE - CSE246DataStructureFall2010

Download Report

Transcript TIC TAC TOE - CSE246DataStructureFall2010

DATA STRUCTURES AND ALGORITHMS

The project that we worked on is a
well known game called “Tic Tac Toe”.

We implemented this game using a
binary tree which is a very flexible
data structure along with some other
data structures namely link lists &
multi dimensional arrays.


Tic-tac-toe, also spelled tick tack
toe, or noughts and crosses is a
pencil paper game for two players,
X and O, who take turns marking
the spaces in a 3×3 grid.
The player who succeeds in placing
three respective marks in a
horizontal, vertical, or diagonal
row wins the game.

Choose which player will be represented
by X and which by O.

Let player X go first to put an X in any of
the nine sections of the grid.

The players take turns putting their
symbol on the table.

The first player to have 3 of their symbols
in a row, whether it is horizontally,
vertically, or diagonally, is the winner.



A binary tree is a tree data structure
in which each node has at most two
child nodes, usually distinguished as
"left" and "right".
Nodes with children are parent nodes,
and child nodes may contain
references to their parents.
Any node in the data structure can be
reached by starting at root node and
repeatedly following references to
either the left or right child.



JButton
JLabel
File streaming
Following classes were used in our program:
 tttapp
 Node
 AI








java.util.*
java.io.*
java.awt.*
javax.swing.*
java.awt.event.*
Firstedge(text file)
Firstcorner(text file)














AI()
setstate()
match()
load()
searchstate()
nextmove()
display()
compwin()
compwins()
userwins()
chktie()
getc()
actionperformed()
init()


Only two strategies i.e. first-corner and firstedge are taken into consideration while
developing the program’s logic.
The computer always goes first.