def load_elements_from_file(self, robot_init_filename, block_init_filename): map = Map((int(self.cfg['MAP']['grid_row_dimension']), int(self.cfg['MAP']['grid_column_dimension']))) for x, y in map.get_blocks_init_place(block_init_filename): if not map.is_location_in_environment(x, y, ( int(self.cfg['MAP']['grid_row_dimension']), int(self.cfg['MAP']['grid_column_dimension']))): raise OutsideBoundryError('init block (x, y) not in map!') map.grid[x][y] = BLOCK_AREA map.blocks.append((x, y)) for x, y in map.get_robot_init_place(robot_init_filename): if not map.is_location_in_environment(x, y, ( int(self.cfg['MAP']['grid_row_dimension']), int(self.cfg['MAP']['grid_column_dimension']))): raise OutsideBoundryError('init robot (x, y) not in map!') map.grid[x][y] = ROBOT_AREA map.robots.append(Robot(x, y)) # add robots return map
def judge_side_white(self, x, y): if x < 0 or y < 0 or x >= self.grid_dimension[ 0] or y >= self.grid_dimension[1]: raise OutsideBoundryError('(x, y) not in map!') if self.is_location_in_environment( x - 1, y, self.grid_dimension) and self.grid[x - 1][y] == EXPLORATED_AREA: return True elif self.is_location_in_environment( x + 1, y, self.grid_dimension) and self.grid[x + 1][y] == EXPLORATED_AREA: return True elif self.is_location_in_environment( x, y + 1, self.grid_dimension) and self.grid[x][y + 1] == EXPLORATED_AREA: return True elif self.is_location_in_environment( x, y - 1, self.grid_dimension) and self.grid[x][y - 1] == EXPLORATED_AREA: return True else: return False
def load_elements_by_click(self, robots_sequences, blocks_sequences): map = Map((int(self.cfg['MAP']['grid_row_dimension']), int(self.cfg['MAP']['grid_column_dimension']))) for x, y in blocks_sequences: if not map.is_location_in_environment(x, y, ( int(self.cfg['MAP']['grid_row_dimension']), int(self.cfg['MAP']['grid_column_dimension']))): raise OutsideBoundryError('init block (x, y) not in map!') map.grid[x][y] = BLOCK_AREA map.blocks.append((x, y)) for x, y in robots_sequences: if not map.is_location_in_environment(x, y, ( int(self.cfg['MAP']['grid_row_dimension']), int(self.cfg['MAP']['grid_column_dimension']))): raise OutsideBoundryError('init robot (x, y) not in map!') map.grid[x][y] = ROBOT_AREA map.robots.append(Robot(x, y)) # add robots return map