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)
def main(): options = get_options() p1 = PlayerWrapper("red", options.player1_loc) p2 = PlayerWrapper("yellow", options.player2_loc) result = play([p1, p2]) print(result)
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)
def main(): # import player classes and create new players options = get_options() p1 = PlayerWrapper("red", options.player1_loc) p2 = PlayerWrapper("yellow", options.player2_loc) # start game_setup result = play([p1, p2]) print(result)
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)
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)
def run_game(weights, random_board=False): # Code copied from __main__() in referee.py # Modified to allow for training algorithm = Algorithm() options = get_options() real_reward = {"r": 0, "g": 0, "b": 0} # 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) # Play the game! players = [p_R, p_G, p_B] board = None if random_board: board = Board.get_random_board() play(players, options, out, training=True, random_board=board) exits = p_R.player.board.exits draw = all(exits.values()) < 4 if not draw: items = exits.items() winner = max(items, key=lambda score: items[1])[0] print("# DEBUG WINNER", winner) for color in "rgb": real_reward[color] = -1 real_reward[winner] = 1 else: for color in "rgb": real_reward[color] = 0 # game finished, now we update weights assert (len(players) > 0) for wrapper in players: features = wrapper.player.features rewards = wrapper.player.rewards weights = algorithm.weight_update( weights, features, rewards, real_reward[wrapper.player.color[0]]) return weights # 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)