University of Computer
Studies (Pakokku)
Tic Tac Toe Game
PRESENTED BY GROUP VI
Member List
No Roll No. Name
1 5CS-23 Mg Kyaw Thi Ha
2 5CS-42 Mg Myo Kyaw Htun
3 5CS-12 Ma Hnin Theint Theint Phyoe
4 5CS-26 Ma Yee Mon Htoo
5 5CS-31 Ma Chue Nadi Thein Naing
6 5CS-34 Ma Sandar Lin
Content
Introduction
Objective
Tic Tac Toe
Conclusion
Introduction
Tic-tac-toe (American English), noughts and crosses (British English), or Xs and Os is a
paper-and-pencil 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 of their marks in a horizontal, vertical, or
diagonal row is the winner. A computer player ( O ) is made for the game Tic-Tac-Toe by
using First Order Logic. The program will allow a human user to play against the computer.
Objectives
To play Tic-Tac-Toe game
To create the computer player
To implement the First Order Logic
Tic Tac Toe
Winning Condition
win(Board, Player) :- rowwin(Board, Player).
win(Board, Player) :- colwin(Board, Player).
win(Board, Player) :- diagwin(Board, Player).
rowwin(Board, Player) :- Board = [Player,Player,Player,_,_,_,_,_,_].
rowwin(Board, Player) :- Board = [_,_,_,Player,Player,Player,_,_,_].
rowwin(Board, Player) :- Board = [_,_,_,_,_,_,Player,Player,Player].
colwin(Board, Player) :- Board = [Player,_,_,Player,_,_,Player,_,_].
colwin(Board, Player) :- Board = [_,Player,_,_,Player,_,_,Player,_].
colwin(Board, Player) :- Board = [_,_,Player,_,_,Player,_,_,Player].
diagwin(Board, Player) :- Board = [Player,_,_,_,Player,_,_,_,Player].
diagwin(Board, Player) :- Board = [_,_,Player,_,Player,_,Player,_,_].
Predicates to support playing a game with
the user
x_can_win_in_one(Board) :- move(Board, x, Newboard), win(Newboard, x).
Predicate orespond generates the
computer’s (playing o) response from the
current Board
orespond(Board,Newboard) :-move(Board, o, Newboard),win(Newboard, o),!.
orespond(Board,Newboard) :-move(Board,o,
Newboard),not(x_can_win_in_one(Newboard)).
orespond(Board,Newboard) :-move(Board, o, Newboard).
orespond(Board,Newboard):-not(member(b,Board)) , ! , write(’Cats game!’), nl,
Newboard=board.
Define Move
xmove([b,B,C,D,E,F,G,H,I], 1, [x,B,C,D,E,F,G,H,I]).
xmove([A,b,C,D,E,F,G,H,I], 2, [A,x,C,D,E,F,G,H,I]).
xmove([A,B,b,D,E,F,G,H,I], 3, [A,B,x,D,E,F,G,H,I]).
xmove([A,B,C,b,E,F,G,H,I], 4, [A,B,C,x,E,F,G,H,I]).
xmove([A,B,C,D,b,F,G,H,I], 5, [A,B,C,D,x,F,G,H,I]).
xmove([A,B,C,D,E,b,G,H,I], 6, [A,B,C,D,E,x,G,H,I]).
xmove([A,B,C,D,E,F,b,H,I], 7, [A,B,C,D,E,F,x,H,I]).
xmove([A,B,C,D,E,F,G,b,I], 8, [A,B,C,D,E,F,G,x,I]).
xmove([A,B,C,D,E,F,G,H,b], 9, [A,B,C,D,E,F,G,H,x]).
xmove(Board, _N, Board) :- write(’Illegal move.’), nl
Define O Move
move([b,B,C,D,E,F,G,H,I], Player, [Player,B,C,D,E,F,G,H,I]).
move([A,b,C,D,E,F,G,H,I], Player, [A,Player,C,D,E,F,G,H,I]).
move([A,B,b,D,E,F,G,H,I], Player, [A,B,Player,D,E,F,G,H,I]).
move([A,B,C,b,E,F,G,H,I], Player, [A,B,C,Player,E,F,G,H,I]).
move([A,B,C,D,b,F,G,H,I], Player, [A,B,C,D,Player,F,G,H,I]).
move([A,B,C,D,E,b,G,H,I], Player, [A,B,C,D,E,Player,G,H,I]).
move([A,B,C,D,E,F,b,H,I], Player, [A,B,C,D,E,F,Player,H,I]).
move([A,B,C,D,E,F,G,b,I], Player, [A,B,C,D,E,F,G,Player,I]).
move([A,B,C,D,E,F,G,H,b], Player, [A,B,C,D,E,F,G,H,Player]).
Conclusion
As the conclusion, we understand about the tic tac toe game. First, we knew the rule of
game. Second we implemented game by using First Order Logic. Now, Game AI is very
development such as Dota 2 AI, called OpenAI Five, learned by playing over 10,000 years of
games against itself. Finally, we created the small computer player. But it do not optimize
move by using minimax, alphabeta….