Exemplo n.º 1
0
    def place_avatar(self, color: Color, position: Position) -> None:
        """
        Places an avatar on behalf of the given player color at
        the specified location if it is not a hole.

        :param color: color of player to place avatar for
        :param position: position to place avatar
        :return: None
        """
        # Validate type of color
        if not isinstance(color, Color):
            raise TypeError('Expected Color for player color!')

        # Validate type of position
        if not isinstance(position, Position):
            raise TypeError('Expected Position for position!')

        # Make sure target position is not occupied by another player or
        # a hole
        if not self.is_position_open(position):
            raise InvalidPositionException(
                f"Position {position} already occupied or hole!")

        # Make sure player exists
        if color not in self.player_order:
            raise NonExistentPlayerException()

        # Update placement to reflect updated avatar's position
        self.get_player_by_color(color).add_place(position)

        if self.__all_avatars_have_been_placed:
            # Proceed to the next unstuck player
            self.__trigger_next_turn(0)
Exemplo n.º 2
0
    def is_position_open(self, position: Position) -> bool:
        """
        Returns false if given position is either a hole or occupied
        by another avatar. Otherwise, it returns true.

        :param position: position to check
        :return: boolean indicating if condition above is fulfilled
        """
        if not isinstance(position, Position):
            raise TypeError('Expected Position for position!')

        # Check if position is within bounds
        if position.x >= self.__board.rows or position.y >= self.__board.cols:
            raise InvalidPositionException(
                f'{position} is outside the bounds of the board!')

        # Check if tile is a hole
        if self.__board.get_tile(position).is_hole:
            return False

        # Check if an avatar is at position
        for placement_arr in self.placements.values():
            if position in placement_arr:
                return False

        return True
Exemplo n.º 3
0
    def input(self, position):
        position = int(position)

        if position >= 1 and position <= 8:
            return self.pifacedigital.input_pins[position - 1].value

        raise InvalidPositionException("PiFace has no input position " +
                                       str(position))
Exemplo n.º 4
0
    def relay(self, position, value):
        position = int(position)

        if position >= 1 and position <= 2:
            self.output(position, value)
            return

        raise InvalidPositionException("Pyface has no relay position " +
                                       str(position))
    def input(self, position):
        position = int(position)

        if position == 1:
            return automationhat.input.one.read()
        elif position == 2:
            return automationhat.input.two.read()
        elif position == 3:
            return automationhat.input.three.read()

        raise InvalidPositionException(
            "Automation Phat has no input position " + str(position))
    def relay(self, position, value):
        position = int(position)

        if value:
            value = 1
        else:
            value = 0

        if position == 1:
            automationhat.relay.one.write(value)

        raise InvalidPositionException(
            "Automation Phat has no relay position " + str(position))
Exemplo n.º 7
0
    def get_tile(self, pt: Position) -> AbstractTile:
        """
        Returns the tile at the given point.

        :param pt: position the tile lives
        :return: AbstractTile object
        """
        # Validate point
        if not isinstance(pt, Position):
            raise TypeError('Expected Position object for pt!')

        if pt not in self.__tiles.keys():
            raise InvalidPositionException('No tile exists at given position!')

        return self.__tiles.get(pt)
    def output(self, position, value):
        position = int(position)

        if value:
            value = 1
        else:
            value = 0

        if position == 1:
            return automationhat.output.one.write(value)
        elif position == 2:
            return automationhat.output.two.write(value)
        elif position == 3:
            return automationhat.output.three.write(value)

        raise InvalidPositionException(
            "Automation Phat has no output position " + str(position))
Exemplo n.º 9
0
    def output(self, position, value):
        position = int(position)

        if value:
            value = 1
        else:
            value = 0

        if position >= 1 and position <= 8:
            if value:
                self.pifacedigital.output_pins[position - 1].turn_on()
            else:
                self.pifacedigital.output_pins[position - 1].turn_off()
            return

        raise InvalidPositionException("PiFace has no output position " +
                                       str(position))