Sei sulla pagina 1di 12

A PROJECT REPORT

ON

TIC TAC TOE GAME

SUBMITTED BY

SHUBHAM BHOR
VIVEK GUPTA
VISHAK NAIR
AKASH GUPTA

MENTOR
Prof. RANJITA GAONKAR

DEPARTMENT OF COMPUTER ENGINEERING


PILLAI COLLEGE OF ENGINEERING
NEW PANVEL – 410 206
UNIVERSITY OF MUMBAI

Academic Year 2018 – 19


Department of Computer Engineering
Pillai College of Engineering
New Panvel – 410 206

CERTIFICATE
This is to certify that the requirements for the mini project report entitled “TIC TAC TOE

GAME (USER V/S COMPUTER)” have been successfully completed by the following
students:

Name Roll No.


SHUBHAM BHOR 306
VIVEK GUPTA 315
VISHAK NAIR 331
AKASH GUPTA 313

in partial fulfillment of Second year of Engineering in the Department of Computer Engineering,


Pillai College of Engineering, New Panvel – 410 206 during the Academic Year 2018 – 2019.

_____________________ _____________________
Subject In-charge Head of Department
Ranjita Gaonkar Dr. Madhumita Chatterjee
TABLE OF CONTENTS

Page No.
Chapter 1
Introduction 2
1.1 Introduction

Chapter 2
Objective 3
2.1 Problem Definition
2.2 Scope

Chapter 3
Methodology 4
3.1 Algorithms or Technologies Used and their description in detail

Chapter 4
Implementation 7
4.1 System Overview
4.2 Project working with Snapshots

Chapter 5
Conclusion 9
5.1 Project Learning Outcomes
5.2 Future Scope
Acknowledgement 10

1| P a g e
Chapter 1

TIC TAC TOE


1.1 Introduction.

 Tic-tac-toe (also known as noughts and crosses 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 wins
the game. Players soon discover that the best play from both parties leads to a draw.
Hence, tic-tac-toe is most often played by young children.

 This game can be played in a 3x3 grid (shown in the Fig 1.1) .The game can be played by
two players. There are two options for players: (a) Human (b) Computer.

Fig. 1.1

1.2 Strategy.
1.Win: If the player has two in a row, they can place a third to get three in a row.

2.Block: If the opponent has two in a row, the player must play the third themselves to block the
opponent.

3.Fork: Create an opportunity where the player has two threats to win (two non-blocked lines of 2).

4.Blocking an opponent's fork: If there is only one possible fork for the opponent, the player
should block it. Otherwise, the player should block any forks in any way that simultaneously allows
them to create two in a row. Otherwise, the player should create a two in a row to force the opponent
into defending, as long as it doesn't result in them creating a fork. For example, if "X" has two
opposite corners and "O" has the center, "O" must not play a corner in order to win. (Playing a
corner in this scenario creates a fork for "X" to win.)

5.Center: A player marks the center. (If it is the first move of the game, playing on a corner gives the
second player more opportunities to make a mistake and may therefore be the better choice;
however, it makes no difference between perfect players.)

6.Opposite corner: If the opponent is in the corner, the player plays the opposite corner.

7.Empty corner: The player plays in a corner square

2|Page
Chapter 2

OBJECTIVE

2.1Problem Definition
 To develop a GUI application to create a Java program that can play a game of Tic-Tac-
Toe with the user. Tic-Tac-Toe is a simple game usually played with paper and pencil.
First, we make a simple 3 x 3 grid on the paper. Then two players alternate turns by
marking Xs and Os in empty spaces on the grid. The first player who makes three of his
or her marks in a horizontal, vertical, or diagonal row wins. If all of the spaces in the
grid are filled before any player marks three in a row, the game is a draw.
 Here are the rules and instructions for this challenge:
1.The computer plays against the human. The human moves first and is X. The computer
is O.
2. The program begins by displaying a short welcome message, and then it prompts the
player for his or her first move.
3. We use X to mark the human’s plays and O to mark the computer’s plays.
4. Play continues until one player has scored three in a row or all squares have been filled
with no winner. The program is able to determine whether either player has scored
three in a row and won the game.
5. The human and computer players can play in only those squares that are not already
occupied by either player.
6. The program ends when the game is won by either player or the game is a draw. If the
user want to play again, he must run the program again.

2.2Scope
The Program will provide the following points:
a) Knowledge about Best moves in TicTacToe game.
b) Basic Knowledge of AI algorithm.

