How to use the pelita.simplesetup.SimpleServer function in pelita

To help you get started, we’ve selected a few pelita 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 ASPP / pelita / demo / demo_simplegame.py View on Github external
# ## # ## ####    # ##.   . .   .#
    #.. .  .  #. . #. #  # ## #####  #
    # ## #### #.## #     #  .  . . ..#
    #..  ..   # #  #  #    ##### #####
    ##### #####    #  #  # #   ..  ..#
    #.. . .  .  #     # ##.# #### ## #
    #  ##### ## #  # .# . .#  .  . ..#
    #.   . .   .## #    #### ## # ## #
    ######### #  .    #    .  #    #.#
    #           ## #   . #    # #   .#
    #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)
github ASPP / pelita / test / test_simplesetup.py View on Github external
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("^<")), address=client2_address)

        client1.autoplay_process()
        client2.autoplay_process()
        server.run()
        server.shutdown()
github ASPP / pelita / test / test_simplesetup.py View on Github external
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
github ASPP / pelita / test / test_pelitagame.py View on Github external
def test_remote_game():
    remote = [libpelita.get_python_process(), '-m', 'pelita.scripts.pelita_player', '--remote']
    remote_stopping = remote + ['pelita/player/StoppingPlayer', 'tcp://127.0.0.1:52301']
    remote_food_eater = remote + ['pelita/player/FoodEatingPlayer', 'tcp://127.0.0.1:52302']

    remote_procs = [Popen_autokill(args) for args in [remote_stopping, remote_food_eater]]

    layout = """
        ##########
        #        #
        #0  ..  1#
        ##########
        """
    server = SimpleServer(layout_string=layout, rounds=5, players=2,
                          bind_addrs=['remote:tcp://127.0.0.1:52301', 'remote:tcp://127.0.0.1:52302'])

    server.run()
    server.shutdown()

    assert server.game_master.game_state['team_wins'] == 1

    server = SimpleServer(layout_string=layout, rounds=5, players=2,
                          bind_addrs=['remote:tcp://127.0.0.1:52302', 'remote:tcp://127.0.0.1:52301'])

    server.run()
    server.shutdown()

    assert server.game_master.game_state['team_wins'] == 0

    server = SimpleServer(layout_string=layout, rounds=5, players=2,
github ASPP / pelita / pelitagame.py View on Github external
if args.layout == 'list':
        layouts = pelita.layout.get_available_layouts()
        print '\n'.join(layouts)
        sys.exit(0)

    if 'list' in (args.bad_team, args.good_team):
        print '\n'.join(PLAYERS)
        sys.exit(0)

    bads = load_team(args.bad_team)
    goods = load_team(args.good_team)

    for team in (bads, goods):
        client = pelita.simplesetup.SimpleClient(team)
        client.autoplay_background()
    server = pelita.simplesetup.SimpleServer(layout_file=args.layoutfile,
                                             layout_name=args.layout,
                                             rounds=args.rounds,
                                             )

    if args.viewer in 'tk':
        server.run_tk(geometry=args.geometry)
    elif args.viewer == 'ascii':
        server.run_simple(pelita.viewer.AsciiViewer)
    elif args.viewer == 'null':
        server.run_simple(pelita.viewer.DevNullViewer)
    else:
        assert 0
github ASPP / pelita / demo / demo_server_game.py View on Github external
py_proc = sys.executable
    if not py_proc:
        raise RuntimeError("Cannot retrieve current Python executable.")
    return py_proc

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.INFO)

layout = (
        """ ##################
            #0#.  . 2# .   3 #
            # #####    ##### #
            #     . #  .  .#1#
            ################## """)

server = SimpleServer(layout_string=layout, rounds=200, bind_addrs=("tcp://*:50007", "tcp://*:50008"))

publisher = SimplePublisher("tcp://*:50012")
server.game_master.register_viewer(publisher)

subscribe_sock = server
tk_open = "TkViewer(%r, %r).run()" % ("tcp://localhost:50012", "tcp://localhost:50013")
tkprocess = subprocess.Popen([get_python_process(),
                              "-c",
                              "from pelita.ui.tk_viewer import TkViewer\n" + tk_open])

try:
    print(server.bind_addresses)
    server.register_teams()
    controller = SimpleController(server.game_master, "tcp://*:50013")
    controller.run()
    server.exit_teams()
github ASPP / pelita / doc / source / my_player / my_game.py View on Github external
from pelita.simplesetup import SimpleClient, SimpleServer
from pelita.player import SimpleTeam, BFSPlayer, BasicDefensePlayer
from my_player import MyPlayer

# setup you own team
my_client = SimpleClient(
        SimpleTeam("my team", MyPlayer(), MyPlayer()))
my_client.autoplay_background()

# fight against two strong opponents
enemy_team = SimpleClient(
        SimpleTeam("the enemy", BFSPlayer(), BasicDefensePlayer()))
enemy_team.autoplay_background()

server = SimpleServer()
server.run_tk()
github ASPP / pelita / demo / demo.py View on Github external
cases, pressing CTRL+Z and then entering ‘kill %%’ usually is the way to get rid
of the program. """

from pelita.simplesetup import SimpleClient, SimpleServer
from pelita.player import RandomPlayer, NQRandomPlayer,\
    BFSPlayer, BasicDefensePlayer, SimpleTeam

client = SimpleClient(
        SimpleTeam("the good ones", RandomPlayer(), NQRandomPlayer()))
client.autoplay_background()

client2 = SimpleClient(
        SimpleTeam("the bad ones", BFSPlayer(), BasicDefensePlayer()))
client2.autoplay_background()

server = SimpleServer()
server.run_tk()