Vous êtes sur la page 1sur 19

# Name: Rudra pratap singh

## Roll NO : Class : Xll

SCI

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

## Examiner’s signature Teacher – In – charge

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.
import random
import collections

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 not seen:
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 spot in display.values()):

break

if alive:
print('Congratulations! You win.')
else:
print('Sorry, you failed.')

----------------------------------------------------------------------------------------------------
-------------------------
import atexit
import collections
import itertools
import random
import sqlite3
import time

import console

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='\r\n')
print('Level:', self.score // 4 + 1, end='\r\n')
print('Next piece:', self.next_letter, end='\r\n')
print('Stash piece:', 'no' if self.stash is None else 'yes', end='\r\n')
print('*' * (self.width + 2), end='\r\n')
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='\r\n')
print('*' * (self.width + 2), end='\r\n')

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('Game over! Press any key to quit.', end='\r\n')
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 full lines."
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):

"Move piece 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(x for 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)
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.

## Handle keyboard input in 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)
name = input()
if name:
con = sqlite3.connect('tetris.sqlite3', isolation_level=None)
con.execute('CREATE TABLE IF NOT EXISTS Leaderboard (name, score)')
con.execute('INSERT INTO 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-point for Tetris."
game = Game(10, 10)

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 ("Dont cheat!")
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 scissors\n{}").format(sus))
elif x=="paper" and pc=="rock":
sleep(0.5)
print (("\nYou win.paper beats rock\n{}").format(sus))
elif x=="scissors" and pc=="paper":
sleep(0.5)
print (("\nYou win.scissors beats paper\n{}").format(sus))
else:
sleep(0.5)
print (("\nYou lose. {} beats {}\n{}").format(pc,x,sus))
input()