Exemplo n.º 1
0
    def add_piece(self):
        # If grid is full, do not bother trying to add
        if is_grid_full(self.grid):
            self.position = (-1, -1)
            return self.grid

        # Create a deep copy of the grid so that it does not change the original grid
        grid_to_modify = copy.deepcopy(self.grid)

        empty_spaces = get_empty_tiles_positions(grid_to_modify)
        # See if desired position to add is empty
        if self.position in empty_spaces:
            add_new_tile_at_position(grid_to_modify, self.position, self.value)

            # Create a new piece object
            piece = Piece(self.position)
            # Add the value of the piece
            piece.value = self.value
            piece.marker = self.piece_marker_dict[self.value]

            # Put the piece in the list of the player
            self.player.pieces.append(piece)

        else:
            self.position = (-1, -1)

        return grid_to_modify