How to use the chess.engine.Mate function in chess

To help you get started, we’ve selected a few chess examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github linrock / chess-puzzle-maker / test / unit / test_ambiguous.py View on Github external
def test_not_ambiguous_mate_vs_counter_mate(self):
        self.assertFalse(ambiguous_best_move([
            Mate(1),
            Mate(-14),
            Mate(-11),
        ]))
        self.assertFalse(ambiguous_best_move([
            Mate(-2),
            Mate(10),
            Mate(8),
        ]))
github linrock / chess-puzzle-maker / test / unit / test_should_investigate.py View on Github external
def test_not_investigating_major_advantage_to_mate_threat(self):
        a = Cp(900)
        b = Mate(5)
        self.assertFalse(should_investigate(a, b, board))

        a = Cp(-900)
        b = Mate(-5)
        self.assertFalse(should_investigate(a, b, board))
github linrock / chess-puzzle-maker / test / unit / test_should_investigate.py View on Github external
def test_investigating_even_position_to_mate(self):
        a = Cp(0)
        b = Mate(5)
        self.assertTrue(should_investigate(a, b, board))

        a = Cp(0)
        b = Mate(-5)
        self.assertTrue(should_investigate(a, b, board))
github linrock / chess-puzzle-maker / test / unit / test_should_investigate.py View on Github external
def test_investigating_mate_threat_to_major_disadvantage(self):
        a = Mate(5)
        b = Cp(-700)
        self.assertTrue(should_investigate(a, b, board))

        a = Mate(-5)
        b = Cp(700)
        self.assertTrue(should_investigate(a, b, board))
github linrock / chess-puzzle-maker / test / unit / test_ambiguous.py View on Github external
def test_ambiguous_mate_vs_significant_advantage(self):
        self.assertTrue(ambiguous_best_move([
            Mate(1),
            Cp(700),
        ]))
github linrock / chess-puzzle-maker / test / unit / test_should_investigate.py View on Github external
def test_investigating_mate_threat_to_getting_mated(self):
        a = Mate(1)
        b = Mate(-1)
        self.assertTrue(should_investigate(a, b, board))

        a = Mate(-1)
        b = Mate(1)
        self.assertTrue(should_investigate(a, b, board))
github niklasf / python-chess / chess / engine.py View on Github external
def __pos__(self) -> "Mate":
        return Mate(self.moves)
github niklasf / python-chess / chess / engine.py View on Github external
if len(integer_tokens) < 4 or not selector:
        return info

    # Required integer tokens.
    info["depth"] = integer_tokens.pop(0)
    cp = integer_tokens.pop(0)
    info["time"] = float(integer_tokens.pop(0)) / 100
    info["nodes"] = int(integer_tokens.pop(0))

    # Score.
    if cp <= -100000:
        score = Mate(cp + 100000)  # type: Score
    elif cp == 100000:
        score = MateGiven
    elif cp >= 100000:
        score = Mate(cp - 100000)
    else:
        score = Cp(cp)
    info["score"] = PovScore(score, root_board.turn)

    # Optional integer tokens.
    if integer_tokens:
        info["seldepth"] = integer_tokens.pop(0)
    if integer_tokens:
        info["nps"] = integer_tokens.pop(0)

    while len(integer_tokens) > 1:
        # Reserved for future extensions.
        integer_tokens.pop(0)

    if integer_tokens:
        info["tbhits"] = integer_tokens.pop(0)
github niklasf / python-chess / chess / engine.py View on Github external
LOGGER.error("exception parsing %s from info: %r", parameter, arg)
        elif parameter == "ebf":
            try:
                info["ebf"] = float(tokens.pop(0))
            except (ValueError, IndexError):
                LOGGER.error("exception parsing %s from info: %r", parameter, arg)
        elif parameter == "score" and selector & INFO_SCORE:
            try:
                kind = tokens.pop(0)
                value = tokens.pop(0)
                if tokens and tokens[0] in ["lowerbound", "upperbound"]:
                    info[tokens.pop(0)] = True
                if kind == "cp":
                    info["score"] = PovScore(Cp(int(value)), root_board.turn)
                elif kind == "mate":
                    info["score"] = PovScore(Mate(int(value)), root_board.turn)
                else:
                    LOGGER.error("unknown score kind %r in info (expected cp or mate): %r", kind, arg)
            except (ValueError, IndexError):
                LOGGER.error("exception parsing score from info: %r", arg)
        elif parameter == "currmove":
            try:
                info["currmove"] = chess.Move.from_uci(tokens.pop(0))
            except (ValueError, IndexError):
                LOGGER.error("exception parsing currmove from info: %r", arg)
        elif parameter == "currline" and selector & INFO_CURRLINE:
            try:
                if "currline" not in info:
                    info["currline"] = {}

                cpunr = int(tokens.pop(0))
                info["currline"][cpunr] = currline = []

chess

A chess library with move generation and validation, Polyglot opening book probing, PGN reading and writing, Gaviota tablebase probing, Syzygy tablebase probing, and XBoard/UCI engine communication.

GPL-3.0
Latest version published 10 months ago

Package Health Score

72 / 100
Full package analysis