3| P a g e
Chapter 3
METHODOLOGY

3.1 Algorithms or Technologies Used.

Suppose the player use X and the computer use O . The logic used for the AI is as follows:

1) First move:

a) If the center is free, get the center.(Fig: 3.1) b) Otherwise, get any of the corners.(Fig: 3.2)

X O O
Fig:3.1 Fig:3.2
O X
2) Second move:
O O
a) Block user from winning.(Fig: 3.3)
b)Op tion for winning by applying the
following logic: If the center is occupied by user, get any of the corners. (Fig: 3.4)

X O O O

O X

X O

Fig:3.3 Fig;3.4

Otherwise, the following cases happen:


Case 1: If any situation arises like the Fig 3.5 then the computer sets its symbol any one of the
position among 2, 4, 6 and 8.
X O

O O

O X Fig:3.5
4|Page
Case 2: If any situation arises like the Fig 3.6 or Fig 3.7 or Fig 3.8
then the computer sets its symbol at any position among 4 and 6.
X X X

46
O 4 O 6 4 O 6

O X X

Fig:3.6 Fig;3.7 Fig:3.8


Case 3: If any situation arises like the Fig 3.9 or Fig 3.10 or Fig 3.11 then the computer sets its
symbol at any position among 2 and 8.

2 2 2

O X X O X X O

X 8 8 8 X

Fig:3.9 Fig:3.10 Fig:3.11

Case 4: If any situation arises like the Fig 3.12 or Fig 3.13 or Fig 3.14 or 3.15 then the computer
sets its symbol at any position among 1, 3, 7 and 9.

1X 3 1 Fig:3.12
X 3
OX
X O

7 9 7 Fig:3.13 9

3
1 3
1 3 O
X
O X

7 9
X 7 X 9
9

Fig:3.14 Fig:3.15
5|Page
3) Third and fourth move:
a) Option for winning. (Fig: 3.16)
b) Block user from winning. (Fig: 3.17)
c) Randomly play a move. (Fig: 3.18)

O X . O X X O

X O X O O O X

X O X X X O

Fig:3.16 Fig;3.17 Fig:3.18

6|Page

Chapter 4
IMPLEMENTATION
4.1 System Overview
1. The Program is to perform the operations (O) based on the input of User (X) .
2. The Program is divided in two parts:-
a) main class TicTacToe is used for Graphical User Interface(GUI),Showing various
messages,Reset the game.
b) package class TicTacToeBoard to take User’s move, to provide best Move by computer,to
give outcomes to the main class.
Methods: The methods we used in our program are as follows:
 private int SquareToIndex(String square): to take the User’s input through the various
Buttons.
 private String IndexToSquare(int index): to perform computers move depending on
user’s input.
 public String getNextMove(): to win if possible,to block if necessary,center if it is open,
open corner,open edge.
 public void playAt(String square, int player):giving best move to play by the
computer.
 public String canPlayerWin(int player): to check whether the player can win,if yes then
perform best move to block.
 public int isGameOver(): to check whether the game is over i.e.Player has won,
Computer has won or it’s a draw.
 public void reset():to reset the game if it is over and OK buton is clicked.

4.2 Project working with Snapshots.


 Welcome Message.

7|Page
 When Computer has won.

 When it’s a Draw.

 When Player has won.

8|Page
Chapter 5

CONCLUSION

5.1 Project Learning Outcomes


1. We have been able to learn the basic Core logic-AI algorithm.
2. Basic of Graphical User Interface (GUI) using Java.
3. To use the User defined functions using recursion.

5.2 Future Scope


 Create a User v/s Computer as well as Player v/s Player in one program.
 To create a complex AI algorithm to perform Computer’s move.

9|Page
Acknowledgement

We would like to express our specials thanks of gratitude to Principal Dr. Sandeep
Joshi, H.O.D. Dr. Madhumita Chatterjee and Prof. Harshal Lamba and Prof.
Ranjita Gaonkar who gave us the opportunity to do this project based learning in
the topic Tic Tac Toe Game(User v/s Computer), which helped us in applying the
knowledge that we have acquired during the semester and learn new concepts.
We are immensely grateful to all of them for sharing their pearls of wisdom with us
during this course of project based learning.

10| P a g e

Potrebbero piacerti anche