How to use the pelita.simplesetup.SimpleClient 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 / test / test_simplesetup.py View on Github external
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
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()
github ASPP / pelita / test / test_simplesetup.py View on Github external
#        #
        #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()
github ASPP / pelita / test / test_simplesetup.py View on Github external
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
github ASPP / pelita / pelitagame.py View on Github external
args = parser.parse_args(argv)

    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_simplelocalgame.py View on Github external
#!/usr/bin/env python3

"""
This file demonstrates setting up a server and two clients using local connections.
"""

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

client = SimpleClient(SimpleTeam("the good ones", NQRandomPlayer(), BFSPlayer()), address="ipc:///tmp/pelita-client1")
client.autoplay_process()

client2 = SimpleClient(SimpleTeam("the bad ones", BFSPlayer(), BasicDefensePlayer()), address="ipc:///tmp/pelita-client2")
client2.autoplay_process()

layout = """
    ##################################
    #...   #      .#     #  #       3#
    # ## #   # ###    #  #     #####1#
    #.   # #    # .   # ##           #
    #.#    #  .    #    .  # #########
    # ## # ## ####    # ##.   . .   .#
    #.. .  .  #. . #. #  # ## #####  #
    # ## #### #.## #     #  .  . . ..#
    #..  ..   # #  #  #    ##### #####
    ##### #####    #  #  # #   ..  ..#
    #.. . .  .  #     # ##.# #### ## #
    #  ##### ## #  # .# . .#  .  . ..#
    #.   . .   .## #    #### ## # ## #
github ASPP / pelita / demo / demo_simplelocalgame.py View on Github external
#!/usr/bin/env python3

"""
This file demonstrates setting up a server and two clients using local connections.
"""

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

client = SimpleClient(SimpleTeam("the good ones", NQRandomPlayer(), BFSPlayer()), address="ipc:///tmp/pelita-client1")
client.autoplay_process()

client2 = SimpleClient(SimpleTeam("the bad ones", BFSPlayer(), BasicDefensePlayer()), address="ipc:///tmp/pelita-client2")
client2.autoplay_process()

layout = """
    ##################################
    #...   #      .#     #  #       3#
    # ## #   # ###    #  #     #####1#
    #.   # #    # .   # ##           #
    #.#    #  .    #    .  # #########
    # ## # ## ####    # ##.   . .   .#
    #.. .  .  #. . #. #  # ## #####  #
    # ## #### #.## #     #  .  . . ..#
    #..  ..   # #  #  #    ##### #####
    ##### #####    #  #  # #   ..  ..#
github ASPP / pelita / demo / demo.py View on Github external
A difference to the remote game in demo_simplegame is that now,
`client.autoplay_background` uses a background thread instead of a background
process. This background thread sometimes does not close on CTRL+C. In these
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()
github ASPP / pelita / demo / demo_client_game.py View on Github external
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()
github ASPP / pelita / doc / source / my_player / my_game.py View on Github external
#!/usr/bin/env python
# -*- coding: utf-8 -*-

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()