def test_foods(self): game_state = create_test_game_state() self.assertEqual(28, len(game_state.game_turns[0].foods)) self.assertEqual(5, len(game_state.game_turns[101].foods)) self.assertEqual( Position(7, 5), game_state.game_turns[0].foods[Position(7, 5)].position)
def test_create_ants_turn0(self): game_state = create_test_game_state() turn0 = game_state.game_turns[0] self.assertEqual(8, len(turn0.ants)) self.assertEqual(Position(1, 19), turn0.ants[Position(1, 19)].position) self.assertEqual('lazarant', turn0.ants[Position(1, 19)].bot.bot_type) self.assertEqual('pkmiec', turn0.ants[Position(41, 19)].bot.bot_type)
def test_hills(self): game_state = create_test_game_state() self.assertEqual(8, len(game_state.game_turns[0].hills)) self.assertEqual( Position(1, 19), game_state.game_turns[0].hills[Position(1, 19)].position) self.assertTrue(game_state.game_turns[151].hills[Position( 1, 19)].is_alive) self.assertFalse(game_state.game_turns[152].hills[Position( 1, 19)].is_alive)
def test_create_nn_input(self): game_state = create_test_game_state() test_ant = game_state.game_turns[0].ants.get(Position(1, 19)) ant_vision = game_state.game_map.get_positions_within_distance( test_ant.position, game_state.view_radius_squared) translator = GameStateTranslator() nn_input = translator.convert_to_1d_example(test_ant, game_state) self.assertIsNotNone(nn_input) self.assertEqual((len(ant_vision) - 1), len(nn_input.features))
def test_next_direction(self): game_state = create_test_game_state() self.assertEqual( Direction.WEST, self.get_ant_at_pos(game_state, 0, Position(28, 19)).next_direction) self.assertEqual( Direction.NORTH, self.get_ant_at_pos(game_state, 1, Position(28, 18)).next_direction) self.assertEqual( Direction.NORTH, self.get_ant_at_pos(game_state, 2, Position(27, 18)).next_direction) self.assertEqual( Direction.SOUTH, self.get_ant_at_pos(game_state, 12, Position(19, 24)).next_direction)
def test_create_2d_ant_vision(self): game_state = create_test_game_state() translator = GameStateTranslator() translated = translator.convert_to_2d_ant_vision( 'pkmiec_1', [game_state]) self.assertIsNotNone(translated)
def test_ant_position(self): game_state = create_test_game_state() test_ant: AntTurn = self.get_ant_at_pos(game_state, 59, Position(16, 14)) self.assertIsNotNone(test_ant) self.assertEqual('lazarant', test_ant.bot.bot_type)
def test_create_ants_turn2(self): game_state = create_test_game_state() turn2 = game_state.game_turns[2] self.assertEqual(13, len(turn2.ants)) self.assertEqual(Position(3, 19), turn2.ants[Position(3, 19)].position)
def test_create_ants_turn1(self): game_state = create_test_game_state() turn1 = game_state.game_turns[1] self.assertEqual(8, len(turn1.ants)) self.assertIsNotNone( self.get_ant_at_pos(game_state, 1, Position(2, 19)))
import cProfile import glob from ants_ai.training.neural_network.encoders.game_state_translator import GameStateTranslator from ants_ai.training.tests.test_utils import create_test_game_state from ants_ai.training.game_state.generator import GameStateGenerator from functional import seq import jsonpickle import os from ants_ai.training.game_state.game_state import GameState from ants_ai.training.neural_network.encoders import encoders as enc game_state = create_test_game_state() translator = GameStateTranslator() def load_game_state(path: str, gsg: GameStateGenerator) -> GameState: with open(path, "r") as f: json_data = f.read() pr = jsonpickle.decode(json_data) return gsg.generate(pr) def convert_game_state(): bot_to_emulate = 'memetix_1' game_paths = [ f for f in glob.glob( f'{os.getcwd()}\\training\\tests\\test_data\\**\\*.json') ] test_games = game_paths[2:3] gst = GameStateTranslator()