Пример #1
0
def main():
    # Parse command-line options into a namespace for use throughout this
    # program
    options = get_options()

    try:
        # Import player classes
        p_R = PlayerWrapper('red',   options.playerR_loc, options)
        p_G = PlayerWrapper('green', options.playerG_loc, options)
        p_B = PlayerWrapper('blue',  options.playerB_loc, options)

        # We'll start measuring space usage from now, after all
        # library imports should be finished:
        set_space_line()

        # Play the game!
        play(p_R, p_G, p_B, options)
    
    # In case the game ends in an abnormal way, print a clean error
    # message for the user (rather than a trace).
    except IllegalActionException as e:
        info("game error", options)
        say("error: invalid action!")
        if options.verbosity > 0:
            say(e)
    except ResourceLimitException as e:
        info("game error", options)
        say("error: resource limit exceeded!")
        if options.verbosity > 0:
            say(e)
Пример #2
0
def main():
    # Parse command-line options into a namespace for use throughout this
    # program
    options = get_options()

    # Create a star-log for controlling the format of output from within this
    # program
    out = StarLog(options.verbosity)
    out.comment("all messages printed by the client after this begin with a *")
    out.comment("(any other lines of output must be from your Player class).")
    out.comment()

    try:
        # Import player classes
        player = PlayerWrapper("your player", options.player_loc, options, out)

        # We'll start measuring space usage from now, after all
        # library imports should be finished:
        set_space_line()

        # Play the game, catching any errors and displaying them to the
        # user:
        connect_and_play(player, options, out)

    except KeyboardInterrupt:
        print()  # (end the line)
        out.comment("bye!")
    except ConnectingException as e:
        out.print("error connecting to server")
        out.comment(e)
    except DisconnectException:
        out.print("connection lost")
    except ProtocolException as e:
        out.print("protocol error!")
        out.comment(e)
Пример #3
0
def main():
    # Parse command-line options into a namespace for use throughout this
    # program
    options = get_options()

    # Create a star-log for controlling the format of output from within this
    # program
    config(level=options.verbosity, ansi=options.use_colour)
    comment("all messages printed by the referee after this begin with *")
    comment("(any other lines of output must be from your Player class).")
    comment()

    try:
        # Import player classes
        p1 = PlayerWrapper(
            "player 1",
            options.player1_loc,
            time_limit=options.time,
            space_limit=options.space,
        )
        p2 = PlayerWrapper(
            "player 2",
            options.player2_loc,
            time_limit=options.time,
            space_limit=options.space,
        )

        # We'll start measuring space usage from now, after all
        # library imports should be finished:
        set_space_line()

        # Play the game!
        result = play(
            [p1, p2],
            delay=options.delay,
            print_state=(options.verbosity > 1),
            use_debugboard=(options.verbosity > 2),
            use_colour=options.use_colour,
            use_unicode=options.use_unicode,
            log_filename=options.logfile,
        )
        # Display the final result of the game to the user.
        comment("game over!", depth=-1)
        print(result)

    # In case the game ends in an abnormal way, print a clean error
    # message for the user (rather than a trace).
    except KeyboardInterrupt:
        _print()  # (end the line)
        comment("bye!")
    except IllegalActionException as e:
        comment("game error!", depth=-1)
        print("error: invalid action!")
        comment(e)
    except ResourceLimitException as e:
        comment("game error!", depth=-1)
        print("error: resource limit exceeded!")
        comment(e)
