How to use the chess.engine.Cp 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_ambiguous_significant_advantages(self):
        self.assertTrue(ambiguous_best_move([
            Cp(767),
            Cp(758),
            Cp(177),
        ]))
        self.assertTrue(ambiguous_best_move([
            Cp(552),
            Cp(505),
            Cp(443),
        ]))
        self.assertTrue(ambiguous_best_move([
            Cp(408),
            Cp(224),
            Cp(219),
        ]))
        self.assertTrue(ambiguous_best_move([
            Cp(254),
            Cp(254),
            Cp(240),
        ]))
github linrock / chess-puzzle-maker / test / unit / test_ambiguous.py View on Github external
Cp(-78),
            Cp(-154),
            Cp(-192),
        ]))
        self.assertTrue(ambiguous_best_move([
            Cp(262),
            Cp(191),
            Cp(186),
        ]))
        self.assertTrue(ambiguous_best_move([
            Cp(166),
            Cp(152),
            Cp(146),
        ]))
        self.assertTrue(ambiguous_best_move([
            Cp(72),
            Cp(25),
            Cp(8),
        ]))
github linrock / chess-puzzle-maker / test / unit / test_ambiguous.py View on Github external
Cp(203),
            Cp(-72),
            Cp(-97),
        ]))
        self.assertFalse(ambiguous_best_move([
            Cp(-114),
            Cp(85),
            Cp(89),
        ]))
        self.assertFalse(ambiguous_best_move([
            Cp(-101),
            Cp(103),
            Cp(282),
        ]))
        self.assertFalse(ambiguous_best_move([
            Cp(53),
            Cp(-75),
            Cp(-122),
        ]))
github linrock / chess-puzzle-maker / test / unit / test_ambiguous.py View on Github external
def test_not_ambiguous_significant_advantage_vs_slight_advantage(self):
        self.assertFalse(ambiguous_best_move([
            Cp(379),
            Cp(78),
            Cp(77),
        ]))
        self.assertFalse(ambiguous_best_move([
            Cp(365),
            Cp(110),
            Cp(95),
        ]))
        self.assertFalse(ambiguous_best_move([
            Cp(-683),
            Cp(-81),
            Cp(-65),
        ]))
github linrock / chess-puzzle-maker / test / unit / test_should_investigate.py View on Github external
def test_investigating_major_advantage_to_major_disadvantage(self):
        a = Cp(700)
        b = Cp(-700)
        self.assertTrue(should_investigate(a, b, board))

        a = Cp(-700)
        b = Cp(700)
        self.assertTrue(should_investigate(a, b, board))
github linrock / chess-puzzle-maker / test / unit / test_should_investigate.py View on Github external
def test_not_investigating_insignificant_score_changes(self):
        score_changes = [
            [0, 0],
            [-50, 50],
            [50, -50],
            [-70, -70],
            [70, 70],
        ]
        for a, b in score_changes:
            a = Cp(a)
            b = Cp(b)
            self.assertFalse(should_investigate(a, b, board))
github linrock / chess-puzzle-maker / test / unit / test_ambiguous.py View on Github external
def test_ambiguous_significant_advantages(self):
        self.assertTrue(ambiguous_best_move([
            Cp(767),
            Cp(758),
            Cp(177),
        ]))
        self.assertTrue(ambiguous_best_move([
            Cp(552),
            Cp(505),
            Cp(443),
        ]))
        self.assertTrue(ambiguous_best_move([
            Cp(408),
            Cp(224),
            Cp(219),
        ]))
        self.assertTrue(ambiguous_best_move([
            Cp(254),
            Cp(254),
            Cp(240),
        ]))
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 niklasf / python-chess / chess / engine.py View on Github external
info["time"] = int(tokens.pop(0)) / 1000.0
            except (ValueError, IndexError):
                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"] = {}
github niklasf / python-chess / chess / engine.py View on Github external
# 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)

    # Principal variation.

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 1 month ago

Package Health Score

82 / 100
Full package analysis