Exemple #1
0
 def test_demo_players(self):
     test_layout = (""" ############
         #0#.   .# 1#
         ############ """)
     team = [SimpleTeam(NQRandomPlayer()), SimpleTeam(NQRandomPlayer())]
     gm = GameMaster(test_layout, team, 2, 1)
     gm.play()
     self.assertEqual(gm.universe.bots[0].current_pos, (1, 1))
     self.assertEqual(gm.universe.bots[1].current_pos, (9, 1))
Exemple #2
0
 def test_path(self):
     test_layout = (""" ############
         #  . # .# ##
         # ## #  # ##
         #0#.   .##1#
         ############ """)
     team = [SimpleTeam(NQRandomPlayer()), SimpleTeam(NQRandomPlayer())]
     gm = GameMaster(test_layout, team, 2, 7)
     gm.play()
     self.assertEqual(gm.universe.bots[0].current_pos, (4, 3))
     self.assertEqual(gm.universe.bots[1].current_pos, (10, 3))
#!/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#
    #.   # #    # .   # ##           #
    #.#    #  .    #    .  # #########
    # ## # ## ####    # ##.   . .   .#
    #.. .  .  #. . #. #  # ## #####  #
    # ## #### #.## #     #  .  . . ..#
    #..  ..   # #  #  #    ##### #####
    ##### #####    #  #  # #   ..  ..#
Exemple #4
0
#!/usr/bin/python
from pelita.game_master import GameMaster
from pelita.player import StoppingPlayer, SimpleTeam
from pelita.viewer import AsciiViewer
from players import RandomPlayer, NQRandomPlayer

if __name__ == '__main__':
    layout = (""" ##################
            #0#.  .  # .     #
            #2#####    #####1#
            #     . #  .  .#3#
            ################## """)
    gm = GameMaster(layout, 4, 200)
    gm.register_team(SimpleTeam(StoppingPlayer(), NQRandomPlayer()))
    gm.register_team(SimpleTeam(NQRandomPlayer(), NQRandomPlayer()))
    gm.register_viewer(AsciiViewer())
    gm.play()
Exemple #5
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)

Exemple #6
0
#!/usr/bin/python
from pelita.game_master import GameMaster
from pelita.player import StoppingPlayer, SimpleTeam
from pelita.viewer import AsciiViewer
from players import RandomPlayer, NQRandomPlayer

if __name__ == '__main__':
    layout = (""" ##################
            #0#.  .  # .     #
            #2#####    #####1#
            #     . #  .  .#3#
            ################## """)
    teams = [
        SimpleTeam(StoppingPlayer(), NQRandomPlayer()),
        SimpleTeam(StoppingPlayer(), NQRandomPlayer())
    ]
    gm = GameMaster(layout, teams, 4, 200)
    gm.register_viewer(AsciiViewer())
    gm.play()