question archive A Python program: I need help with writing this python program
Subject:Computer SciencePrice: Bought3
A Python program: I need help with writing this python program. A class named BlackBoxGame for playing an abstract board game called Black Box. It takes place on a 10x10 grid. Rows 0 and 9, and columns 0 and 9 (border squares), are used by the guessing player for shooting rays into the black box. The atoms are restricted to being within rows 1-8 and columns 1-8.
The guessing player will start with 25 points.
Tip: Probably the easiest way of representing the board is to use a list of lists.
The BlackBoxGame class must include the following methods:
Feel free to add whatever other classes, methods, or data members. All data members must be private. All methods must have no more than 20-25 lines of code - don't try to get around this by making really long or complicated lines of code.
Whether you think of the list indices as being [row][column] or [column][row] doesn't matter as long as you're consistent.
Here's a very simple example of how the class could be used:
game = BlackBoxGame([(3,2),(1,7),(4,6),(8,8)])
move_result = game.shoot_ray(3,9)
game.shoot_ray(0,2)
guess_result = game.guess_atom(5,5)
score = game.get_score()
atoms = game.atoms_left()
----------------------------------------------------------------------------------------------------------------------------------------
Current Code:
class BlackBoxGame():
def __init__(self,atoms):
self.board = [list([0]*10)]*10
self.atoms = atoms
self.score = 25
self.guesses = []
def shoot_ray(self,row,column):
"""Takes in row and column as its parameters
If the chosen row & column is a corner or non border square return False
"""
if (row == 9 or row == 0) or (column == 0 or column == 9):
if (row == 9 or row == 0) and (column == 0 or column == 9):
return False
if row == 9 or row == 0:
if row == 9:
row = 0
elif row == 0:
row == 9
for i in self.atoms:
if i[1] == column:
return False
else:
return (row,column)
if column == 9 or column == 0:
if column == 9:
column = 0
elif column == 0:
column == 9
for i in self.atoms:
if i[0] == row:
return False
else:
return (row,column)
return False
def guess_atom(self,row,column):
if (row,column) in self.atoms:
self.atoms.remove(row,column)
return True
else:
if (row,column) in self.guesses:
return False
self.score -= 5
self.guesses.append((row,column))
return False
def get_score(self):
return self.score
def atoms_left(self):
return len(self.atoms)
