Ejemplo n.º 1
0
 def test__ant_not_on_field(self):
     config = DictionaryConfigProvider()
     config.SetValue('InitialPosition', 'InitialDirection', 0)
     config.SetValue('InitialPosition', 'InitialPosition_x', 1)
     config.SetValue('InitialPosition', 'InitialPosition_y', 1)
     processor = AntStepProcesser(config)
     is_on_field = processor.is_ant_on_field(99)
     self.assertTrue(not is_on_field)
Ejemplo n.º 2
0
 def test__empty_ant(self):
     config = DictionaryConfigProvider()
     config.SetValue('InitialPosition', 'InitialDirection', 0)
     config.SetValue('InitialPosition', 'InitialPosition_x', 1)
     config.SetValue('InitialPosition', 'InitialPosition_y', 1)
     processor = AntStepProcesser(config)
     position_data = processor.get_ant_position_and_direction(99)
     self.assertTrue(position_data[0] == -1 and position_data[1] == -1
                     and position_data[2] == -1)
Ejemplo n.º 3
0
 def test__from_north_step_back(self):
     config = DictionaryConfigProvider()
     config.SetValue('InitialPosition', 'InitialDirection', 0)
     config.SetValue('InitialPosition', 'InitialPosition_x', 1)
     config.SetValue('InitialPosition', 'InitialPosition_y', 1)
     processor = AntStepProcesser(config)
     processor.process_ant_step(99, StepEnum.Back)
     position_data = processor.get_ant_position_and_direction(99)
     self.assertTrue(position_data[1] == 2)
Ejemplo n.º 4
0
 def test__initial_step_turn(self):
     config = DictionaryConfigProvider()
     config.SetValue('InitialPosition', 'InitialDirection', 0)
     config.SetValue('InitialPosition', 'InitialPosition_x', 1)
     config.SetValue('InitialPosition', 'InitialPosition_y', 1)
     processor = AntStepProcesser(config)
     processor.process_ant_step(99, StepEnum.TurnRight)
     position_data = processor.get_ant_position_and_direction(99)
     self.assertTrue(position_data[2] == DirectionsEnum.East)
Ejemplo n.º 5
0
 def test__from_east_step_forward(self):
     config = DictionaryConfigProvider()
     config.SetValue('InitialPosition', 'InitialDirection', 0)
     config.SetValue('InitialPosition', 'InitialPosition_x', 1)
     config.SetValue('InitialPosition', 'InitialPosition_y', 1)
     processor = AntStepProcesser(config)
     processor.process_ant_step(99, StepEnum.TurnRight)
     processor.process_ant_step(99, StepEnum.Forward)
     position_data = processor.get_ant_position_and_direction(99)
     self.assertTrue(position_data[0] == 2)
Ejemplo n.º 6
0
 def test__y_negetive_south_facing_axis_movment(self):
     config = DictionaryConfigProvider()
     config.SetValue('InitialPosition', 'InitialDirection', 1)
     config.SetValue('InitialPosition', 'InitialPosition_x', 1)
     config.SetValue('InitialPosition', 'InitialPosition_y', 1)
     processor = AntStepProcesser(config)
     processor.process_ant_step(99, StepEnum.NoStep)
     translate = TranslateStep(config, processor)
     step = AntStep(99, Position(1, 0))
     movment = translate.TranlateStep(step)
     self.assertTrue(movment[0] == StepEnum.Back)
Ejemplo n.º 7
0
 def test__x_positive_east_facing_axis_movment(self):
     config = DictionaryConfigProvider()
     config.SetValue('InitialPosition', 'InitialDirection', 2)
     config.SetValue('InitialPosition', 'InitialPosition_x', 1)
     config.SetValue('InitialPosition', 'InitialPosition_y', 1)
     processor = AntStepProcesser(config)
     processor.process_ant_step(99, StepEnum.NoStep)
     translate = TranslateStep(config, processor)
     step = AntStep(99, Position(2, 1))
     movment = translate.TranlateStep(step)
     self.assertTrue(len(movment) == 1)
     self.assertTrue(movment[0] == StepEnum.Forward)
Ejemplo n.º 8
0
 def test__initial_ant_and_no_ant(self):
     config = DictionaryConfigProvider()
     config.SetValue('InitialPosition', 'InitialDirection', 0)
     config.SetValue('InitialPosition', 'InitialPosition_x', 1)
     config.SetValue('InitialPosition', 'InitialPosition_y', 1)
     processor = AntStepProcesser(config)
     processor.process_ant_step(99, StepEnum.NoStep)
     position_data = processor.get_ant_position_and_direction(99)
     self.assertTrue(position_data[0] == 1 and position_data[1] == 1
                     and position_data[2] == DirectionsEnum.North)
     position_data = processor.get_ant_position_and_direction(100)
     self.assertTrue(position_data[0] == -1 and position_data[1] == -1
                     and position_data[2] == -1)
