How to use the pelita.player.BFSPlayer 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 / 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 / demo / demo_local_actor.py View on Github external
################## """)

# Notify the ServerActor that we’d like to run a game
# with our preferred layout, 4 bots and 200 rounds.
server.notify("initialize_game", [layout, 4, 200])

# Initialise a TkViewer and register it with the ServerActor.
viewer = TkViewer()
server.notify("register_viewer", [viewer])

# Our two PlayerTeams must be defined in the same Python
# process (because this is local game).
# Create their ClientActors, register the Teams, and connect
# to the ServerActor.
clientActor = ClientActor("the good ones")
clientActor.register_team(SimpleTeam(BFSPlayer(), BFSPlayer()))
clientActor.connect_local("pelita-main")

clientActor2 = ClientActor("the bad ones")
clientActor2.register_team(SimpleTeam(RandomPlayer(), RandomPlayer()))
clientActor2.connect_local("pelita-main")

# Now follows the boilerplate which is needed to run the game.
# As this uses a TkViewer, we need to give Tk the control
# over our main thread.
# Since everything else runs in threaded actors, this is not
# much of a problem. The queue needed to exchange data between
# different threads is handled by our TkViewer.
try:
    viewer.root.mainloop()
except KeyboardInterrupt:
    print "Received CTRL+C. Exiting."
github ASPP / pelita / demo / demo_bfs.py View on Github external
#!/usr/bin/env python3
from pelita.game_master import GameMaster
from pelita.player import StoppingPlayer, SimpleTeam
from pelita.viewer import AsciiViewer
from pelita.player 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()
github ASPP / pelita / demo / demo_defensive.py View on Github external
#!/usr/bin/env python3
from pelita.game_master import GameMaster
from pelita.player import SimpleTeam, StoppingPlayer
from pelita.viewer import AsciiViewer
from pelita.layout import get_random_layout
from pelita.player import BFSPlayer, BasicDefensePlayer

if __name__ == '__main__':
    name, layout = get_random_layout()
    gm = GameMaster(layout, 4, 200)
    gm.register_team(SimpleTeam(BFSPlayer(), BFSPlayer()))
    gm.register_team(SimpleTeam(BasicDefensePlayer(), BasicDefensePlayer()))
    gm.register_viewer(AsciiViewer())
    gm.play()
github ASPP / pelita / demo / demo_simpleclient.py View on Github external
"""
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 pelita.player 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()
github ASPP / pelita / demo / demo_client_game.py View on Github external
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()
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()