Rajat and Naman
Rajat and Naman
Rajat and Naman
Session -2022-23
Class – xii [commerce]
Subject: Informatics Practices [065]
TOPIC: TIC TAC TOE GAME
SUBMITTED BY SUBMITTED TO
Mas. Rajat Verma Mr. Navin Piplodiya
Mas. Naman Jain
1
Certificate
This is to certify that Mast. Rajat Verma &
Naman Jain Student of Class XI [commerce] of THE
Principal
2
ACKNOWLEDGEMENT
I extend my sincere thanks to my school THE NEW ERA
3
Index
1. About Python 5–8
2. About Tic Tac Toe Game 9 – 10
3. Source code 11 – 18
4. Output Screens 19
5. Reference 20
4
About Python
Python is one of those rare languages which can claim to be
both simple and powerful. You will find yourself pleasantly
surprised to see how easy it is to concentrate on the solution to the
problem rather than the syntax and structure of the language you
are programming in.
Guido van Rossum, the creator of the Python language, named the
language after the BBC show "Monty Python's Flying Circus". He
doesn't particularly like snakes that kill animals for food by
winding their long bodies around them and crushing them.
5
Features of Python programming language
7
The official introduction to Python is:
8
INTRODUCTION
9
Game Rules
Winning condition
10
Source Code:
import random
import sys
moves=((1,7,3,9),(5,),(2,4,6,8))
# Winner combinations
winners=((0,1,2),(3,4,5),(6,7,8),(0,3,6),(1,4,7),(2,5,8),(0,4,8),(2,4,6))
# Table
tab=range(1,10)
def print_board():
x=1
11
for i in board:
if x%3 == 0:
if i != 1: end+='---------\n';
char=' '
if i in ('X','O'): char=i;
x+=1
print(char,end=end)
def select_char():
chars=('X','O')
if random.randint(0,1) == 0:
return chars[::-1]
12
return chars
return True
return False
places=[ ]
x=0
for i in brd:
if i == player: places.append(x);
x+=1
win=True
13
win=True
for ix in tup:
if brd[ix] != player:
win=False
break
if win == True:
break
return win
brd[move-1] = player
if undo:
14
brd[move-1] = move-1
# AI goes here
def computer_move():
move=-1
for i in range(1,10):
move=i
break
if move == -1:
15
for i in range(1,10):
move=i
break
if move == -1:
for mv in tup:
move=mv
break
def space_exist():
16
return board.count('X') + board.count('O') != 9
while space_exist():
print_board()
move = int(input())
if not moved:
continue
# if won:
17
result='*** Congratulations ! You won ! ***'
break
elif computer_move()[1]:
break;
print_board()
print(result)
18
OUTPUT
**********************
19
Reference
Informatics Practices -: Sultan Chand [ Preeti Arora]
Web support - : Wikipedia and Other web blogs to create and this
project.
20