def run_test_game(i): np.random.seed(int.from_bytes(os.urandom(4), byteorder='little')) value_net = ValueNet(rl_model_filepath, rl_step-1) # load from previous generation rl_player = RLValueMinimaxPlayer(value_net, rl_minimax_depth) minimax_player = SimpleMinimaxPlayer(base_minimax_depth) if i % 2: win, step, _ = play_game(rl_player, minimax_player, verbose=0, limit_to_draw=limit_to_draw) else: win, step, _ = play_game(minimax_player, rl_player, verbose=0, limit_to_draw=limit_to_draw) return win, step
def simulate(args): red_model = ai.load_model(args.red_model) yellow_model = ai.load_model(args.yellow_model) prefix_base_path = make_base_dir(args.output_prefix) # prefix_base_path = os.path.dirname(args.output_prefix) # os.makedirs(prefix_base_path) with open('{}metadata.txt'.format(args.output_prefix), 'w+') as f: f.write("Red Model:{}\nYellow Model: {}\n".format( args.red_model, args.yellow_model)) for i in range(args.num_games): if i % 1000 == 0 and i > 0: print "Generating Game: {}".format(i) results = ai.play_game(red_model, yellow_model) data = results output_file = "{}/game_{}.json".format(args.output_prefix, i) with open(output_file, 'w+') as f: f.write(json.dumps(data)) f.write('\n') print "All Games Run. Saved to: {}".format(prefix_base_path)
def run_init_game(i): print("Generating game number {}".format(i)) np.random.seed(int.from_bytes(os.urandom(4), byteorder='little')) random.seed(int.from_bytes(os.urandom(4), byteorder='little')) minimax_player = SimpleMinimaxPlayer(base_minimax_depth) _, _, trace = play_game(minimax_player, minimax_player, verbose=1, limit_to_draw=limit_to_draw, random_burn_in=random_burn_in, trace_min=trace_min) return trace
def run_rl_game(i): print("Generating RL game number {} from generation {}".format(i, rl_step-1)) np.random.seed(int.from_bytes(os.urandom(4), byteorder='little')) random.seed(int.from_bytes(os.urandom(4), byteorder='little')) value_net = ValueNet(rl_model_filepath, rl_step-1) # load from previous generation rl_player = RLValueMinimaxPlayer(value_net, rl_minimax_depth) _, _, trace = play_game(rl_player, rl_player, verbose=1, limit_to_draw=limit_to_draw, random_burn_in=random_burn_in, trace_min=trace_min) return trace
During a guess prompt, the up / down arrow keys can be used to cycle through prior guesses. The left / right arrow keys and the backspace key can be used in conjunction to edit a previous guess (which can then be submitted by pressing Enter). Type 'QUIT' as a guess to exit the game early. Type 'CHEAT' as a guess to have the game print the correct pattern (for testing). ''' % (PATTERN_LENGTH, ', '.join(colors_long), ', '.join(colors_short)) while True: guess = raw_input('Your guess: ') if guess == 'QUIT': print 'Exiting game early.' break if guess == 'CHEAT': print 'The correct pattern is:', ' '.join(game.pattern) continue try: done, correct_match, correct_position = game.guess(guess.split(' ')) except ValueError as e: print 'Invalid input: %s' % e.message continue if done: print 'Correct guess!' break else: print 'Incorrect guess: %d %d' % (correct_match, correct_position) else: print 'Skipping instructions.' play_game(game)