Exemple #1
0
 def test_controller_protocol1(self):
     eng = MockEngine(protocol1)
     ctl = EngineController(eng)
     self.assertEqual(ctl.ident["name"], "Mock")
     self.assertEqual(ctl.ident["author"], "Janzert")
     self.assertEqual(ctl.protocol_version, 1)
     self.assertEqual(ctl.is_running(), True)
     resp = ctl.get_response()
     self.assertIsInstance(resp, EngineResponse)
     self.assertEqual(resp.type, "log")
     self.assertEqual(resp.message,
                      eng.expected[eng.event - 1][1].lstrip("log "))
     ctl.setoption("depth", 4)
     ctl.newgame()
     pos = board.Position(board.Color.GOLD, 4, board.BASIC_SETUP)
     ctl.setposition(pos)
     ctl.go()
     ctl.stop()
     resp = ctl.get_response()
     self.assertEqual(resp.type, "info")
     self.assertEqual(resp.message,
                      eng.expected[eng.event - 1][1].lstrip("info "))
     resp = ctl.get_response()
     self.assertEqual(resp.type, "bestmove")
     self.assertEqual(resp.move,
                      eng.expected[eng.event - 1][1].lstrip("bestmove "))
     ctl.makemove("Hb2n Ed2n")
     ctl.go("ponder")
     ctl.quit()
     ctl.cleanup()
Exemple #2
0
 def test_controller_protocol1(self):
     eng = MockEngine(protocol1)
     ctl = EngineController(eng)
     self.assertEqual(ctl.ident["name"], "Mock")
     self.assertEqual(ctl.ident["author"], "Janzert")
     self.assertEqual(ctl.protocol_version, 1)
     self.assertEqual(ctl.is_running(), True)
     resp = ctl.get_response()
     self.assertIsInstance(resp, EngineResponse)
     self.assertEqual(resp.type, "log")
     self.assertEqual(resp.message,
                      eng.expected[eng.event - 1][1].lstrip("log "))
     ctl.setoption("depth", 4)
     ctl.newgame()
     pos = board.Position(board.Color.GOLD, 4, board.BASIC_SETUP)
     ctl.setposition(pos)
     ctl.go()
     ctl.stop()
     resp = ctl.get_response()
     self.assertEqual(resp.type, "info")
     self.assertEqual(resp.message,
                      eng.expected[eng.event - 1][1].lstrip("info "))
     resp = ctl.get_response()
     self.assertEqual(resp.type, "bestmove")
     self.assertEqual(resp.move,
                      eng.expected[eng.event - 1][1].lstrip("bestmove "))
     ctl.makemove("Hb2n Ed2n")
     ctl.go("ponder")
     ctl.quit()
     ctl.cleanup()
Exemple #3
0
 def test_controller(self):
     eng = MockEngine(protocol1)
     ctl = EngineController(eng)
     self.assertEqual(ctl.ident["name"], "Mock")
     self.assertEqual(ctl.ident["author"], "Janzert")
     self.assertEqual(ctl.protocol_version, 1)
     self.assertEqual(ctl.is_running(), True)
     self.assertRaises(socket.timeout, ctl.get_response)
     resp = ctl.get_response()
     self.assertIsInstance(resp, EngineResponse)
     self.assertEqual(resp.type, "log")
     self.assertEqual(resp.message,
                      eng.expected[eng.event - 1][1].lstrip("log "))
     ctl.setoption("depth", 4)
     ctl.newgame()
     pos = board.Position(board.Color.GOLD, 4, board.BASIC_SETUP)
     ctl.setposition(pos)
     ctl.go()
     ctl.stop()
     resp = ctl.get_response()
     self.assertEqual(resp.type, "info")
     self.assertEqual(resp.message,
                      eng.expected[eng.event - 1][1].lstrip("info "))
     resp = ctl.get_response()
     self.assertEqual(resp.type, "bestmove")
     self.assertEqual(resp.move,
                      eng.expected[eng.event - 1][1].lstrip("bestmove "))
     ctl.makemove("Hb2n Ed2n")
     ctl.go("ponder")
     ctl.quit()
     ctl.cleanup()
     # bad response to isready
     eng = MockEngine(bad_isready_response)
     ctl = EngineController(eng)
     ctl.newgame()
     self.assertRaises(EngineException, ctl.isready)
     # timeout waiting for aeiok
     eng = MockEngine(aeiok_timeout)
     self.assertRaises(EngineException, EngineController, eng)
     # IOError sending aei
     eng = MockEngine(aei_send_error)
     self.assertRaises(EngineException, EngineController, eng)
