Beruflich Dokumente
Kultur Dokumente
Project Report
Bachelor in Technology
Submitted by:
Nikunj
1703323
1703323 Page 1
CERTIFICATE
This is to certify that the work presented in the thesis entitled “Tic Tac Toe” is a
bonafide record of the work done during the period from July, 2017 to December, 2017
at Chandigarh Engineering College Landran, Mohali, Punjab, Nikunj , 1703323..
The project work is an authentic record of my own work and is carried out under
the supervision and guidance or Bachittarjeet Singh, instructor. The matter presented
in the report has not been submitted elsewhere, wholly or in part, for the award of any
other degree or diploma.
Nikunj (1703323)
This is to certify that the above statement made by the candidate is correct to the best
of my knowledge.
Bachittarjeet Singh
Instructor
1703323 Page 2
ACKNOWLEDGEMENT
I take this opportunity to express my sincere gratitude to the Principal, Chandigarh Engineering
College, Landran, for providing this opportunity to carry out the present thesis work.
The constant guidance and encouragement received from Dr. Shashi Bhushan,
Professor and Head, Department of Information Technology, has been of great help in
carrying our present work and helped us in completing this project with success.
I am also thankful to all the faculty and staff members of Department of Information
Technology, Chandigarh Engineering College, Landran for their intellectual support
throughout the course of this work.
1703323 Page 3
ABSTRACT
Players soon discover that the best game on both sides leads to a draw.
Therefore, tic-tac-toe is most often played by young children.
Due to the simplicity of the tic-tac-toe, it is often used as a
pedagogical tool to teach the concepts of good sportsmanship and the
branch of artificial intelligence that deals with the search for game
trees. It is easy to write a computer program to play perfectly to
tic-tac-toe, to list the 765 essentially different positions (the spatial
complexity of the state), or the 26,830 possible games to rotations and
reflections (the complexity of the game tree) in this Space.
The game can be generalized to a m, n, k-game in which two players
alternate placing stones of their own color on a m × n board, in order
to get k of their own color in a row.
Tic-tac-toe is the (3,3,3) -game. Harary's generalized tic-tac-toe is an
even wider generalization of tic tac toe. It can also be generalized as
and game. Tic-tac-toe is the game where n is equal to 3 and d is equal
to 2. If played correctly, the game will end in a tie by tic-tac-toe a
useless game.
1703323 Page 4
Table of Contents
I
Abstract
Ii
Certificate
iii
Acknowledgement
3.2 Output 20
References 23
1703323 Page 5
1703323 Page 6
List of Figures
1 Figure 2.1 11
2 Figure 2.2 13
3 Figure 2.3 14
4 Figure 2.4 15
1703323 Page 7
CHAPTER 1 - INTRODUCTION
TIC-TAC-TOE (OR NOUGHTS AND CROSSES, XS AND OS) IS A
PENCIL-AND-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.
PLAYERS SOON DISCOVER THAT BEST PLAY FROM BOTH PARTIES LEADS
TO A DRAW (OFTEN REFERRED TO AS CAT OR CAT'S GAME). HENCE,
TIC-TAC-TOE IS MOST OFTEN PLAYED BY YOUNG CHILDREN.
1703323 Page 8
CHAPTER 1.1 – MOTIVATION
In this project, we have created two different agents who compete
against
player vs player
Player vs computer
Once I was playing this game so I thought of making a game that is
similar to tic tac toe. Then I searched on the internet about the idea
with 2 or 3 hrs.I found a game named blackjack which is played in
zero cross and Is very similar to tic tac toe but also differ.
In this I found it an interesiting thing that 2 peoples can compete.
In this there Is a 0 and * .one can choose either 0 or *.
Tic-tac-toe (or Noughts and crosses, X’s and O’s) is a
pencil-and-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.
Players soon discover that best play from both parties leads to a draw
(often referred to as cat or cat's game). Hence, Tic-tac-toe is most
often played by young children.
1703323 Page 9
CHAPTER 2-CONCEPT
CHAPTER 2.1 – DESIGN SPECIFICATION
1703323 Page 10
Chapter 2.2 –Functionality and User interface
Tic-tac-toe on 8*8 matrix consists of 9 blocks (3 rows and 3
columns).
PLAYER VS PLAYER
In the player vs player version two players turn by turn enter the
input from keyboard. Keyboard keys (1-9) map to the 9 blocks of
tic-tac-toe. So, in order to select an it blocks on tic-tac-toe player has
to press it key on the keyboard.
Once the display on 8*8 gets updated, turn switches to the next
player. Moves of players are shown by / and \ on the chosen block. In
case one of the players wins or the game gets draw, the 8*8 display
and score on LED display get refreshed automatically.
Pressing * or # at any point of time will restart the whole game.
Condition for win –
A player wins the game when he completes a row or a column or a
diagonal on the tic-tac-toe.
PLAYER VS COMPUTER
In the player vs computer player, a single person can play the game
vs an automated player. Here the automated player has been
designed with always win strategy i.e. it won’t ever allow the other
player to win the game.
In both these versions, score on the LED display will specify
number of games won by each player and also show which
player is currently playing.
1703323 Page 11
CHAPTER 2.3 – DATA PATH
1703323 Page 12
CHAPTER 2.4 – USE CASE DIAGRAM
1703323 Page 13
CHAPTER 2.5 – CONTEXT DIAGRAM
1703323 Page 14
CHAPTER 3– IMPLEMENTATION
Code:-
def display_board(board):
clear_output() # Remember, this only works in jupyter!
print(' | |')
print(' ' + board[7] + ' | ' + board[8] + ' | ' + board[9])
print(' | |')
print('-----------')
print(' | |')
print(' ' + board[4] + ' | ' + board[5] + ' | ' + board[6])
print(' | |')
print('-----------')
print(' | |')
print(' ' + board[1] + ' | ' + board[2] + ' | ' + board[3])
print(' | |')
In [2]:
test_board = ['#','X','O','X','O','X','O','X','O','X']
display_board(test_board)
| |
X | O | X
| |
-----------
| |
O | X | O
| |
-----------
| |
X | O | X
| |
if marker == 'X':
return ('X', 'O')
else:
1703323 Page 15
return ('O', 'X')
In [5]:
player_input()
Player 1: Do you want to be X or O? X
Out[5]:
('X', 'O')
1703323 Page 16
In [9]:
win_check(test_board,'X')
Out[9]:
True
def choose_first():
if random.randint(0, 1) == 0:
return 'Player 2'
else:
return 'Player 1'
In [11]:
def space_check(board, position):
return position
In [14]:
def replay():
return input('Do you want to play again? Enter Yes or No: ').lower().st
artswith('y')
Steps 7:
In [15]:
print('Welcome to Tic Tac Toe!')
1703323 Page 17
while True:
# Reset the board
theBoard = [' '] * 10
player1_marker, player2_marker = player_input()
turn = choose_first()
print(turn + ' will go first.')
if play_game.lower()[0] == 'y':
game_on = True
else:
game_on = False
while game_on:
if turn == 'Player 1':
# Player1's turn.
display_board(theBoard)
position = player_choice(theBoard)
place_marker(theBoard, player1_marker, position)
if win_check(theBoard, player1_marker):
display_board(theBoard)
print('Congratulations! You have won the game!')
game_on = False
else:
if full_board_check(theBoard):
display_board(theBoard)
print('The game is a draw!')
break
else:
turn = 'Player 2'
else:
# Player2's turn.
display_board(theBoard)
position = player_choice(theBoard)
place_marker(theBoard, player2_marker, position)
if win_check(theBoard, player2_marker):
display_board(theBoard)
print('Player 2 has won!')
game_on = False
else:
1703323 Page 18
if full_board_check(theBoard):
display_board(theBoard)
print('The game is a draw!')
break
else:
turn = 'Player 1'
if not replay():
break
1703323 Page 19
Chapter 3.1-Output
1. Output when match gets draw: -
| |
X | O | X
| |
-----------
| |
O | O | X
| |
-----------
| |
X | X | O
| |
The game is a draw!
Do you want to play again? Enter Yes or No: NO
1703323 Page 20
Chapter 3.2– Risk Management
A common definition of risk is an uncertain event that if it occurs, can have a
positive or negative
effect on a project’s goals. It helps us to achieve the project’s
objectives, thus ensuring the
successful completion of the project. For successful development of this project
we have to need to identify the possible risk.
The possible risk for this project is described in below:
(a) The probability of moving away our-self from this project before it is finish
is low.
(b) The probability of user acceptance is great.
(c) The probability of requirement can't come in the time is low.
(d) The probability of marketing the product system is great.
(e) The probability of technology components isn’t fit for purpose of this
project is low.
(f) The probability of selecting low quality requirements are low.
(g) The probability of take wrong decisions are low.
(h) The probability of does not complete this project within a limited time is
low.
1703323 Page 21
Chapter 4– Conclusions and Future Work
The two-player machine and one player machine for tic tac
toe work fine.
Limitations: -
Score cannot be displayed properly because of limitation on number of
connectors available. For temporary basis con- 21 is being used which
does not maps the first pin and hence introduces an error in the score.
Possible refinements: -
We thought of introducing this additional feature which we could not
because of timing constraints: -
difficulty levels in one player machine. As for now we have computer
player which will always win.
1703323 Page 22
REFERENCES
Python.com
Pythontutorial.com
Wikipedia
W3 school
Quora
JavaTpoint
Coursera
Jupiternotebook
1703323 Page 23