question archive A Python program: I need help with writing this python program

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.

  • If any entry/exit location of the current ray is shared with any entry/exit of a previous ray, then it should not be deducted from the score again.
  • Each entry and exit location counts as a point. Hits and reflections therefore cost one point, while detours cost two points
  • Each incorrect guess of an atom position will cost 5 points, but repeat guesses should not be deducted from the score again.

 

Tip: Probably the easiest way of representing the board is to use a list of lists.

 

The BlackBoxGame class must include the following methods:

  • An init method that takes as its parameter a list of (row, column) tuples for the locations of the atoms in the black box, and initializes any data members. You may assume that the given coordinates are valid and don't contain any duplicates. You may also assume that the list contains at least one tuple.
  • A method named shoot_ray that takes as its parameters the row and column (in that order) of the border square where the ray originates. If the chosen row and column designate a corner square or a non-border square, it should return False. Otherwise, shoot_ray should return a tuple of the row and column (in that order) of the exit border square. If there is no exit border square (because there was a hit), then shoot_ray should return None. The guessing player's score should be adjusted accordingly. (Note: if the return value of a function can have different types, it's a very good idea to specify that in the docstring.)
  • A method named guess_atom that takes as parameters a row and column (in that order). If there is an atom at that location, guess_atom should return True, otherwise it should return False. The guessing player's score should be adjusted accordingly.
  • A method named get_score that takes no parameters and returns the current score.
  • A method named atoms_left that takes no parameters and returns the number of atoms that haven't been guessed yet.

 

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)

pur-new-sol

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE