def makeConfigFile(config, resolver=None, openFileAfterWrite=False): imageRoot = config['imageRoot'] resolver = resolver or _RESOLVER_BY_NAME[config.get('resolver', 'default')] for filename, fields in config['targets']: _fields = fields if isinstance(fields, tuple) else tuple(fields) seq = (_extractFields(resolver(imagePath), _fields) for imagePath in Path.ilistFileEx(imageRoot)) File.writeLines(filename,seq) if openFileAfterWrite: subprocess.Popen(f'notepad {filename}', shell=True)
def exec(self, ai_cmds: Dict[Player, AICommand], strategy_obstacles) -> Dict: self.updates_obstacles() self.strategy_obstacles = strategy_obstacles for player, ai_cmd in ai_cmds.items(): if ai_cmd.target is not None: if ai_cmd.enable_pathfinder: self.paths[player] = self.generate_path(player, ai_cmd) else: self.paths[player] = Path(start=player.position, target=ai_cmd.target.position) else: self.paths[player] = None return self.paths
def path_smoother(path, speed, end_speed) -> Tuple[Path, float]: if len(path) < 3: return path, end_speed p1 = path[0] p2 = path[1] p3 = path[2] p4, p5 = compute_circle_points(p1, p2, p3, speed, acc=MAX_LINEAR_ACCELERATION) if (p1 - p2).norm < (p4 - p2).norm or (p3 - p2).norm < (p5 - p2).norm: point_list = path[:3] else: point_list = [path.start, p4, p5] turn_radius, _ = compute_turn_radius(*point_list, speed, acc=MAX_LINEAR_ACCELERATION) next_speed = speed_in_corner(turn_radius, acc=MAX_LINEAR_ACCELERATION) return Path.from_sequence(point_list), next_speed
def test_whenInitializingFromAListOfPoints_thenAListOfPointsIsAssigned(self): path = Path.from_sequence(A_LIST_OF_POSITION) assert path.points == A_LIST_OF_POSITION
def test_givenStartTargetArray_whenFromArray_thenReturnPath(self): path = Path.from_array(A_START_ARRAY, A_TARGET_ARRAY) self.assertEqual(path.start, A_START) assert path.target == A_TARGET
A_START = Position(100, 200) A_TARGET = Position(123, -456) A_PATH = Path(start=A_START, target=A_TARGET) A_START_ARRAY = A_START.array A_TARGET_ARRAY = A_TARGET.array A_LIST_OF_POSITION = [Position(0, 0), Position(0, 10), Position(10, 10), Position(10, 20), Position(20, 20), Position(20, 30)] A_LONG_PATH = Path.from_sequence(A_LIST_OF_POSITION) PATH_LENGTH = 50 A_LIST_OF_CLOSE_POSITION = [Position(1,1), Position(1,-1), Position(1, -2), Position(10,1), Position(10,1), Position(10,2), Position(10, 21), Position(10, 20), Position(10, 22), Position(30, 21), Position(30, 20), Position(30, 22)] A_PATH_WITH_CLOSE_POINTS = Path.from_sequence(A_LIST_OF_CLOSE_POSITION) A_PATH_WITH_CLOSE_POINTS_FILTERED = Path.from_sequence([Position(1, 1), Position(10, 1), Position(10, 21), Position(30, 22)]) class TestPath(unittest.TestCase):
def test_whenInitializingFromAListOfPoints_thenAListOfPointsIsAssigned( self): path = Path.from_sequence(A_LIST_OF_POSITION) assert path.points == A_LIST_OF_POSITION
def test_givenStartTarget_whenNew_thenReturnPath(self): path = Path(start=A_START, target=A_TARGET) self.assertEqual(path.start, A_START) assert path.target == A_TARGET
import unittest from Util import Path, Position __author__ = 'Simon Bouchard' A_START = Position(100, 200) A_TARGET = Position(123, -456) A_PATH = Path(start=A_START, target=A_TARGET) A_START_ARRAY = A_START.array A_TARGET_ARRAY = A_TARGET.array A_LIST_OF_POSITION = [ Position(0, 0), Position(0, 10), Position(10, 10), Position(10, 20), Position(20, 20), Position(20, 30) ] A_LONG_PATH = Path.from_sequence(A_LIST_OF_POSITION) PATH_LENGTH = 50 A_LIST_OF_CLOSE_POSITION = [ Position(1, 1), Position(1, -1), Position(1, -2), Position(10, 1), Position(10, 1), Position(10, 2),