예제 #1
0
def op_tail(giter: Iterator[Tuple[str, Iterator[str]]],
            args: argparse.Namespace) -> Iterator[Tuple[str, str]]:
    n_rows = int(args.args[0])

    for k, gi in giter:
        for i in mi.tail(n_rows, gi):
            yield k, i
예제 #2
0
 def captures(self, gamestate):
     """
     Docstrings
     """
     gamestate = {(piece.pos.x, piece.pos.y): piece.color
                  for piece in gamestate}
     attacks = []
     for i, j in tail(4, self.pos.vectors):
         n = 1
         while self.isOnBoard(position := (self.pos.x + i * n,
                                           self.pos.y + j * n)):
예제 #3
0
 def moves(self, gamestate):
     """
     Docstrings
     """
     gamestate = [(piece.pos.x, piece.pos.y) for piece in gamestate]
     moves = []
     for i, j in tail(4, self.pos.vectors):
         direction = []
         n = 1
         while self.isOnBoard(move := (self.pos.x + i * n, self.pos.y +
                                       j * n)) and (self.pos.x + i * n,
                                                    self.pos.y +
                                                    j * n) not in gamestate:
             direction.append(move)
             n += 1
         moves += direction
예제 #4
0
def sample_files(config: Dict, table_spec: Dict, s3_files: Generator,
                 sample_rate: int = 5, max_records: int = 1000, max_files: int = 5) -> Generator:
    """
    Get samples from all files
    :param config:
    :param table_spec:
    :param s3_files:
    :param sample_rate:
    :param max_records:
    :param max_files:
    :returns: Generator containing all samples as dicts
    """
    LOGGER.info("Sampling files (max files: %s)", max_files)
    for s3_file in more_itertools.tail(max_files, s3_files):
        LOGGER.info('Sampling %s (max records: %s, sample rate: %s)',
                    s3_file['key'],
                    max_records,
                    sample_rate)
        yield from itertools.islice(sample_file(config, table_spec, s3_file['key'], sample_rate), max_records)
예제 #5
0
    def moveBank(self, position, piece):
        """
        Méthode qui retourne un tuple des coups légals
        pour la piece à la position en argument.

        :returns: generator
        """
        x, y = position
        if piece == 'K':
            return ((x + i, y + j) for i, j in self.vectors)
        elif piece == 'T':
            return (((x + i * n, y + j * n) for n in range(1, 9))
                    for i, j in take(4, self.vectors))
        elif piece == 'Q':
            return (((x + i * n, y + j * n) for n in range(1, 9))
                    for i, j in self.vectors)
        elif piece == 'F':
            return (((x + i * n, y + j * n) for n in range(1, 9))
                    for i, j in tail(4, self.vectors))
        elif piece == 'C':
            return ((x + dx, y + dy)
                    for dx, dy in chain(product((-1, 1), (
                        -2, 2)), product((-2, 2), (-1, 1))))
예제 #6
0
 def test_greater(self):
     """Length of iterable is greater than requested tail"""
     self.assertEqual(list(mi.tail(3, 'ABCDEFG')), ['E', 'F', 'G'])
예제 #7
0
 def test_less(self):
     """Length of iterable is less than requested tail"""
     self.assertEqual(
         list(mi.tail(8, 'ABCDEFG')), ['A', 'B', 'C', 'D', 'E', 'F', 'G']
     )
예제 #8
0
 def test_equal(self):
     """Length of iterable is equal to the requested tail"""
     self.assertEqual(
         list(mi.tail(7, 'ABCDEFG')), ['A', 'B', 'C', 'D', 'E', 'F', 'G']
     )
예제 #9
0
 def test_greater(self):
     """Length of iterable is greather than requested tail"""
     self.assertEqual(list(mi.tail(3, 'ABCDEFG')), ['E', 'F', 'G'])