Ejemplo n.º 9
0
 def test__complex_set_1(self):
     config = DictionaryConfigProvider()
     config.SetValue('InitialPosition', 'InitialDirection', 0)
     config.SetValue('InitialPosition', 'InitialPosition_x', 1)
     config.SetValue('InitialPosition', 'InitialPosition_y', 1)
     processor = AntStepProcesser(config)
     processor.process_ant_step(99, StepEnum.Back)
     processor.process_ant_step(99, StepEnum.Back)
     processor.process_ant_step(99, StepEnum.TurnRight)
     processor.process_ant_step(99, StepEnum.Forward)
     position_data = processor.get_ant_position_and_direction(99)
     self.assertTrue(position_data[0] == 2)
     self.assertTrue(position_data[1] == 3)
     self.assertTrue(position_data[2] == DirectionsEnum.East)
Ejemplo n.º 10
0
	def test__CalculatePathToDestination_UniformGrid(self):
		Maze = MazeFacade(DIYMazeParser(8))
		Provider = UnifiedWorldImageProvider(maze=Maze, config=DictionaryConfigProvider())

		weights = {NodeStateEnum.Clear: 2,
				   NodeStateEnum.Obs: np.inf,
				   NodeStateEnum.UnExplored: 1,
				   NodeStateEnum.Ant: np.inf}

		Planner = AntPathPlanner(safetyRadius=2, cellTypeWeights=weights, stabilityFactor=1)
		StartPosition = Position(0, 0)
		mazeMatrix = Maze.GetMatrix()
		manuallyAdjustedMaze = np.where(mazeMatrix == 1, NodeStateEnum.UnExplored, NodeStateEnum.Clear)
		manuallyAdjustedMaze[0, 0] = NodeStateEnum.Clear
		singleAntWorldImage = SimpleSingleAntWorldImage(manuallyAdjustedMaze, {})
		weightedMatrix = Planner._AntPathPlanner__ConvertWorldImageToWeightedMatrix(StartPosition, singleAntWorldImage)
		pathMatrix = Dijkstra(weightedMatrix, StartPosition)

		resultRoute = Planner._AntPathPlanner__CalculatePathToDestination(StartPosition, Position(4, 4), pathMatrix)

		weightSum = 0

		for position in resultRoute:
			weightSum += weightedMatrix[position.X][position.Y]
			self.assertEqual(pathMatrix[position.X][position.Y], weightSum)

		def printRoute(route):
			for position in route:
				print(f'[{position.X}, {position.Y}] ')
Ejemplo n.º 11
0
	def test__ConvertWorldImageToWeightedMatrix_EmptyGrid(self):
		Maze = MazeFacade(DIYMazeParser(8))
		Provider = UnifiedWorldImageProvider(maze=Maze, config=DictionaryConfigProvider())

		weights = {NodeStateEnum.Clear: 2,
				   NodeStateEnum.Obs: np.inf,
				   NodeStateEnum.UnExplored: 1,
				   NodeStateEnum.Ant: np.inf}

		Planner = AntPathPlanner(safetyRadius=2, cellTypeWeights=weights, stabilityFactor=1)
		StartPosition = Position(0, 0)
		mazeMatrix = Maze.GetMatrix()
		manuallyAdjustedMaze = np.where(mazeMatrix == 1, NodeStateEnum.UnExplored, NodeStateEnum.Clear)
		manuallyAdjustedMaze[0, 0] = NodeStateEnum.Clear
		singleAntWorldImage = SimpleSingleAntWorldImage(manuallyAdjustedMaze, {})
		result = Planner._AntPathPlanner__ConvertWorldImageToWeightedMatrix(StartPosition, singleAntWorldImage)

		Width, Height = result.shape

		for i in range(0, Width):
			for j in range(0, Height):
				if i == 0 and j == 0:
					self.assertEqual(result[i][j], weights[NodeStateEnum.Clear])
				else:
					self.assertEqual(result[i][j], weights[NodeStateEnum.UnExplored])
Ejemplo n.º 12
0
def test_SingleScout(self):
	Maze = MazeFacade(DIYMazeParser(8))
	Provider = UnifiedWorldImageProvider(maze=Maze, config=DictionaryConfigProvider())

	weights = {NodeStateEnum.Clear: 2,
			   NodeStateEnum.Obs: np.inf,
			   NodeStateEnum.UnExplored: 1,
			   NodeStateEnum.Ant: np.inf}

	ant = AlgoAnt(id=1, config=DictionaryConfigProvider(), position=Position(3, 3))

	Provider.ProcessStep(ant, AntStep(ant.ID, ant.CurrentPosition))
	Provider.UpdatePositionsAccordingToMoves()
	Planner = AntPathPlanner(safetyRadius=0, cellTypeWeights=weights)

	result = Planner._AntPathPlanner__ConvertWorldImageToWeightedMatrix(Position(0, 0),
																		Provider.GetAntWorldImage(ant))

	print(result)
Ejemplo n.º 13
0
 def setUp(self):
     self.__Config = config = DictionaryConfigProvider()
     config.SetValue("SimpleAnt", "VisibilityRange", 2)
     config.SetValue("SimpleAnt", "AllowedMovement", 1)