0% found this document useful (0 votes)
20 views27 pages

Kuljit, Ankit and Rohan

The document outlines an investigatory project on developing an interactive Tic-Tac-Toe game using Python for the academic session 2024-2025. It includes acknowledgments, system requirements, salient features, source code, and a bibliography. The project was completed by students Vedansh, Ritesh Kumar Sharma, and Kuljit, under the guidance of their teacher Mr. Rajulal Meena.

Uploaded by

ghostmodeonhoes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views27 pages

Kuljit, Ankit and Rohan

The document outlines an investigatory project on developing an interactive Tic-Tac-Toe game using Python for the academic session 2024-2025. It includes acknowledgments, system requirements, salient features, source code, and a bibliography. The project was completed by students Vedansh, Ritesh Kumar Sharma, and Kuljit, under the guidance of their teacher Mr. Rajulal Meena.

Uploaded by

ghostmodeonhoes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

COMPUTER SCIENCE

INVESTIGATORY PROJECT
ON
BUILDING AN INTERACTIVE
DEVELOPING TIC-TAC-TOE
A COLOR GAME GAME
Using Python

SESSION – 2024-2025

Sumbitted To: Mr. Rajulal Meena

Made By: Vedansh & Ritesh


ROHAN, KULJIT Kumar
AND Sharma
ANKIT

Class: 11th Science (PCM)

DEPARTMENT OF COMPUTER SCIENCE


KENDRIYA VIDYALAYA NO. 1 BATHINDA CANTT
BATHINDA (PUNJAB)
ACKNOWLEDGEMENT

We, Vedansh
Rohan,& Kuljit
Ritesh Kumar
and Sharma
Ankit , would like to thank our principal,
Miss. Kumud Ahuja, who has inspired and encouraged us by her deeds and

achievements, as she always tells us what we do the best and be the best init.

Next, I would like to express my sincere gratitude towards our Computer


Science teacher, Mr. Rajulal Meena , for his continuous support and valuable
guidance in making this project a great success.

Vedansh & Ritesh


Rohan, Kuljit Kumar
And Sharma
Ankit
Class – 11th B
Roll No: 27
23& 22
CERTIFICATE
This is to certify that Megha
ROHAN, and Ankita
KULJIT AND ANKIT

of 11th B
A has successfully completed the
computer science assignment for the
academic year 2018-19
2024-25 as per the

guidelines given by CBSE.


INTRODUCTION

This program will play tic tac toe with the


user. It will respond to player moves. User
just have to enter what do they desired to
choose. ‘X’ or ‘0’
INDEX
1. ACKNOWLEGMENT
2. CERTIFICATES
3. INTRODUCTION
4. SYSTEM REQUIREMENTS
5. SALIENT FEATURES
6. CODE
7. OUTPUT

8.BIBLOGRAPHY
SALIENT FEATURES
PROGRAM IS USER FRIENDLY
THE PROGRAM IS COMPACT
THE PROGRAM IS
RESPONSIVE
THE PROGRAM IS COMPACT
SYSTEM
REQUREMENTS
Main processor : Pentium 111 and above.
Hard disk : 1 GB
RAM : 1GB
Operating system : Windows XP and
above.
Complier: Jupyter, Pycham, Atom etc.
Language : Python.

FLOWCHART
START

ASK FOR
PLAYER’S
LETTER

DECIDE
WHO
WILL GO
FIRTST

PLAYER’S COMPUTER’S
MOVE MOVE

Get’s computer turn


Show the board
Get’s its turn Check if
computer
won

Gets players
move

Check for
tie

Check if
player won

Ask to play again

Game will start


again
Check for
tie

stop
SOURCE CODE

#!/usr/bin/python3

# Simple TicTacToe game in Python -

EAO

import random

import sys
board=[i for i in range(0,9)]

player, computer = '',''

# Corners, Center and Others,

respectively

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

for i in board:

end = ' | '

if x%3 == 0:
end = ' \n'

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]

return chars

def can_move(brd, player, move):

if move in tab and brd[move-1] ==

move-1:
return True

return False

def can_win(brd, player, move):

places=[]

x=0

for i in brd:

if i == player: places.append(x);
x+=1

win=True

for tup in winners:

win=True

for ix in tup:

if brd[ix] != player:

win=False

break
if win == True:

break

return win

def make_move(brd, player, move,

undo=False):

if can_move(brd, player, move):

brd[move-1] = player
win=can_win(brd, player, move)

if undo:

brd[move-1] = move-1

return (True, win)

return (False, False)

# AI goes here

def computer_move():
move=-1

# If I can win, others don't matter.

for i in range(1,10):

if make_move(board, computer, i,

True)[1]:

move=i

break

if move == -1:
# If player can win, block him.

for i in range(1,10):

if make_move(board, player, i,

True)[1]:

move=i

break

if move == -1:

# Otherwise, try to take one of

desired places.
for tup in moves:

for mv in tup:

if move == -1 and

can_move(board, computer, mv):

move=mv

break

return make_move(board, computer,

move)
def space_exist():

return board.count('X') +

board.count('O') != 9

player, computer = select_char()

print('Player is [%s] and computer is

[%s]' % (player, computer))

result='%%% Deuce ! %%%'

while space_exist():
print_board()

print('# Make your move ! [1-9] : ',

end='')

move = int(input())

moved, won = make_move(board,

player, move)

if not moved:

print(' >> Invalid number ! Try

again !')
continue

if won:

result='* Congratulations ! You won

! *'

break

elif computer_move()[1]:

result='=== You lose ! =='


break;

print_board()

print(result)
BIBLOGRAPHY

1.www.google.com

2.www.github.com

3.slideshare

4.computer science with python by sumita

arora for class 11th


CERTIFICATE

This is to certify that the embodied work on the project entitled “Color Game in
Python” for the partial fulfillment of the SESSION 2024-25 is a part of the

practical examination of Computer Science subject. It has been successfully


completed by: Vedansh & Ritesh Kumar Sharma, And class Roll No: 27 & 22

of Kendriya Vidyalaya No.1 Bathinda Cantt. This project is the genuine work
done by under our proper supervision and guidance of Mr. Rajulal Meena .

Signature of the Examiner Signature


of Guide

Signature of Principal

You might also like