Ejemplo n.º 1
0
    def _get_legal_directions(board: np.array, board_size: int,
                              location: tuple, color_value: int) -> list:
        legal_directions: List[Tuple[int, int]] = []

        # check if location points to an empty spot
        if board.item(location) != -1:
            return legal_directions

        # search in all directions
        for direction in Board._directions:
            found_opponent: bool = False  # check wetter there is an opponent's disk
            i: int = location[0] + direction[0]
            j: int = location[1] + direction[1]
            while 0 <= i < board_size and 0 <= j < board_size:
                # while not out of the board, keep going
                disk: int = board[i, j]
                if disk == -1 or (disk == color_value and not found_opponent):
                    break  # found empty spot or player's disk before finding opponent's disk

                if disk == 1 - color_value:
                    found_opponent: bool = True  # found opponent's disk

                if disk == color_value and found_opponent:
                    legal_directions.append(
                        direction
                    )  # found own disk after finding opponent's disk
                    break

                i += direction[0]
                j += direction[1]

        return legal_directions
Ejemplo n.º 2
0
    def _getIj(self, tile: np.array, ij: List[Tuple[int, int]] = None):
        newIj = rollLowFreqIndex(self.window, ij)

        if tile.item(newIj) < 1: return self._getIj(tile, ij)
        return newIj