def test_mis_003(): """ Tests the MIS response """ daide_str = 'MIS ( #0 )' game = Game(map_name='standard') phase_name = 'W1901A' power = game.get_power('FRANCE') response = responses.MIS(phase_name=phase_name, power=power) assert isinstance(response, responses.MIS), 'Expected a MIS response' assert bytes(response) == str_to_bytes(daide_str)
def test_mis_010(): """ Tests the MIS response """ daide_str = 'MIS ( FRA FLT BRE ) ( FRA AMY MAR )' game = Game(map_name='standard') phase_name = 'S1901M' power = game.get_power('FRANCE') power.orders['INVALID'] = 'A PAR - BUR' response = responses.MIS(phase_name=phase_name, power=power) assert isinstance(response, responses.MIS), 'Expected a MIS response' assert bytes(response) == str_to_bytes(daide_str)
def test_get_nb_centers(): """ Testing if the number of supply centers is correct """ game = Game() player = FakePlayer() state_proto = extract_state_proto(game) # Checking every power power_names = [power_name for power_name in game.powers] for power_name in power_names: assert player.get_nb_centers(state_proto, power_name) == len(game.get_power(power_name).centers)
def test_mis_012(): """ Tests the MIS response """ daide_str = 'MIS ( #-1 )' game = Game(map_name='standard') phase_name = 'W1901A' power = game.get_power('FRANCE') power.centers += ['LON'] power.units = power.units[:2] response = responses.MIS(phase_name=phase_name, power=power) assert isinstance(response, responses.MIS), 'Expected a MIS response' assert bytes(response) == str_to_bytes(daide_str)
def test_mis_008(): """ Tests the MIS response """ daide_str = 'MIS ( FRA FLT BRE ) ( FRA AMY MAR )' game = Game(map_name='standard') game.add_rule('NO_CHECK') game.set_orders('FRANCE', ['A PAR - BUR']) phase_name = 'S1901M' power = game.get_power('FRANCE') response = responses.MIS(phase_name=phase_name, power=power) assert isinstance(response, responses.MIS), 'Expected a MIS response' assert bytes(response) == str_to_bytes(daide_str)
def play_game(game: Game, save_game: bool, agent_nation: list, label="", turn_number = 3, repeat_number= 1000): set_starting_influence(game) if save_game: saver = GameSaver() q_table_Handler = QtableHandler(game, agent_nation) iterator = 0 state = 0 finish = False stats = {"centers":defaultdict(list), "influence":defaultdict(list)} while not game.is_game_done and not finish: iterator += 1 q_table_Handler.set_turn_info() # settings order phase = game.get_current_phase()[-1] for power_name, power in game.powers.items(): power_orders = q_table_Handler.chose_orders(power_name) game.set_orders(power_name, power_orders) #visualizer.paint_orders(game) if save_game: saver.save_game(game, "gierka") game.process() if phase == 'M': q_table_Handler.set_reward() adjust_influence(game) if iterator == turn_number: state += 1 if state % repeat_number == 0: q_table_Handler.save() if state == repeat_number: save_stat(stats,turn_number,label) game = load_saved_games_from_disk("game.json")[0] return iterator = 0 print("State: ", state) print("Accuracy: {0}".format(q_table_Handler.get_accuracy())) print("Number of Germany centers: ", game.get_centers("GERMANY").__len__(), game.get_power("GERMANY").influence.__len__()) for power_name, _ in game.powers.items(): stats["influence"][power_name].append(game.get_power(power_name).influence.__len__()) stats["centers"][power_name].append(game.get_centers(power_name).__len__()) game = load_saved_games_from_disk("game.json")[0] q_table_Handler.game = game q_table_Handler.attempts = 0 q_table_Handler.miss_hits = 0
def test_mis_002(): """ Tests the MIS response """ daide_str = 'MIS ( TUR FLT ANK MRT ( ARM ) ) ' \ '( TUR FLT CON MRT ( BLA SMY ( BUL ECS ) ( BUL SCS ) ) ) ' \ '( TUR AMY SMY MRT ( SYR ) )' game = Game(map_name='standard') phase_name = 'S1901R' power = game.get_power('TURKEY') power.units = ['F ANK', 'F CON', 'A SMY'] power.retreats['F ANK'] = ['ARM'] power.retreats['F CON'] = ['BLA', 'SMY', 'BUL/EC', 'BUL/SC'] power.retreats['A SMY'] = ['SYR'] response = responses.MIS(phase_name=phase_name, power=power) assert isinstance(response, responses.MIS), 'Expected a MIS response' assert bytes(response) == str_to_bytes(daide_str)