當前位置: 首頁>>代碼示例>>Python>>正文


Python simplesetup.SimpleServer類代碼示例

本文整理匯總了Python中pelita.simplesetup.SimpleServer的典型用法代碼示例。如果您正苦於以下問題:Python SimpleServer類的具體用法?Python SimpleServer怎麽用?Python SimpleServer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了SimpleServer類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_simple_failing_bots

    def test_simple_failing_bots(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")

        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()
開發者ID:ASPP,項目名稱:pelita,代碼行數:30,代碼來源:test_simplesetup.py

示例2: test_failing_bots_do_not_crash_server

    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

        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
開發者ID:ASPP,項目名稱:pelita,代碼行數:33,代碼來源:test_simplesetup.py

示例3: test_simple_game

    def test_simple_game(self):
        layout = """
        ##########
        #        #
        #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:
            self.assertTrue(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()
開發者ID:nwilbert,項目名稱:pelita,代碼行數:30,代碼來源:test_simplesetup.py

示例4: test_simple_remote_game

    def test_simple_remote_game(self):
        layout = """
        ##########
        #        #
        #0      1#
        ##########
        """
        client1 = SimpleClient(SimpleTeam("team1", RandomPlayer()), local=False)
        client2 = SimpleClient(SimpleTeam("team2", RandomPlayer()), local=False)
        server = SimpleServer(layout_string=layout, rounds=5, players=2, local=False)

        self.assertEqual(server.host, "")
        self.assertEqual(server.port, 50007)
        self.assertTrue(server.server.is_alive)

        client1.autoplay_background()
        client2.autoplay_background()
        server.run_simple(AsciiViewer)

        self.assertFalse(server.server.is_alive)
開發者ID:FrancescAlted,項目名稱:pelita,代碼行數:20,代碼來源:test_simplesetup.py

示例5: test_simple_remote_game

    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("^<<v>")), address=client2_address)

        client1.autoplay_process()
        client2.autoplay_process()
        server.run()
        server.shutdown()
開發者ID:ASPP,項目名稱:pelita,代碼行數:22,代碼來源:test_simplesetup.py

示例6: SimpleServer

    # ## # ## ####    # ##.   . .   .#
    #.. .  .  #. . #. #  # ## #####  #
    # ## #### #.## #     #  .  . . ..#
    #..  ..   # #  #  #    ##### #####
    ##### #####    #  #  # #   ..  ..#
    #.. . .  .  #     # ##.# #### ## #
    #  ##### ## #  # .# . .#  .  . ..#
    #.   . .   .## #    #### ## # ## #
    ######### #  .    #    .  #    #.#
    #           ## #   . #    # #   .#
    #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)
開發者ID:ASPP,項目名稱:pelita,代碼行數:30,代碼來源:demo_simplegame.py

示例7: RuntimeError

    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()
開發者ID:NelleV,項目名稱:pelita,代碼行數:31,代碼來源:demo_server_game.py

示例8: test_remote_game

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,
                          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

    # terminate processes
    [p.terminate() for p in remote_procs]
    for p in remote_procs:
        assert p.wait(2) is not None
開發者ID:ASPP,項目名稱:pelita,代碼行數:41,代碼來源:test_pelitagame.py

示例9: SimpleServer

# -*- coding: utf-8 -*-

"""
We start a server using the SimpleServer class and a layout
given by the specified layout file.
"""

from pelita.simplesetup import SimpleServer

server = SimpleServer(layoutfile="layouts/02.layout")
# For more control, we could also define a game with 8 Bots,
# run 10000 rounds and want to receive connections on port
#
# server = SimpleServer(layoutfile="layouts/02.layout", players=8, rounds=10000, port=61009)

# Now we run it with a Tk interface.
# This will only ever return if interrupted or if Tk is closed.
server.run_tk()

開發者ID:holdensmagicalunicorn,項目名稱:pelita,代碼行數:18,代碼來源:demo_simpleserver.py


注:本文中的pelita.simplesetup.SimpleServer類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。