Пример #4
0
def main():
    # Parse command-line options into a namespace for use throughout this
    # program
    options = get_options()

    # Create a star-log for controlling the format of output from within this
    # program
    out = StarLog(level=options.verbosity, ansi=options.use_colour)
    out.comment("all messages printed by the client after this begin with a *")
    out.comment("(any other lines of output must be from your Player class).")
    out.comment()

    try:
        # Import player classes
        player = PlayerWrapper("your player",
                               options.player_loc,
                               logfn=out.comment)

        # Even though we're not limiting space, the display
        # may still be useful for some users
        set_space_line()

        # Play the game, catching any errors and displaying them to the
        # user:
        result = connect_and_play(player,
                                  options.name,
                                  options.channel,
                                  options.host,
                                  options.port,
                                  logfilename=options.logfile,
                                  out_function=out.comment,
                                  print_state=(options.verbosity > 1),
                                  use_debugboard=(options.verbosity > 2),
                                  use_colour=options.use_colour,
                                  use_unicode=options.use_unicode)

        out.comment("game over!", depth=-1)
        out.print(result)

    except KeyboardInterrupt:
        print()  # (end the line)
        out.comment("bye!")
    except ConnectingException as e:
        out.print("error connecting to server")
        out.comment(e)
    except DisconnectException as e:
        out.print("connection lost", depth=-1)
        out.comment(e)
    except ProtocolException as e:
        out.print("protocol error!", depth=-1)
        out.comment(e)
    except ServerEncounteredError as e:
        out.print("server encountered error!", depth=-1)
        out.comment(e)
Пример #5
0
def main():
    # Parse command-line options into a namespace for use throughout this
    # program
    options = get_options()

    # Create a star-log for controlling the format of output from within this
    # program
    out = StarLog(level=options.verbosity, star="*")
    out.comment(
        "all messages printed by the referee after this begin with a *")
    out.comment(
        "(any other lines of output must be from your Player classes).")
    out.comment()

    try:
        # Import player classes
        p_R = PlayerWrapper('red player', options.playerR_loc, options, out)
        p_G = PlayerWrapper('green player', options.playerG_loc, options, out)
        p_B = PlayerWrapper('blue player', options.playerB_loc, options, out)

        # We'll start measuring space usage from now, after all
        # library imports should be finished:
        set_space_line()

        # open('simulation.tsv', 'w').close()

        # with open('simulation.tsv', 'wt') as out_file:
        #     tsv_writer = csv.writer(out_file, delimiter='\t')

        #     for i in range(-3,4):
        #         for j in range(-3,4):
        #             if i+j <4 and i+j>-4:
        #                 tsv_writer.writerow([(i,j),0])

        # Play the game!
        open('result2.txt', 'w').close()
        n = 10
        for i in range(0, n):
            play([p_R, p_G, p_B], options, out)

    # In case the game ends in an abnormal way, print a clean error
    # message for the user (rather than a trace).
    except KeyboardInterrupt:
        print()  # (end the line)
        out.comment("bye!")
    except IllegalActionException as e:
        out.section("game error")
        out.print("error: invalid action!")
        out.comment(e)
    except ResourceLimitException as e:
        out.section("game error")
        out.print("error: resource limit exceeded!")
        out.comment(e)
Пример #6
0
def main():
    # Parse command-line options into a namespace for use throughout this
    # program
    options = get_options()

    # Create a star-log for controlling the format of output from within this
    # program
    out = StarLog(level=options.verbosity, star="*")
    out.comment(
        "all messages printed by the referee after this begin with a *")
    out.comment(
        "(any other lines of output must be from your Player classes).")
    out.comment()

    try:
        # Import player classes
        p_R = PlayerWrapper('red player', options.playerR_loc, options, out)
        p_G = PlayerWrapper('green player', options.playerG_loc, options, out)
        p_B = PlayerWrapper('blue player', options.playerB_loc, options, out)

        # We'll start measuring space usage from now, after all
        # library imports should be finished:
        set_space_line()

        # Play the game!
        play([p_R, p_G, p_B], options, out)

    # In case the game ends in an abnormal way, print a clean error
    # message for the user (rather than a trace).
    except KeyboardInterrupt:
        print()  # (end the line)
        out.comment("bye!")
    except IllegalActionException as e:
        out.section("game error")
        out.print("error: invalid action!")
        out.comment(e)
    except ResourceLimitException as e:
        out.section("game error")
        out.print("error: resource limit exceeded!")
        out.comment(e)