SlideShare une entreprise Scribd logo
1  sur  20
Name: Rudra pratap singh
Roll NO : Class : Xll
SCI
SCHOOL : A.P.S ACADEMY
This is to cerify that the bonafide work of F.I.T (Practical / Project) has
been done by the student as per CBSE requirement during the
academic session : 2019-2020
Examiner’s signature Teacher – In – charge
Date HEAD OF INSTITUTION
I WOULD LIKE TO EXPRESS MY SPECIAL
THANKS OF GRATITUDE TO MY TEACHER
MRS. DEEPIKA MULLICK AS WELL AS OUR
PRINCIPAL MRS. HEMA KALAKOTI WHO
GAVE ME THE GOLDEN OPPORTUNITY TO
DO THIS WONDERFUL PROJECT ON THE
TOPIC GAMEING PROGRAM WHICH ALSO
HELPED ME IN DOING A LOT OF RESEARCH
AND I COME TO KNOW ABOUT SO MANY
NEW THINGS I AM REALLY THANKFUL TO
THEM.
SECONDLY I WOULD ALSO LIKE TO THANK
MY PARENTS AND FRIENDS WHO HELPED
ME A LOT IN FINALIZING THIS PROJECT
WITHIN THE LIMITED TIME FRAME.
importrandom
importcollections
random.seed(1)
size = 5
bombs = collections.defaultdict(int)
counts = collections.defaultdict(int)
display = collections.defaultdict(lambda: 'X')
neighbors = sorted(set((i, j) for i in range(size) for j in range(size)) - {(0, 0)})
# Initialize
for x in range(size):
for y in range(size):
bombs[x, y] = 0
counts[x, y] = 0
display[x, y] = '?'
# Set bombs
for _ in range(3):
x = random.randrange(size)
y = random.randrange(size)
bombs[x, y] = 1
# Calculate counts
for x in range(size):
for y in range(size):
total = 0
for i in [-1, 0, 1]:
for j in [-1, 0, 1]:
total += bombs[x + i, y + j]
counts[x, y] = total
def show(grid):
for x in range(size):
for y in range(size):
print(grid[x, y], end=', ')
print()
print('Bombs:')
show(bombs)
print('Counts:')
show(counts)
alive = True
def reveal(x, y):
if bombs[x, y]:
return False
display[x, y] = counts[x, y]
if counts[x, y]:
return True
zeros = [ (x, y) ]
while zeros:
x, y = zeros.pop()
if not ((0 <= x < size) and (0 <= y < size)):
continue
if counts[x, y] == 0:
display[x, y] = 0
for i in (-1, 0, 1):
for j in (-1, 0, 1):
if i == j == 0:
continue
offset_x = x + i
offset_y = y + j
seen = display[offset_x, offset_y] != '?'
if counts[offset_x, offset_y] == 0 and notseen:
zeros.append((offset_x, offset_y))
return True
while alive:
show(display)
x = int(input('row: '))
y = int(input('column: '))
alive = reveal(x, y)
if not alive or not any(spot== '?' for spotin display.values()):
break
if alive:
print('Congratulations!You win.')
else:
print('Sorry, you failed.')
----------------------------------------------------------------------------------------------------
-------------------------
importatexit
importcollections
importitertools
importrandom
importsqlite3
importthreading
importtime
importconsole
original_terminal_state = console.get_terminal_mode()
atexit.register(console.set_terminal_mode, original_terminal_state)
class Game:
"Game state for Tetris."
def __init__(self, width, height, seed=None):
self.random = random.Random(seed)
self.width= width
self.height = height
self.board = collections.defaultdict(lambda: '#')
for x in range(width):
for y in range(height):
self.board[x, y] = ' '
self.active = True
self.speed = 20
self.next_letter = self.random.choice('IJLOSTZ')
self.piece = self.next_piece()
self.score = 0
self.stash = None
def draw(self):
"Draw game state."
print('Score:', self.score, end='rn')
print('Level:', self.score// 4 + 1, end='rn')
print('Nextpiece:', self.next_letter, end='rn')
print('Stash piece:', 'no' if self.stash is Noneelse 'yes', end='rn')
print('*' * (self.width + 2), end='rn')
for y in range(self.height):
print('|', end='')
for x in range(self.width):
if (x, y) in self.piece:
print('@', end='')
else:
print(self.board[x, y], end='')
print('|', end='rn')
print('*' * (self.width + 2), end='rn')
def next_piece(self):
"Create a new piece, on collision set active to False."
letter = self.next_letter
self.next_letter = self.random.choice('IJLOSTZ')
if letter == 'I':
piece = {(0, 0), (0, 1), (0, 2), (0, 3)}
elif letter == 'J':
piece = {(1, 0), (1, 1), (1, 2), (0, 2)}
elif letter == 'L':
piece = {(0, 0), (0, 1), (0, 2), (1, 2)}
elif letter == 'O':
piece = {(0, 0), (0, 1), (1, 0), (1, 1)}
elif letter == 'S':
piece = {(0, 1), (1, 0), (1, 1), (2, 0)}
elif letter == 'T':
piece = {(0, 0), (1, 0), (2, 0), (1, 1)}
else:
assert letter == 'Z'
piece = {(0, 0), (1, 0), (1, 1), (2, 1)}
offset = self.width // 2 - 1
piece = {(x + offset, y) for x, y in piece}
if self.collide(piece):
self.end()
return piece
def end(self):
self.active = False
print('Gameover!Pressany key to quit.', end='rn')
def tick(self, mark):
"Notify the game of a clock tick."
if mark % self.speed == 0:
moved = self.move_piece(0, 1)
if not moved:
for x, y in self.piece:
self.board[x, y] = '#'
self.collapse()
self.piece = self.next_piece()
self.draw()
def collapse(self):
"Collapse fulllines."
y = self.height - 1
while y >= 0:
full_line= all(self.board[x, y] == '#' for x in range(self.width))
if full_line:
z = y
while z > 0:
for x in range(self.width):
self.board[x, z] = self.board[x, z - 1]
z -= 1
for x in range(self.width):
self.board[x, 0] = ' '
self.score += 1
if self.score % 4 == 0:
self.speed -= 1
else:
y -= 1
def collide(self, piece):
"Check whether piece collides with others on board."
return any(self.board[x, y] != ' ' for x, y in piece)
def move_piece(self, x, y):
"Movepiece by delta x and y."
new_piece= {(a + x, y + b) for a, b in self.piece}
if self.collide(new_piece):
return False
self.piece = new_piece
return True
def rotate_piece(self):
"Rotate piece."
min_x = min(xfor x, y in self.piece)
max_x = max(x for x, y in self.piece)
diff_x = max_x - min_x
min_y = min(y for x, y in self.piece)
max_y = max(y for x, y in self.piece)
diff_y = max_y - min_y
size = max(diff_x, diff_y)
new_piece= set()
for x, y in self.piece:
pair = (min_x + size) - (y - min_y), min_y + (x - min_x)
new_piece.add(pair)
if self.collide(new_piece):
return False
self.piece = new_piece
return True
def move(self, key):
"Update game state based on key press."
if key == 'left':
moved = self.move_piece(-1, 0)
elif key == 'right':
moved = self.move_piece(1, 0)
elif key == 'down':
moved = self.move_piece(0, 1)
elif key == 'up':
moved = self.rotate_piece()
elif key == 'swap':
if self.stash is None:
self.stash = self.piece
self.piece = self.next_piece()
else:
self.piece, self.stash = self.stash, self.piece
if self.collide(self.piece):
self.end()
moved = True
else:
assert key == 'space'
moved = self.move_piece(0, 1)
while moved:
moved = self.move_piece(0, 1)
moved = True
if moved:
self.draw()
def draw_loop(game):
game.draw()
counter = itertools.count(start=1)
while game.active:
mark = next(counter)
game.tick(mark)
time.sleep(0.1)
def input_loop(game):
"""Input loop.
Handlekeyboard inputin a separate thread.
"""
while game.active:
key = console.get_input()
if key is None:
continue
elif key == 'quit':
game.active = False
else:
assert key in ('left', 'down', 'right', 'up', 'space', 'swap')
game.move(key)
console.set_terminal_mode(original_terminal_state)
print('Enter your namefor leaderboard (blank to ignore):')
name = input()
if name:
con = sqlite3.connect('tetris.sqlite3', isolation_level=None)
con.execute('CREATE TABLE IFNOT EXISTS Leaderboard (name, score)')
con.execute('INSERTINTO Leaderboard VALUES (?, ?)', (name,
game.score))
scores = con.execute('SELECT* FROM Leaderboard ORDER BY score
DESC LIMIT 10')
print('{0:<16}| {1:<16}'.format('Name', 'Score'))
for pair in scores:
print('{0:<16}| {1:<16}'.format(*pair))
def main():
"Main entry-pointfor Tetris."
game = Game(10, 10)
draw_thread = threading.Thread(target=draw_loop, args=(game,))
input_thread = threading.Thread(target=input_loop, args=(game,))
draw_thread.start()
input_thread.start()
draw_thread.join()
input_thread.join()
if __name__ == '__main__':
main()
---------------------------------------------------------------------------------------------------
import time
from time import sleep
import random
sus="-"*35
depo=["rock","paper","scissors"]
while True:
x=input("rock , paper, scissors: ")
if x not in depo:
print ("Dontcheat!")
continue
pc=random.choice(depo)
sleep(0.5)
print (("Computer picked {}.").format(pc))
if x==pc:
sleep(0.5)
print (("nIt's a draw.n{}").format(sus))
elif x=="rock" and pc=="scissors":
sleep(0.5)
print (("nYou win.rock beats scissorsn{}").format(sus))
elif x=="paper" and pc=="rock":
sleep(0.5)
print (("nYou win.paper beats rockn{}").format(sus))
elif x=="scissors" and pc=="paper":
sleep(0.5)
print (("nYou win.scissors beats papern{}").format(sus))
else:
sleep(0.5)
print (("nYou lose. {} beats {}n{}").format(pc,x,sus))
input()
New microsoft office word document

Contenu connexe

Tendances

Ch11 Search & Sort
Ch11 Search & SortCh11 Search & Sort
Ch11 Search & Sort
leminhvuong
 
PyCon2009_AI_Alt
PyCon2009_AI_AltPyCon2009_AI_Alt
PyCon2009_AI_Alt
Hiroshi Ono
 

Tendances (17)

The Ring programming language version 1.8 book - Part 57 of 202
The Ring programming language version 1.8 book - Part 57 of 202The Ring programming language version 1.8 book - Part 57 of 202
The Ring programming language version 1.8 book - Part 57 of 202
 
Intro to Game Programming
Intro to Game ProgrammingIntro to Game Programming
Intro to Game Programming
 
The Ring programming language version 1.7 book - Part 55 of 196
The Ring programming language version 1.7 book - Part 55 of 196The Ring programming language version 1.7 book - Part 55 of 196
The Ring programming language version 1.7 book - Part 55 of 196
 
pptuni1
pptuni1pptuni1
pptuni1
 
The Ring programming language version 1.5.2 book - Part 50 of 181
The Ring programming language version 1.5.2 book - Part 50 of 181The Ring programming language version 1.5.2 book - Part 50 of 181
The Ring programming language version 1.5.2 book - Part 50 of 181
 
Utility Classes Are Killing Us
Utility Classes Are Killing UsUtility Classes Are Killing Us
Utility Classes Are Killing Us
 
The Ring programming language version 1.6 book - Part 53 of 189
The Ring programming language version 1.6 book - Part 53 of 189The Ring programming language version 1.6 book - Part 53 of 189
The Ring programming language version 1.6 book - Part 53 of 189
 
The Ring programming language version 1.5 book - Part 9 of 31
The Ring programming language version 1.5 book - Part 9 of 31The Ring programming language version 1.5 book - Part 9 of 31
The Ring programming language version 1.5 book - Part 9 of 31
 
The Ring programming language version 1.5.4 book - Part 46 of 185
The Ring programming language version 1.5.4 book - Part 46 of 185The Ring programming language version 1.5.4 book - Part 46 of 185
The Ring programming language version 1.5.4 book - Part 46 of 185
 
The Ring programming language version 1.4.1 book - Part 15 of 31
The Ring programming language version 1.4.1 book - Part 15 of 31The Ring programming language version 1.4.1 book - Part 15 of 31
The Ring programming language version 1.4.1 book - Part 15 of 31
 
Silverlight as a Gaming Platform
Silverlight as a Gaming PlatformSilverlight as a Gaming Platform
Silverlight as a Gaming Platform
 
The Ring programming language version 1.9 book - Part 62 of 210
The Ring programming language version 1.9 book - Part 62 of 210The Ring programming language version 1.9 book - Part 62 of 210
The Ring programming language version 1.9 book - Part 62 of 210
 
The Ring programming language version 1.8 book - Part 56 of 202
The Ring programming language version 1.8 book - Part 56 of 202The Ring programming language version 1.8 book - Part 56 of 202
The Ring programming language version 1.8 book - Part 56 of 202
 
The Ring programming language version 1.8 book - Part 55 of 202
The Ring programming language version 1.8 book - Part 55 of 202The Ring programming language version 1.8 book - Part 55 of 202
The Ring programming language version 1.8 book - Part 55 of 202
 
The Ring programming language version 1.5.4 book - Part 51 of 185
The Ring programming language version 1.5.4 book - Part 51 of 185The Ring programming language version 1.5.4 book - Part 51 of 185
The Ring programming language version 1.5.4 book - Part 51 of 185
 
Ch11 Search & Sort
Ch11 Search & SortCh11 Search & Sort
Ch11 Search & Sort
 
PyCon2009_AI_Alt
PyCon2009_AI_AltPyCon2009_AI_Alt
PyCon2009_AI_Alt
 

Similaire à New microsoft office word document

19012011102_Nayan Oza_Practical-7_AI.pdf
19012011102_Nayan Oza_Practical-7_AI.pdf19012011102_Nayan Oza_Practical-7_AI.pdf
19012011102_Nayan Oza_Practical-7_AI.pdf
NayanOza
 
Please help me fix this code! will upvote. The code needs to produce .pdf
Please help me fix this code! will upvote.  The code needs to produce .pdfPlease help me fix this code! will upvote.  The code needs to produce .pdf
Please help me fix this code! will upvote. The code needs to produce .pdf
climatecontrolsv
 
Please help this code is supposed to evaluate current node state and i.pdf
Please help this code is supposed to evaluate current node state and i.pdfPlease help this code is supposed to evaluate current node state and i.pdf
Please help this code is supposed to evaluate current node state and i.pdf
climatecontrolsv
 
This is a homework assignment that I have for my Java coding class. .pdf
This is a homework assignment that I have for my Java coding class. .pdfThis is a homework assignment that I have for my Java coding class. .pdf
This is a homework assignment that I have for my Java coding class. .pdf
feelinggift
 
Mylib.pydef allInOne(n1, n2) return {addplus(n1, n2).docx
Mylib.pydef allInOne(n1, n2)    return {addplus(n1, n2).docxMylib.pydef allInOne(n1, n2)    return {addplus(n1, n2).docx
Mylib.pydef allInOne(n1, n2) return {addplus(n1, n2).docx
roushhsiu
 
Mylib.pydef allInOne(n1, n2) return {addplus(n1, n2.docx
Mylib.pydef allInOne(n1, n2)    return {addplus(n1, n2.docxMylib.pydef allInOne(n1, n2)    return {addplus(n1, n2.docx
Mylib.pydef allInOne(n1, n2) return {addplus(n1, n2.docx
gemaherd
 
Will upvote asapPlease help my code gives me incorrect val.pdf
Will upvote asapPlease help my code gives me incorrect val.pdfWill upvote asapPlease help my code gives me incorrect val.pdf
Will upvote asapPlease help my code gives me incorrect val.pdf
sales223546
 
Will upvote Please fix the following code and post your inputs and o.pdf
Will upvote Please fix the following code and post your inputs and o.pdfWill upvote Please fix the following code and post your inputs and o.pdf
Will upvote Please fix the following code and post your inputs and o.pdf
info335653
 
Fix this code so that it will run with proper answers, please dont u.pdf
Fix this code so that it will run with proper answers, please dont u.pdfFix this code so that it will run with proper answers, please dont u.pdf
Fix this code so that it will run with proper answers, please dont u.pdf
txkev
 

Similaire à New microsoft office word document (20)

Retos de Programación en Python
Retos de Programación en PythonRetos de Programación en Python
Retos de Programación en Python
 
19012011102_Nayan Oza_Practical-7_AI.pdf
19012011102_Nayan Oza_Practical-7_AI.pdf19012011102_Nayan Oza_Practical-7_AI.pdf
19012011102_Nayan Oza_Practical-7_AI.pdf
 
p.pdf
p.pdfp.pdf
p.pdf
 
Please help me fix this code! will upvote. The code needs to produce .pdf
Please help me fix this code! will upvote.  The code needs to produce .pdfPlease help me fix this code! will upvote.  The code needs to produce .pdf
Please help me fix this code! will upvote. The code needs to produce .pdf
 
Please help this code is supposed to evaluate current node state and i.pdf
Please help this code is supposed to evaluate current node state and i.pdfPlease help this code is supposed to evaluate current node state and i.pdf
Please help this code is supposed to evaluate current node state and i.pdf
 
AI_Lab_File()[1]sachin_final (1).pdf
AI_Lab_File()[1]sachin_final (1).pdfAI_Lab_File()[1]sachin_final (1).pdf
AI_Lab_File()[1]sachin_final (1).pdf
 
calculator_new (1).pdf
calculator_new (1).pdfcalculator_new (1).pdf
calculator_new (1).pdf
 
This is a homework assignment that I have for my Java coding class. .pdf
This is a homework assignment that I have for my Java coding class. .pdfThis is a homework assignment that I have for my Java coding class. .pdf
This is a homework assignment that I have for my Java coding class. .pdf
 
Mylib.pydef allInOne(n1, n2) return {addplus(n1, n2).docx
Mylib.pydef allInOne(n1, n2)    return {addplus(n1, n2).docxMylib.pydef allInOne(n1, n2)    return {addplus(n1, n2).docx
Mylib.pydef allInOne(n1, n2) return {addplus(n1, n2).docx
 
Mylib.pydef allInOne(n1, n2) return {addplus(n1, n2.docx
Mylib.pydef allInOne(n1, n2)    return {addplus(n1, n2.docxMylib.pydef allInOne(n1, n2)    return {addplus(n1, n2.docx
Mylib.pydef allInOne(n1, n2) return {addplus(n1, n2.docx
 
Py Die R E A D M E
Py Die  R E A D M EPy Die  R E A D M E
Py Die R E A D M E
 
λ | Lenses
λ | Lensesλ | Lenses
λ | Lenses
 
Will upvote asapPlease help my code gives me incorrect val.pdf
Will upvote asapPlease help my code gives me incorrect val.pdfWill upvote asapPlease help my code gives me incorrect val.pdf
Will upvote asapPlease help my code gives me incorrect val.pdf
 
Python Tidbits
Python TidbitsPython Tidbits
Python Tidbits
 
Practicle 1.docx
Practicle 1.docxPracticle 1.docx
Practicle 1.docx
 
Will upvote Please fix the following code and post your inputs and o.pdf
Will upvote Please fix the following code and post your inputs and o.pdfWill upvote Please fix the following code and post your inputs and o.pdf
Will upvote Please fix the following code and post your inputs and o.pdf
 
関数プログラミングことはじめ revival
関数プログラミングことはじめ revival関数プログラミングことはじめ revival
関数プログラミングことはじめ revival
 
Practical File Grade 12.pdf
Practical File Grade 12.pdfPractical File Grade 12.pdf
Practical File Grade 12.pdf
 
EcmaScript 6
EcmaScript 6 EcmaScript 6
EcmaScript 6
 
Fix this code so that it will run with proper answers, please dont u.pdf
Fix this code so that it will run with proper answers, please dont u.pdfFix this code so that it will run with proper answers, please dont u.pdf
Fix this code so that it will run with proper answers, please dont u.pdf
 

Dernier

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 

Dernier (20)

ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 

New microsoft office word document

  • 1.
  • 2. Name: Rudra pratap singh Roll NO : Class : Xll SCI SCHOOL : A.P.S ACADEMY This is to cerify that the bonafide work of F.I.T (Practical / Project) has been done by the student as per CBSE requirement during the academic session : 2019-2020 Examiner’s signature Teacher – In – charge Date HEAD OF INSTITUTION
  • 3. I WOULD LIKE TO EXPRESS MY SPECIAL THANKS OF GRATITUDE TO MY TEACHER MRS. DEEPIKA MULLICK AS WELL AS OUR PRINCIPAL MRS. HEMA KALAKOTI WHO GAVE ME THE GOLDEN OPPORTUNITY TO DO THIS WONDERFUL PROJECT ON THE TOPIC GAMEING PROGRAM WHICH ALSO HELPED ME IN DOING A LOT OF RESEARCH AND I COME TO KNOW ABOUT SO MANY NEW THINGS I AM REALLY THANKFUL TO THEM. SECONDLY I WOULD ALSO LIKE TO THANK MY PARENTS AND FRIENDS WHO HELPED ME A LOT IN FINALIZING THIS PROJECT WITHIN THE LIMITED TIME FRAME.
  • 4.
  • 5. importrandom importcollections random.seed(1) size = 5 bombs = collections.defaultdict(int) counts = collections.defaultdict(int) display = collections.defaultdict(lambda: 'X') neighbors = sorted(set((i, j) for i in range(size) for j in range(size)) - {(0, 0)}) # Initialize for x in range(size): for y in range(size): bombs[x, y] = 0 counts[x, y] = 0 display[x, y] = '?' # Set bombs for _ in range(3): x = random.randrange(size) y = random.randrange(size) bombs[x, y] = 1 # Calculate counts for x in range(size): for y in range(size): total = 0 for i in [-1, 0, 1]: for j in [-1, 0, 1]: total += bombs[x + i, y + j]
  • 6. counts[x, y] = total def show(grid): for x in range(size): for y in range(size): print(grid[x, y], end=', ') print() print('Bombs:') show(bombs) print('Counts:') show(counts) alive = True def reveal(x, y): if bombs[x, y]: return False display[x, y] = counts[x, y] if counts[x, y]: return True zeros = [ (x, y) ] while zeros: x, y = zeros.pop() if not ((0 <= x < size) and (0 <= y < size)): continue if counts[x, y] == 0: display[x, y] = 0 for i in (-1, 0, 1): for j in (-1, 0, 1):
  • 7. if i == j == 0: continue offset_x = x + i offset_y = y + j seen = display[offset_x, offset_y] != '?' if counts[offset_x, offset_y] == 0 and notseen: zeros.append((offset_x, offset_y)) return True while alive: show(display) x = int(input('row: ')) y = int(input('column: ')) alive = reveal(x, y) if not alive or not any(spot== '?' for spotin display.values()): break if alive: print('Congratulations!You win.') else: print('Sorry, you failed.') ---------------------------------------------------------------------------------------------------- -------------------------
  • 8.
  • 9.
  • 10.
  • 11. importatexit importcollections importitertools importrandom importsqlite3 importthreading importtime importconsole original_terminal_state = console.get_terminal_mode() atexit.register(console.set_terminal_mode, original_terminal_state) class Game: "Game state for Tetris." def __init__(self, width, height, seed=None): self.random = random.Random(seed) self.width= width self.height = height self.board = collections.defaultdict(lambda: '#') for x in range(width): for y in range(height): self.board[x, y] = ' ' self.active = True self.speed = 20 self.next_letter = self.random.choice('IJLOSTZ') self.piece = self.next_piece() self.score = 0 self.stash = None def draw(self): "Draw game state." print('Score:', self.score, end='rn') print('Level:', self.score// 4 + 1, end='rn') print('Nextpiece:', self.next_letter, end='rn') print('Stash piece:', 'no' if self.stash is Noneelse 'yes', end='rn') print('*' * (self.width + 2), end='rn')
  • 12. for y in range(self.height): print('|', end='') for x in range(self.width): if (x, y) in self.piece: print('@', end='') else: print(self.board[x, y], end='') print('|', end='rn') print('*' * (self.width + 2), end='rn') def next_piece(self): "Create a new piece, on collision set active to False." letter = self.next_letter self.next_letter = self.random.choice('IJLOSTZ') if letter == 'I': piece = {(0, 0), (0, 1), (0, 2), (0, 3)} elif letter == 'J': piece = {(1, 0), (1, 1), (1, 2), (0, 2)} elif letter == 'L': piece = {(0, 0), (0, 1), (0, 2), (1, 2)} elif letter == 'O': piece = {(0, 0), (0, 1), (1, 0), (1, 1)} elif letter == 'S': piece = {(0, 1), (1, 0), (1, 1), (2, 0)} elif letter == 'T': piece = {(0, 0), (1, 0), (2, 0), (1, 1)} else: assert letter == 'Z' piece = {(0, 0), (1, 0), (1, 1), (2, 1)} offset = self.width // 2 - 1 piece = {(x + offset, y) for x, y in piece} if self.collide(piece): self.end() return piece def end(self): self.active = False print('Gameover!Pressany key to quit.', end='rn')
  • 13. def tick(self, mark): "Notify the game of a clock tick." if mark % self.speed == 0: moved = self.move_piece(0, 1) if not moved: for x, y in self.piece: self.board[x, y] = '#' self.collapse() self.piece = self.next_piece() self.draw() def collapse(self): "Collapse fulllines." y = self.height - 1 while y >= 0: full_line= all(self.board[x, y] == '#' for x in range(self.width)) if full_line: z = y while z > 0: for x in range(self.width): self.board[x, z] = self.board[x, z - 1] z -= 1 for x in range(self.width): self.board[x, 0] = ' ' self.score += 1 if self.score % 4 == 0: self.speed -= 1 else: y -= 1 def collide(self, piece): "Check whether piece collides with others on board." return any(self.board[x, y] != ' ' for x, y in piece) def move_piece(self, x, y): "Movepiece by delta x and y." new_piece= {(a + x, y + b) for a, b in self.piece} if self.collide(new_piece): return False
  • 14. self.piece = new_piece return True def rotate_piece(self): "Rotate piece." min_x = min(xfor x, y in self.piece) max_x = max(x for x, y in self.piece) diff_x = max_x - min_x min_y = min(y for x, y in self.piece) max_y = max(y for x, y in self.piece) diff_y = max_y - min_y size = max(diff_x, diff_y) new_piece= set() for x, y in self.piece: pair = (min_x + size) - (y - min_y), min_y + (x - min_x) new_piece.add(pair) if self.collide(new_piece): return False self.piece = new_piece return True def move(self, key): "Update game state based on key press." if key == 'left': moved = self.move_piece(-1, 0) elif key == 'right': moved = self.move_piece(1, 0) elif key == 'down': moved = self.move_piece(0, 1) elif key == 'up': moved = self.rotate_piece() elif key == 'swap': if self.stash is None: self.stash = self.piece self.piece = self.next_piece() else: self.piece, self.stash = self.stash, self.piece if self.collide(self.piece): self.end()
  • 15. moved = True else: assert key == 'space' moved = self.move_piece(0, 1) while moved: moved = self.move_piece(0, 1) moved = True if moved: self.draw() def draw_loop(game): game.draw() counter = itertools.count(start=1) while game.active: mark = next(counter) game.tick(mark) time.sleep(0.1) def input_loop(game): """Input loop. Handlekeyboard inputin a separate thread. """ while game.active: key = console.get_input() if key is None: continue elif key == 'quit': game.active = False else: assert key in ('left', 'down', 'right', 'up', 'space', 'swap') game.move(key) console.set_terminal_mode(original_terminal_state) print('Enter your namefor leaderboard (blank to ignore):') name = input()
  • 16. if name: con = sqlite3.connect('tetris.sqlite3', isolation_level=None) con.execute('CREATE TABLE IFNOT EXISTS Leaderboard (name, score)') con.execute('INSERTINTO Leaderboard VALUES (?, ?)', (name, game.score)) scores = con.execute('SELECT* FROM Leaderboard ORDER BY score DESC LIMIT 10') print('{0:<16}| {1:<16}'.format('Name', 'Score')) for pair in scores: print('{0:<16}| {1:<16}'.format(*pair)) def main(): "Main entry-pointfor Tetris." game = Game(10, 10) draw_thread = threading.Thread(target=draw_loop, args=(game,)) input_thread = threading.Thread(target=input_loop, args=(game,)) draw_thread.start() input_thread.start() draw_thread.join() input_thread.join() if __name__ == '__main__': main() ---------------------------------------------------------------------------------------------------
  • 17.
  • 18.
  • 19. import time from time import sleep import random sus="-"*35 depo=["rock","paper","scissors"] while True: x=input("rock , paper, scissors: ") if x not in depo: print ("Dontcheat!") continue pc=random.choice(depo) sleep(0.5) print (("Computer picked {}.").format(pc)) if x==pc: sleep(0.5) print (("nIt's a draw.n{}").format(sus)) elif x=="rock" and pc=="scissors": sleep(0.5) print (("nYou win.rock beats scissorsn{}").format(sus)) elif x=="paper" and pc=="rock": sleep(0.5) print (("nYou win.paper beats rockn{}").format(sus)) elif x=="scissors" and pc=="paper": sleep(0.5) print (("nYou win.scissors beats papern{}").format(sus)) else: sleep(0.5) print (("nYou lose. {} beats {}n{}").format(pc,x,sus)) input()