def test_simple_failing_bots(self): layout = """ ########## # # #0 .. 1# ########## """ server = SimpleServer(layout_string=layout, rounds=5, players=2) for bind_address in server.bind_addresses: assert bind_address.startswith("tcp://") client1_address = server.bind_addresses[0].replace("*", "localhost") client2_address = server.bind_addresses[1].replace("*", "localhost") class FailingPlayer: def _set_initial(self, dummy, dummy2): pass def _set_index(self, dummy): pass def _get_move(self, universe, game_state): pass client1 = SimpleClient(SimpleTeam("team1", SteppingPlayer("^>>v<")), address=client1_address) client2 = SimpleClient(SimpleTeam("team2", FailingPlayer()), address=client2_address) client1.autoplay_process() client2.autoplay_process() server.run() server.shutdown()
def test_failing_bots_do_not_crash_server(self): layout = """ ########## # # #0 .. 1# ########## """ server = SimpleServer(layout_string=layout, rounds=5, players=2, timeout_length=0.3) for bind_address in server.bind_addresses: assert bind_address.startswith("tcp://") client1_address = server.bind_addresses[0].replace("*", "localhost") client2_address = server.bind_addresses[1].replace("*", "localhost") class ThisIsAnExpectedException(Exception): pass class FailingPlayer(AbstractPlayer): def get_move(self): raise ThisIsAnExpectedException() old_timeout = pelita.simplesetup.DEAD_CONNECTION_TIMEOUT pelita.simplesetup.DEAD_CONNECTION_TIMEOUT = 0.3 client1 = SimpleClient(SimpleTeam("team1", FailingPlayer()), address=client1_address) client2 = SimpleClient(SimpleTeam("team2", FailingPlayer()), address=client2_address) client1.autoplay_process() client2.autoplay_process() server.run() server.shutdown() pelita.simplesetup.DEAD_CONNECTION_TIMEOUT = old_timeout
def test_simple_game(self): layout = """ ########## # # #0 .. 1# ########## """ server = SimpleServer( layout_string=layout, rounds=5, players=2, bind_addrs=("ipc:///tmp/pelita-testplayer1-%s" % uuid.uuid4(), "ipc:///tmp/pelita-testplayer2-%s" % uuid.uuid4())) for bind_address in server.bind_addresses: assert bind_address.startswith("ipc://") client1_address = server.bind_addresses[0] client2_address = server.bind_addresses[1] client1 = SimpleClient(SimpleTeam("team1", RandomPlayer()), address=client1_address) client2 = SimpleClient(SimpleTeam("team2", RandomPlayer()), address=client2_address) client1.autoplay_process() client2.autoplay_process() server.run() server.shutdown()
def test_simple_game(self): layout = """ ########## # # #0 .. 1# ########## """ server = SimpleServer( layout_string=layout, rounds=5, players=2, bind_addrs=( "ipc:///tmp/pelita-testplayer1-%s" % uuid.uuid4(), "ipc:///tmp/pelita-testplayer2-%s" % uuid.uuid4(), ), ) for bind_address in server.bind_addresses: self.assertTrue(bind_address.startswith("ipc://")) client1_address = server.bind_addresses[0] client2_address = server.bind_addresses[1] client1 = SimpleClient(SimpleTeam("team1", RandomPlayer()), address=client1_address) client2 = SimpleClient(SimpleTeam("team2", RandomPlayer()), address=client2_address) client1.autoplay_process() client2.autoplay_process() server.run() server.shutdown()
def test_failing_bots_do_not_crash_server_in_set_initial(self): layout = """ ########## # # #0 .. 1# ########## """ server = SimpleServer(layout_string=layout, rounds=5, players=2, timeout_length=0.3) for bind_address in server.bind_addresses: assert bind_address.startswith("tcp://") client1_address = server.bind_addresses[0].replace("*", "localhost") client2_address = server.bind_addresses[1].replace("*", "localhost") class ThisIsAnExpectedException(Exception): pass class FailingPlayer(AbstractPlayer): def set_initial(self): raise ThisIsAnExpectedException() def get_move(self): raise ThisIsAnExpectedException() old_timeout = pelita.simplesetup.DEAD_CONNECTION_TIMEOUT pelita.simplesetup.DEAD_CONNECTION_TIMEOUT = 0.3 client1 = SimpleClient(SimpleTeam("team1", FailingPlayer()), address=client1_address) client2 = SimpleClient(SimpleTeam("team2", FailingPlayer()), address=client2_address) client1.autoplay_process() client2.autoplay_process() server.run() server.shutdown() pelita.simplesetup.DEAD_CONNECTION_TIMEOUT = old_timeout
def test_simple_remote_game(self): layout = """ ########## # # #0 .. 1# ########## """ server = SimpleServer(layout_string=layout, rounds=5, players=2) for bind_address in server.bind_addresses: assert bind_address.startswith("tcp://") client1_address = server.bind_addresses[0].replace("*", "localhost") client2_address = server.bind_addresses[1].replace("*", "localhost") client1 = SimpleClient(SimpleTeam("team1", SteppingPlayer("^>>v<")), address=client1_address) client2 = SimpleClient(SimpleTeam("team2", SteppingPlayer("^<<v>")), address=client2_address) client1.autoplay_process() client2.autoplay_process() server.run() server.shutdown()
from pelita.player import SimpleTeam from pelita.player import RandomPlayer, BFSPlayer from pelita.simplesetup import SimpleClient import logging try: import colorama MAGENTA = colorama.Fore.MAGENTA RESET = colorama.Fore.RESET except ImportError: MAGENTA = "" RESET = "" FORMAT = '[%(asctime)s,%(msecs)03d][%(name)s][%(levelname)s][%(funcName)s]' + MAGENTA + ' %(message)s' + RESET #logging.basicConfig(format=FORMAT, datefmt="%H:%M:%S", level=logging.WARNING) team1 = SimpleTeam("the good ones", BFSPlayer(), BFSPlayer()) client1 = SimpleClient(team1, address="tcp://localhost:50007") team2 = SimpleTeam("the bad ones", BFSPlayer(), BFSPlayer()) client2 = SimpleClient(team2, address="tcp://localhost:50008") client1.autoplay_process() client2.autoplay_process()
#.. . . #. . #. # # ## ##### # # ## #### #.## # # . . . ..# #.. .. # # # # ##### ##### ##### ##### # # # # .. ..# #.. . . . # # ##.# #### ## # # ##### ## # # .# . .# . . ..# #. . . .## # #### ## # ## # ######### # . # . # #.# # ## # . # # # .# #0##### # # ### # # ## # #2 # # #. # ...# ################################## """ server = SimpleServer(layout_string=layout, rounds=3000) def star_to_localhost(str): # server might publish to tcp://* in which case we simply try localhost for the clients return str.replace("*", "localhost") client = SimpleClient(SimpleTeam("the good ones", NQRandomPlayer(), BFSPlayer()), address=star_to_localhost(server.bind_addresses[0])) client.autoplay_process() client2 = SimpleClient(SimpleTeam("the bad ones", BFSPlayer(), BasicDefensePlayer()), address=star_to_localhost(server.bind_addresses[1])) client2.autoplay_process() server.run() print(server.game_master.universe.pretty) print(server.game_master.game_state)