Пример #1
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
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 players 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#
    #.   # #    # .   # ##           #
    #.#    #  .    #    .  # #########
    # ## # ## ####    # ##.   . .   .#
    #.. .  .  #. . #. #  # ## #####  #
    # ## #### #.## #     #  .  . . ..#
    #..  ..   # #  #  #    ##### #####
    ##### #####    #  #  # #   ..  ..#
Пример #2
0
    #.. .  .  #. . #. #  # ## #####  #
    # ## #### #.## #     #  .  . . ..#
    #..  ..   # #  #  #    ##### #####
    ##### #####    #  #  # #   ..  ..#
    #.. . .  .  #     # ##.# #### ## #
    #  ##### ## #  # .# . .#  .  . ..#
    #.   . .   .## #    #### ## # ## #
    ######### #  .    #    .  #    #.#
    #           ## #   . #    # #   .#
    #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)

Пример #3
0
"""
We start a client using the SimpleClient class and
a couple of previously defined Players.
"""

from pelita.simplesetup import SimpleClient
from pelita.player import SimpleTeam
from players import BFSPlayer, BasicDefensePlayer

# Set up our team named ‘the good ones’ using a
# BFSPlayer and a NQRandomPlayer.
client = SimpleClient(SimpleTeam("the good ones", BFSPlayer(),
                                 BasicDefensePlayer()),
                      address="tcp://localhost:50210")

# Now, we just start the client.
# This method will only return, if the client is interrupted or closes.
client.run()
Пример #4
0
from pelita.player import SimpleTeam
from players 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()
Пример #5
0
#!/usr/bin/python
from pelita.game_master import GameMaster
from pelita.player import StoppingPlayer, SimpleTeam
from pelita.viewer import AsciiViewer
from players import BFSPlayer

if __name__ == '__main__':
    layout = (""" ##################
            #0#.  .  # .     #
            # #####    ##### #
            #     . #  .  .#1#
            ################## """)
    gm = GameMaster(layout, 2, 200)
    gm.register_team(SimpleTeam(BFSPlayer()))
    gm.register_team(SimpleTeam(StoppingPlayer()))
    gm.register_viewer(AsciiViewer())
    gm.play()