예제 #10
0
    def __init__(self):
        super().__init__()

        # Caractéristiques de la fenêtre
        pygame.display.set_caption("Échecs")
        self.dx = 104
        self.boardHeight = 696
        self.boardWidth = 696
        self.squareX, self.squareY = self.boardWidth // 8, self.boardHeight // 8
        self.screen = pygame.display.set_mode(
            (self.boardWidth + self.dx, self.boardHeight))
        self.screen.fill((104, 103, 98))

        # Images
        self.board = pygame.image.load("images/board.png")
        self.contour = pygame.image.load("images/contour.png")
        self.circle = pygame.image.load("images/circle.png")
        self.pieces = {
            'black': {
                'P': pygame.image.load("images/pion_noir.png"),
                'T': pygame.image.load("images/tour_noir.png"),
                'F': pygame.image.load("images/fou_noir.png"),
                'Q': pygame.image.load("images/reine_noir.png"),
                'K': pygame.image.load("images/roi_noir.png"),
                'C': pygame.image.load("images/cheval_noir.png")
            },
            'white': {
                'P': pygame.image.load("images/pion_blanc.png"),
                'T': pygame.image.load("images/tour_blanc.png"),
                'F': pygame.image.load("images/fou_blanc.png"),
                'Q': pygame.image.load("images/reine_blanc.png"),
                'K': pygame.image.load("images/roi_blanc.png"),
                'C': pygame.image.load("images/cheval_blanc.png")
            }
        }
        self.button = {
            True: pygame.image.load("images/on.png"),
            False: pygame.image.load("images/off.png")
        }

        # Suivi des clicks
        self.boardClickPosition = [(0, 0), (0, 0)]
        self.cursorPosition = None

        # Fonctions anonymes pour les positions
        self.windowToBoard = lambda position: (position[0] // self.squareX + 1,
                                               8 - position[1] // self.squareY)
        self.boardToWindow = lambda position: (
            (position[0] - 1) * self.squareX, self.boardHeight -
            (position[1]) * self.squareY)
        self.getLastPositions = lambda positions: list(tail(2, positions))
        self.scaleX = lambda index: self.boardWidth + (index // 6) * (
            (self.boardWidth // 8) // 3)
        self.scaleY = lambda index, color: (index % 6) * (
            (self.boardHeight // 8) // 3) + self.colorPosition[color]

        # Boolean values
        self.showMove = True

        # Importation de sons
        self.moveSound = pygame.mixer.Sound("sons/moveSound.wav")
        self.buttonSound = pygame.mixer.Sound("sons/switchSound.wav")

        # Placements des pions mangés par couleur
        self.colorPosition = {'black': 0, 'white': (self.boardHeight // 8) * 6}
예제 #11
0
 def test_greater(self):
     """Length of iterable is greater than requested tail"""
     self.assertEqual(list(mi.tail(3, "ABCDEFG")), ["E", "F", "G"])
예제 #12
0
    def __init__(self):
        super().__init__()

        # Caractéristiques de la fenêtre
        pygame.display.set_caption("Échecs")
        self.dx = 104
        self.boardHeight = 696
        self.boardWidth = 696
        self.squareX, self.squareY = self.boardWidth // 8, self.boardHeight // 8
        self.screen = pygame.display.set_mode(
            (self.boardWidth + self.dx, self.boardHeight))
        self.screen.fill((104, 103, 98))

        # Images
        self.board = pygame.image.load("board.png")
        self.contour = pygame.image.load("contour.png")
        self.circle = pygame.image.load("circle.png")
        self.pieces = {
            'black': {
                'P': pygame.image.load("pion_noir.png"),
                'T': pygame.image.load("tour_noir.png"),
                'F': pygame.image.load("fou_noir.png"),
                'Q': pygame.image.load("reine_noir.png"),
                'K': pygame.image.load("roi_noir.png"),
                'C': pygame.image.load("cheval_noir.png")
            },
            'white': {
                'P': pygame.image.load("pion_blanc.png"),
                'T': pygame.image.load("tour_blanc.png"),
                'F': pygame.image.load("fou_blanc.png"),
                'Q': pygame.image.load("reine_blanc.png"),
                'K': pygame.image.load("roi_blanc.png"),
                'C': pygame.image.load("cheval_blanc.png")
            }
        }

        # Suivi des clicks
        self.boardClickPosition = [(0, 0), (0, 0)]
        self.cursorPosition = None

        # Fonctions anonymes pour les positions
        self.windowToBoard = lambda position: (position[0] // self.squareX + 1,
                                               8 - position[1] // self.squareY)
        self.boardToWindow = lambda position: (
            (position[0] - 1) * self.squareX, self.boardHeight -
            (position[1]) * self.squareY)
        self.getLastPositions = lambda positions: list(tail(2, positions))
        self.scaleX = lambda index: self.boardWidth + (index // 5) * (
            (self.boardWidth // 8) // 3)
        self.scaleY = lambda index: (index % 5) * (
            (self.boardHeight // 8) // 3) + (self.boardHeight // 8) // 10

        # Boolean values
        self.showMove = True
        self.button = {
            True: pygame.image.load("on.png"),
            False: pygame.image.load("off.png")
        }

        # Importation de sons
        self.moveSound = pygame.mixer.Sound("moveSound.wav")
        self.buttonSound = pygame.mixer.Sound("switchSound.wav")
        self.gagnant = pygame.mixer.Sound("gagnant.wav")
        self.perdant = pygame.mixer.Sound("perdant.wav")
        self.mauvaisc = pygame.mixer.Sound("pourri.wav")
        self.echeccc = pygame.mixer.Sound("echec_1_.wav")
예제 #13
0
 def test_less(self):
     """Length of iterable is less than requested tail"""
     self.assertEqual(
         list(mi.tail(8, "ABCDEFG")), ["A", "B", "C", "D", "E", "F", "G"]
     )
예제 #14
0
 def test_equal(self):
     """Length of iterable is equal to the requested tail"""
     self.assertEqual(
         list(mi.tail(7, "ABCDEFG")), ["A", "B", "C", "D", "E", "F", "G"]
     )
예제 #15
0
 def test_equal(self):
     """Length of iterable is equal to the requested tail"""
     self.assertEqual(list(mi.tail(7, 'ABCDEFG')),
                      ['A', 'B', 'C', 'D', 'E', 'F', 'G'])
예제 #16
0
 def test_less(self):
     """Length of iterable is less than requested tail"""
     self.assertEqual(list(mi.tail(8, 'ABCDEFG')),
                      ['A', 'B', 'C', 'D', 'E', 'F', 'G'])
예제 #17
0
def _first_and_last(iterable, ordering=lambda x: x):
    return ((next(it), next(tail(1, it), ''))
            for it in _consecutive_groups(iterable, ordering))