Example #1
0
    def perft(self, depth):
        nodes = 0
        if depth == 0:
            return 1
        for mv in self.pseudo_moves:
            pc = self.make_move(mv)
            if not movegen.king_attacked(self, not self.color):
                nodes += self.perft(depth - 1)
                if depth == 1:
                    if pc:
                        self.num_captures += 1
                    prm = move.promotion(mv)
                    if prm:
                        if prm == piece.PAWN:
                            self.num_captures += 1
                            self.num_en_passant += 1
                        elif prm == piece.KING:
                            self.num_castles += 1
                        else:
                            self.num_promotions += 1

                    if movegen.king_attacked(self, self.color):
                        self.num_checks += 1
                        if self._game_over():
                            self.num_mates += 1
            self.unmake_move()
        return nodes
Example #2
0
    def perft(self, depth):
        nodes = 0
        if depth == 0:
            return 1
        for mv in self.pseudo_moves:
            pc = self.make_move(mv)
            if not movegen.king_attacked(self, not self.color):
                nodes += self.perft(depth - 1)
                if depth == 1:
                    if pc:
                        self.num_captures += 1
                    prm = move.promotion(mv)
                    if prm:
                        if prm == piece.PAWN:
                            self.num_captures += 1
                            self.num_en_passant += 1
                        elif prm == piece.KING:
                            self.num_castles += 1
                        else:
                            self.num_promotions += 1

                    if movegen.king_attacked(self, self.color):
                        self.num_checks += 1
                        if self._game_over():
                            self.num_mates += 1
            self.unmake_move()
        return nodes
Example #3
0
    def _validate_moves(self, moves, check_end=True):
        legal = []
        for i, mv in enumerate(moves):
            moving_color = self.color
            pc = self.make_move(mv)
            if not movegen.king_attacked(self, moving_color):
                if pc:
                    mv = move.set_capture(mv)

                if check_end and movegen.king_attacked(self, self.color):
                    if self._game_over():
                        mv = move.set_mate(mv)
                    else:
                        mv = move.set_check(mv)
                legal.append(mv)
            self.unmake_move()
        return legal
Example #4
0
    def _validate_moves(self, moves, check_end=True):
        legal = []
        for i, mv in enumerate(moves):
            moving_color = self.color
            pc = self.make_move(mv)
            if not movegen.king_attacked(self, moving_color):
                if pc:
                    mv = move.set_capture(mv)

                if check_end and movegen.king_attacked(self, self.color):
                    if self._game_over():
                        mv = move.set_mate(mv)
                    else:
                        mv = move.set_check(mv)
                legal.append(mv)
            self.unmake_move()
        return legal