def test_pick_starting_regions(self): input = 'pick_starting_regions 1000 11 12 21 31 32 33 11 12 21 31 32 33' command = commandfactory.parse_input(input) actual = command.regions() timeout = command.timeout() expected = ['11', '12', '21', '31', '32', '33', '11', '12', '21', '31', '32', '33'] self.assertEqual(timeout, 1000) self.assertEqual(actual, expected)
def test_setup_super_regions(self): input = 'setup_map super_regions 10 10 20 20 30 30' command = commandfactory.parse_input(input) actual = command.super_region_to_reward() expected = { '10': 10, '20': 20, '30': 30 } self.assertEqual(actual, expected)
def test_setup_neighbors(self): input = 'setup_map neighbors 11 12,32,33 12 31,33 21 33' command = commandfactory.parse_input(input) actual = command.region_to_neighbors() expected = { '11': ['12', '32', '33'], '12': ['31', '33'], '21': ['33'] } self.assertEqual(actual, expected)
def test_update_map(self): input = 'update_map 11 Foo 5 12 Bar 10 21 Foo 3 33 Foo 2' command = commandfactory.parse_input(input) actual = command.map_updates() expected = [ MapUpdate('11', 'Foo', 5), MapUpdate('12', 'Bar', 10), MapUpdate('21', 'Foo', 3), MapUpdate('33', 'Foo', 2) ] self.assertEqual(actual, expected)
def test_setup_regions(self): input = 'setup_map regions 11 10 12 10 21 20 31 30 32 30 33 30' command = commandfactory.parse_input(input) actual = command.region_to_super_region() expected = { '11': '10', '12': '10', '21': '20', '31': '30', '32': '30', '33': '30' } self.assertEqual(actual, expected)
def start(self): self.__game = Game() self.running = True while self.running: try: line = raw_input() command = commandfactory.parse_input(line) output_commands = self.__game.process_command(command) output = ', '.join([cmd.output() for cmd in output_commands]) if output: print(output) except EOFError: break
def test_map_creation(self): input_file_name = './sample_map1.txt' with open(input_file_name) as f: input_lines = map(str.strip, f.readlines()) commands = [commandfactory.parse_input(line) for line in input_lines] self.__map = Map() for input_cmd in commands: if isinstance(input_cmd, SuperRegionsCmd): self.__map.init_super_regions(input_cmd.super_region_to_reward()) elif isinstance(input_cmd, RegionsCmd): self.__map.init_regions(input_cmd.region_to_super_region()) elif isinstance(input_cmd, NeighborsCmd): self.__map.init_neighbors(input_cmd.region_to_neighbors())
def get_sample_map1(): input_file_name = './sample_map1.txt' with open(input_file_name) as f: input_lines = map(str.strip, f.readlines()) commands = [commandfactory.parse_input(line) for line in input_lines] map1 = Map() for input_cmd in commands: if isinstance(input_cmd, SuperRegionsCmd): map1.init_super_regions(input_cmd.super_region_to_reward()) elif isinstance(input_cmd, RegionsCmd): map1.init_regions(input_cmd.region_to_super_region()) elif isinstance(input_cmd, NeighborsCmd): map1.init_neighbors(input_cmd.region_to_neighbors()) situation1 = Situation(map1) return map1, situation1
def test_opponent_moves(self): input = 'opponent_moves 11 12 21 31 32 33 No moves bot1 place_armies 21 2, ' + \ 'bot1 place_armies 2 21 bot1 attack/transfer 12 33 2, bot1 attack/transfer 12 33 4' command = commandfactory.parse_input(input) actual = command.opponent_commands() picks = actual[0].regions() expected_picks = ['11', '12', '21', '31', '32', '33'] self.assertEqual(picks, expected_picks) nomove = actual[1] self.assertIsInstance(nomove, DontMoveCmd) place_armies_1 = actual[2].placed_armies() expected_place_armies_1 = Deployment('bot1', '21', 2) self.assertEqual(place_armies_1, expected_place_armies_1) place_armies_2 = actual[3].placed_armies() expected_place_armies_2 = Deployment('bot1', '2', 21) self.assertEqual(place_armies_2, expected_place_armies_2) move_armies_1 = actual[4].move() expected_move_armies_1 = Move('bot1', '12', '33', 2) self.assertEqual(move_armies_1, expected_move_armies_1) move_armies_2 = actual[5].move() expected_move_armies_2 = Move('bot1', '12', '33', 4) self.assertEqual(move_armies_2, expected_move_armies_2)
def test_settings_opponent_bot(self): input = 'settings your_bot Bar' command = commandfactory.parse_input(input) actual = command.bot_name() expected = 'Bar' self.assertEqual(actual, expected)
def test_move(self): input = 'go attack/transfer 1000' command = commandfactory.parse_input(input) actual = command.timeout() expected = 1000 self.assertEqual(actual, expected)
def test_place_armies(self): input = 'go place_armies 1000' command = commandfactory.parse_input(input) actual = command.timeout() expected = 1000 self.assertEqual(actual, expected)
def test_settings_starting_armies(self): input = 'settings starting_armies 50' command = commandfactory.parse_input(input) actual = command.num_armies() expected = 50 self.assertEqual(actual, expected)