Esempio n. 1
0
class EngineTests(unittest.TestCase):
    def setUp(self):
        self.engine = PyChessCECP()

    @patch('sys.stdout', new_callable=StringIO)
    @patch('pychess.Players.PyChessCECP.get_input', new=MagicMock(side_effect=["protover 2", "stop_unittest"]))
    def test1(self, mock_stdout):
        """ Send 'protover 2' to PyChess engine """

        self.engine.run()
        output = mock_stdout.getvalue()

        self.assertTrue(output.endswith("feature done=1\n"))

    @patch('sys.stdout', new_callable=StringIO)
    @patch('pychess.Players.PyChessCECP.get_input', new=MagicMock(side_effect=["perft", "stop_unittest"]))
    def test2(self, mock_stdout):
        """ Send 'perft' to PyChess engine """

        self.engine.run()
        output = mock_stdout.getvalue()

        self.assertTrue(output.endswith("nps\n"))

    @patch('sys.stdout', new_callable=StringIO)
    @patch('pychess.Players.PyChessCECP.get_input', new=MagicMock(side_effect=["benchmark 2", "stop_unittest"]))
    def test3(self, mock_stdout):
        """ Send 'benchmark 2' to PyChess engine """

        self.engine.run()
        output = mock_stdout.getvalue()

        self.assertTrue(output.endswith("n/s\n"))
Esempio n. 2
0
class EngineTests(unittest.TestCase):
    def setUp(self):
        self.engine = PyChessCECP()

    @patch('sys.stdout', new_callable=StringIO)
    @patch('pychess.Players.PyChessCECP.get_input',
           new=MagicMock(side_effect=["protover 2", "stop_unittest"]))
    def test1(self, mock_stdout):
        """ Send 'protover 2' to PyChess engine """

        self.engine.run()
        output = mock_stdout.getvalue()

        self.assertTrue(output.endswith("feature done=1\n"))

    @patch('sys.stdout', new_callable=StringIO)
    @patch('pychess.Players.PyChessCECP.get_input',
           new=MagicMock(side_effect=["perft", "stop_unittest"]))
    def test2(self, mock_stdout):
        """ Send 'perft' to PyChess engine """

        self.engine.run()
        output = mock_stdout.getvalue()

        self.assertTrue(output.endswith("nps\n"))

    @patch('sys.stdout', new_callable=StringIO)
    @patch('pychess.Players.PyChessCECP.get_input',
           new=MagicMock(side_effect=["benchmark 2", "stop_unittest"]))
    def test3(self, mock_stdout):
        """ Send 'benchmark 2' to PyChess engine """

        self.engine.run()
        output = mock_stdout.getvalue()

        self.assertTrue(output.endswith("n/s\n"))
Esempio n. 3
0
        for depth in range(1, self.sd):
            if not lsearch.searching:
                break
            board = self.board.clone()
            mvs, scr = alphaBeta(board, depth)

            pv1 = " ".join(listToSan(board, mvs))
            time_cs = int(100 * (time() - start))
            print("%s %s %s %s %s" % (depth, scr, time_cs, lsearch.nodes, pv1))

            lsearch.nodes = 0


if __name__ == "__main__":
    import logging
    from pychess.Players.PyChessCECP import PyChessCECP
    if len(sys.argv) == 1 or sys.argv[1:] == ["debug"]:
        if "debug" in sys.argv[1:]:
            log.logger.setLevel(logging.DEBUG)
        else:
            log.logger.setLevel(logging.WARNING)

        pychess = PyChessCECP()
    else:
        print("Unknown argument(s):", repr(sys.argv))
        sys.exit(0)

    pychess.makeReady()
    pychess.run()
Esempio n. 4
0
        for depth in range(1, self.sd):
            if not lsearch.searching:
                break
            board = self.board.clone()
            mvs, scr = alphaBeta(board, depth)

            pv1 = " ".join(listToSan(board, mvs))
            time_cs = int(100 * (time() - start))
            self.print("%s %s %s %s %s" % (depth, scr, time_cs, lsearch.nodes, pv1))

            lsearch.nodes = 0


if __name__ == "__main__":
    import logging
    from pychess.Players.PyChessCECP import PyChessCECP
    if len(sys.argv) == 1 or sys.argv[1:] == ["debug"]:
        if "debug" in sys.argv[1:]:
            log.logger.setLevel(logging.DEBUG)
        else:
            log.logger.setLevel(logging.WARNING)

        pychess = PyChessCECP()
    else:
        print("Unknown argument(s):", repr(sys.argv))
        sys.exit(0)

    pychess.makeReady()
    pychess.run()