def __init__(self, my_map): def is_robot(region): return isinstance(region, robot) self.my_map = my_map for region in my_map.get_regions_with_predicate(is_robot): base = region.base self.robot_location = base self.robot = region if not hasattr(self, 'robot'): raise Exception("Couldn't find a robot") self.last_sense = read_sonar(self.my_map, self.robot, self.robot_location)
def move(self, displacement, direction): senses = [] move_direction = directions[direction] print 'move_direction =', move_direction for i in range(displacement): new_location = pairwise_add(self.robot_location, move_direction) regions = region_list_to_set(self.my_map.regions_between( \ self.robot_location, new_location, 0.5)) for base, region in regions: if isinstance(region, solid): raise WallException self.robot_location = new_location self.robot.base = self.robot_location senses.append(read_sonar(self.my_map, self.robot, self.robot_location)) self.last_sense = senses[-1] return senses
from input_to_map import read_file, print_map from map.region.robot_regions import * from basics.utility import pairwise_add, pairwise_mul, pairwise_sub from sensing.process_sense_data import read_sonar from simulation.simulation_classes import SimulatedRobotIO from map.map import * from simulation.instantiate_map import * m = read_file(open('input.txt')) robot_region = instantiate_robot(m) robot_io = SimulatedRobotIO(m) print print_map(m) walls = read_sonar(m, robot_region) print walls print robot_io.move(1, 'south') print print_map(m)