def readSensors(self): hero_position = self.hero.getPosition() hero_direction = self.hero.getDirection() # ------- # Read the sensors in the hero referential # hero_readings_referenced_hero = {} # for direct in direction.DIRECTIONS: # true_direction = direction.changeReferential(direct,hero_direction) # position_to_check = hero_position + direction.toVector(true_direction) # if self.walls.exists(position_to_check): # hero_readings_referenced_hero[direct] = True # else: # hero_readings_referenced_hero[direct] = False # ------- hero_readings_referenced_hero = zumy_interface.readSensors(self) hero_readings_referenced_game = {} for direct in hero_readings_referenced_hero: true_direction = direction.changeReferential(direct,hero_direction) hero_readings_referenced_game[true_direction] = hero_readings_referenced_hero[direct] return hero_readings_referenced_game
def ackSensor(self, sensor_readings): hero_position = self.hero.getPosition() true_readings = {} for sensor_direction in sensor_readings: true_direction = direction.changeReferential(sensor_direction, direction.NORTH) true_readings[true_direction] = sensor_readings[sensor_direction] for direc in true_readings: position_to_ack = hero_position + direction.toVector(direc) self.known_cells.setValue(position_to_ack, True) self.known_maze.setValue(position_to_ack, true_readings[direc])
def readSensor(game, direct): if direct == direction.NORTH: true_direction = direction.changeReferential(direct,game.hero.getDirection()) position_to_check = game.hero.getPosition() + direction.toVector(true_direction) if game.walls.exists(position_to_check): return True else: return False elif direct == direction.EAST: true_direction = direction.changeReferential(direct,game.hero.getDirection()) position_to_check = game.hero.getPosition() + direction.toVector(true_direction) if game.walls.exists(position_to_check): return True else: return False elif direct == direction.SOUTH: true_direction = direction.changeReferential(direct,game.hero.getDirection()) position_to_check = game.hero.getPosition() + direction.toVector(true_direction) if game.walls.exists(position_to_check): return True else: return False elif direct == direction.WEST: true_direction = direction.changeReferential(direct,game.hero.getDirection()) position_to_check = game.hero.getPosition() + direction.toVector(true_direction) if game.walls.exists(position_to_check): return True else: return False