Beispiel #1
0
 def _make_engine(self):
     self.engine = gtp_engine.Gtp_engine_protocol()
     self.engine.add_commands(self._make_back_end_handlers())
     self.engine.add_protocol_commands()
     self.engine.add_commands({
         'quit': self.handle_quit,
         'gomill-passthrough': self.handle_passthrough,
     })
Beispiel #2
0
def make_engine(player):
    """Return a Gtp_engine_protocol which runs the specified player."""
    gtp_state = gtp_states.Gtp_state(move_generator=player.genmove)

    engine = gtp_engine.Gtp_engine_protocol()
    engine.add_protocol_commands()
    engine.add_commands(gtp_state.get_handlers())
    engine.add_commands(player.get_handlers())
    return engine
Beispiel #3
0
 def __init__(self, tc):
     self.tc = tc
     self.player = gtp_state_test_support.Player()
     self.gtp_state = gtp_state_test_support.Testing_gtp_state(
         move_generator=self.player.genmove,
         acceptable_sizes=(9, 11, 13, 19))
     self.engine = gtp_engine.Gtp_engine_protocol()
     self.engine.add_protocol_commands()
     self.engine.add_commands(self.gtp_state.get_handlers())
     self.tc.addTypeEqualityFunc(gtp_states.History_move,
                                 self.assertHistoryMoveEqual)
def test_run_gtp_session(tc):
    engine = gtp_engine.Gtp_engine_protocol()
    engine.add_protocol_commands()

    stream = "known_command list_commands\nxyzzy\nquit\n"
    command_pipe = test_support.Mock_reading_pipe(stream)
    response_pipe = test_support.Mock_writing_pipe()
    gtp_engine.run_gtp_session(engine, command_pipe, response_pipe)
    tc.assertMultiLineEqual(response_pipe.getvalue(),
                            "= true\n\n? unknown command\n\n=\n\n")
    command_pipe.close()
    response_pipe.close()
def test_engine(tc):
    def handle_test(args):
        if args:
            return "args: " + " ".join(args)
        else:
            return "test response"

    engine = gtp_engine.Gtp_engine_protocol()
    engine.add_protocol_commands()
    engine.add_command('test', handle_test)

    check_engine = gtp_engine_test_support.check_engine
    check_engine(tc, engine, 'test', ['ab', 'cd'], "args: ab cd")
def test_run_gtp_session_broken_pipe(tc):
    def break_pipe(args):
        response_pipe.simulate_broken_pipe()

    engine = gtp_engine.Gtp_engine_protocol()
    engine.add_protocol_commands()
    engine.add_command("break", break_pipe)

    stream = "known_command list_commands\nbreak\nquit\n"
    command_pipe = test_support.Mock_reading_pipe(stream)
    response_pipe = test_support.Mock_writing_pipe()
    with tc.assertRaises(gtp_engine.ControllerDisconnected) as ar:
        gtp_engine.run_gtp_session(engine, command_pipe, response_pipe)
    command_pipe.close()
    response_pipe.close()
Beispiel #7
0
def run_engine(args):
    if "sigpipe" in args:
        signal.signal(signal.SIGPIPE, signal.SIG_DFL)

    def handle_wait(args):
        time.sleep(1)
        return "done waiting"

    engine = gtp_engine.Gtp_engine_protocol()
    engine.add_protocol_commands()
    engine.add_command('wait', handle_wait)
    if "silent" in args:
        try:
            gtp_engine.run_interactive_gtp_session(engine)
        except gtp_engine.ControllerDisconnected:
            print >> sys.stderr, "[controller disconnected]"
            sys.exit(3)
    else:
        gtp_engine.run_interactive_gtp_session(engine)