Exemple #4
0
 def test_controller(self):
     eng = MockEngine(protocol1)
     ctl = EngineController(eng)
     self.assertEqual(ctl.ident["name"], "Mock")
     self.assertEqual(ctl.ident["author"], "Janzert")
     self.assertEqual(ctl.protocol_version, 1)
     self.assertEqual(ctl.is_running(), True)
     self.assertRaises(socket.timeout, ctl.get_response)
     resp = ctl.get_response()
     self.assertIsInstance(resp, EngineResponse)
     self.assertEqual(resp.type, "log")
     self.assertEqual(resp.message,
                      eng.expected[eng.event - 1][1].lstrip("log "))
     ctl.setoption("depth", 4)
     ctl.newgame()
     pos = board.Position(board.Color.GOLD, 4, board.BASIC_SETUP)
     ctl.setposition(pos)
     ctl.go()
     ctl.stop()
     resp = ctl.get_response()
     self.assertEqual(resp.type, "info")
     self.assertEqual(resp.message,
                      eng.expected[eng.event - 1][1].lstrip("info "))
     resp = ctl.get_response()
     self.assertEqual(resp.type, "bestmove")
     self.assertEqual(resp.move,
                      eng.expected[eng.event - 1][1].lstrip("bestmove "))
     ctl.makemove("Hb2n Ed2n")
     ctl.go("ponder")
     ctl.quit()
     ctl.cleanup()
     # bad response to isready
     eng = MockEngine(bad_isready_response)
     ctl = EngineController(eng)
     ctl.newgame()
     self.assertRaises(EngineException, ctl.isready)
     # timeout waiting for aeiok
     eng = MockEngine(aeiok_timeout)
     self.assertRaises(EngineException, EngineController, eng)
     # IOError sending aei
     eng = MockEngine(aei_send_error)
     self.assertRaises(EngineException, EngineController, eng)
Exemple #5
0
 def test_protocol_versions(self):
     eng = MockEngine(protocol0)
     ctl = EngineController(eng)
     self.assertEqual(ctl.ident["name"], "Mock0")
     self.assertEqual(ctl.ident["author"], "Janzert")
     self.assertEqual(ctl.protocol_version, 0)
     ctl.newgame()
     pos = board.Position(board.Color.GOLD, 4, board.BASIC_SETUP)
     ctl.setposition(pos)
     ctl.cleanup()
     # bad protocol version
     eng = MockEngine(bad_protocol)
     eng.log = MockLog()
     ctl = EngineController(eng)
     self.assertIn("Unrecognized protocol version", eng.log.warning)
     pos = board.Position(board.Color.GOLD, 4, board.BASIC_SETUP)
     ctl.newgame()
     ctl.setposition(pos)
     ctl.go()
     ctl.stop()
     ctl.quit()
Exemple #6
0
 def test_protocol_versions(self):
     eng = MockEngine(protocol0)
     ctl = EngineController(eng)
     self.assertEqual(ctl.ident["name"], "Mock0")
     self.assertEqual(ctl.ident["author"], "Janzert")
     self.assertEqual(ctl.protocol_version, 0)
     ctl.newgame()
     pos = board.Position(board.Color.GOLD, 4, board.BASIC_SETUP)
     ctl.setposition(pos)
     ctl.cleanup()
     # bad protocol version
     eng = MockEngine(bad_protocol)
     eng.log = MockLog()
     ctl = EngineController(eng)
     self.assertIn("Unrecognized protocol version", eng.log.warning)
     pos = board.Position(board.Color.GOLD, 4, board.BASIC_SETUP)
     ctl.newgame()
     ctl.setposition(pos)
     ctl.go()
     ctl.stop()
     ctl.quit()
Exemple #7
0
        move = move[3:]
        pos = pos.do_move_str(move)
        eng.makemove(move)
print pos.board_to_str()

for option in config.options(bot_section):
    if option.startswith("post_pos_"):
        value = config.get(bot_section, option)
        eng.setoption(option[9:], value)

search_position = True
if config.has_option("global", "search_position"):
    sp_str = config.get("global", "search_position")
    search_position = not (sp_str.lower() in ["false", "0", "no"])
if search_position:
    eng.go()

while True:
    try:
        resp = eng.get_response(10)
        if resp.type == "info":
            print resp.message
        elif resp.type == "log":
            print "log: %s" % resp.message
        elif resp.type == "bestmove":
            print "bestmove: %s" % resp.move
            break
    except socket.timeout:
        if not search_position:
            break
Exemple #8
0
        move = move[3:]
        pos = pos.do_move_str(move)
        eng.makemove(move)
print pos.board_to_str()

for option in config.options(bot_section):
    if option.startswith("post_pos_"):
        value = config.get(bot_section, option)
        eng.setoption(option[9:], value)

search_position = True
if config.has_option("global", "search_position"):
    sp_str = config.get("global", "search_position")
    search_position = not (sp_str.lower() in ["false", "0", "no"])
if search_position:
    eng.go()

while True:
    try:
        resp = eng.get_response(10)
        if resp.type == "info":
            print resp.message
        elif resp.type == "log":
            print "log: %s" % resp.message
        elif resp.type == "bestmove":
            print "bestmove: %s" % resp.move
            break
    except socket.timeout:
        if not search_position:
            break