def testInitRobot(self): """test de la methode init de la classe Robot""" terrainTest=Terrain('Terrain_test.txt') robotTest = Robot(terrainTest,5,7,3) self.assertEqual(robotTest._Robot__x,5) self.assertEqual(robotTest._Robot__y,7) self.assertEqual(robotTest._Robot__dir,3) self.assertEqual(robotTest.life,9) self.assertIsNot(robotTest.win,True)
def breadth_first_search(state): # initialize the list of states to explore with initial state states_to_explore = [state] # initialize the list of explored states as empty explored_states = [] # selects the initial state as the first state to explore state_being_explored = states_to_explore[0] # while there are states to explore in the list while len(states_to_explore) > 0: # verify if stateToExplore is a final state if state_being_explored.is_final_state(): return state_being_explored # otherwise, expands stateToExplore for action in state.robot.actions: # for each action, get the new state based on the state being explored new_state = State( list(state_being_explored.spaceConfiguration), Robot(state_being_explored.robot.position, list(state_being_explored.robot.actionsTaken))) new_state.apply_action(action) # check if the new state is in the lists already_explored = False already_listed = False # check if the new state is in the list of already explored states for st in explored_states: if new_state.equals_state(st): already_explored = True break # check if the new state is in the list of states to explore(if the state wasn't found in the explored list) if not already_explored: for st in states_to_explore: if new_state.equals_state(st): already_listed = True break # adds the generated state to the list of states to be explored, if it wasn't found in any lists if not already_listed and not already_explored: states_to_explore.append(new_state) # add stateToExplore in the list of states already explored explored_states.append(state_being_explored) # remove stateToExplore from the list of states to explore states_to_explore.remove(state_being_explored) # selecting next state to be explored if len(states_to_explore) > 0: state_being_explored = states_to_explore[0] else: return None
def recursive_depth(state_to_explore, path=[]): path.append(state_to_explore) explored_states.append(state_to_explore) if state_to_explore.is_final_state(): return state_to_explore for action in state_to_explore.robot.actions: new_state = State( list(state_to_explore.spaceConfiguration), Robot(state_to_explore.robot.position, list(state_to_explore.robot.actionsTaken))) new_state.apply_action(action) if state_not_explored(new_state): return recursive_depth(new_state)
#flip the robot on its X-axis #(for example if our robot moves to the right #we want to bring it back to the left when the room changes) if prevCol != rCol: rX = abs(rX - 750) #flip the robot on its Y-axis elif prevRow != rRow: rY = abs(rY - 750) # call the fillRoom function to add the robot to the screen rooms[rRow][rCol].fillRoom(screen, robotImage, rX, rY) #call the sensor data mX = rooms[rRow][rCol].moonWidth mY = rooms[rRow][rCol].moonHeight sensors = Robot.Robot().getSensorData(rX, rY, mX, mY) sensors, positions = DataPrep.addErrors(sensors, rX, rY) positions = [rX, rY] #SLAM! roomCoord = [rRow, rCol] SLAM.demoSlam(sensors, positions, screen, roomCoord) # update the screen pygame.display.update() #print out the graph DataPrep.printCoords()
def testUTurn(self): """test de la methode U-Turn de la classe Robot""" terrainTest=Terrain('Terrain_test.txt') robotTest = Robot(terrainTest) robotTest.U_Turn() self.assertEqual(robotTest._Robot__dir,3)
def testTurnLeft(self): """test de la methode virage gauche de la classe Robot""" terrainTest=Terrain('Terrain_test.txt') robotTest = Robot(terrainTest) robotTest.Turn_Left() self.assertEqual(robotTest._Robot__dir,0)
def testTurnRight(self): """test de la methode virage droite de la classe Robot""" terrainTest=Terrain('Terrain_test.txt') robotTest = Robot(terrainTest) robotTest.Turn_Right() self.assertEqual(robotTest._Robot__dir,2)