Ejemplo n.º 1
0
    def __init__(self, board: Board, addr: str):

        # a reference to the board
        self.board = board

        # the position address
        self.address = addr

        # the piece currently in this position
        self.piece: Union[tuple, Piece] = ()

        try:
            assert address.is_valid(self.address) is True

        except AssertionError as e:
            print("Tried initializing position with invalid address")
            raise e
Ejemplo n.º 2
0
    def copy_board(self, original=None) -> dict:
        """Copy the board state."""
        original = original or self.positions
        positions: dict = {}
        for let in address.LETTERS:  # iterate through columns
            positions[let] = {}
            for num in address.NUMBERS:  # iterate through rows
                addr = let + num
                if address.is_valid(addr):
                    if num == 0:
                        pos = Position(self, "b0")
                    else:
                        pos = Position(self, addr)

                    if original[let][int(num)].is_tiger():
                        pos.place_tiger()
                    elif original[let][int(num)].is_goat():
                        pos.place_goat()
                    positions[let][int(num)] = pos
        return positions
Ejemplo n.º 3
0
    def clear(self):
        """
        Reset the board.
        """
        self.positions = {}
        for let in address.LETTERS:  # iterate through columns
            self.positions[let] = {}

            for num in address.NUMBERS:  # iterate through rows
                addr = let + num
                # check if this position ID is valid
                if address.is_valid(addr):
                    if num == 0:
                        pos = Position(self, "b0")
                    else:
                        pos = Position(self, addr)

                    self.positions[let][int(num)] = pos

        # also reset the number of captured pieces
        self.num_captured = 0
        self.num_moves = 0
        self.is_all_goats_placed = False