def get_steps(self, agent_r, board_size=50, agent_o=None): next_slot = Slot(agent_r.InitPosX, agent_r.InitPosY) flag = (agent_r.InitPosY == board_size - 1 and not (agent_r.InitPosX == 0)) steps = [] counter = 0 while True: counter += 1 if counter > 1000000000000: break steps.append(next_slot) # in the middle of moving from bottom row to top row if flag: next_slot = next_slot.go_north() if next_slot.row == 0: flag = False if next_slot == Slot(agent_r.InitPosX, agent_r.InitPosY): break continue # check if in last position, and start moving from last row to top row elif next_slot.row == board_size - 1 and next_slot.col == board_size - 1 - 1: flag = True next_slot = next_slot.go_east() if next_slot == Slot(agent_r.InitPosX, agent_r.InitPosY): break continue # update next slot elif next_slot.row % 2 != 0: if next_slot.col == board_size - 1 - 1: next_slot = next_slot.go_south() else: next_slot = next_slot.go_east() else: if next_slot.col == 0: next_slot = next_slot.go_south() else: next_slot = next_slot.go_west() if next_slot == Slot(agent_r.InitPosX, agent_r.InitPosY): break return steps
def get_steps(self, agent_r, board_size = 50, agent_o = None): next_slot = Slot(agent_r.InitPosX, agent_r.InitPosY) flag = (agent_r.InitPosX == board_size - 1) counter = 0 # print "init pos {},{}: ".format(agent_r.InitPosX, agent_r.InitPosY) while True: counter += 1 if counter > board_size * board_size: break self.steps.append(next_slot) # in the middle of moving from bottom rpw to top row if flag: if next_slot.col == board_size - 1: flag = False next_slot = next_slot.go_north() else: next_slot = next_slot.go_east() if next_slot == Slot(agent_r.InitPosX, agent_r.InitPosY): break continue # check if in last position, and start moving from last row to top row elif next_slot.row == board_size - 1 - 1 and next_slot.col == 0: flag = True next_slot = next_slot.go_south() if next_slot == Slot(agent_r.InitPosX, agent_r.InitPosY): break continue # update next slot elif next_slot.col % 2 != 0: if next_slot.row == 0: next_slot = next_slot.go_west() else: next_slot = next_slot.go_north() else: if next_slot.row == board_size - 1 - 1: next_slot = next_slot.go_west() else: next_slot = next_slot.go_south() if next_slot.row > board_size - 1: print("+1") if next_slot == Slot(agent_r.InitPosX, agent_r.InitPosY): break return self.steps
def get_steps(self, agent_r, board_size = 50, agent_o = None): """ Returns a non-circular vertical coverage, starting from agent_r's initial position to top-right position, then cover all cells from top-right to bottom-left, without repeating cells (there are some assumption regarding the initial position :param agent_r: the given agent_r :param board_size: board's width :param board_size: board's height :return: a set of steps covering the whole board """ steps = [] next_slot = Slot(agent_r.InitPosX, agent_r.InitPosY) turning_slot = Slot(agent_r.InitPosX, agent_r.InitPosY) reaching_to_farthest_corner = True up_or_down = 'd' # assert call assert agent_r.InitPosX % 2 == 0 while True: steps.append(next_slot) if len(steps) >= board_size * board_size: break # Check if we agent_r reached the farthest corner of the board if next_slot == Slot(board_size - 1, board_size - 1): reaching_to_farthest_corner = False if reaching_to_farthest_corner: if next_slot.row < board_size - 1: next_slot = next_slot.go_south() continue elif next_slot.col < board_size - 1: next_slot = next_slot.go_east() continue else: if next_slot.col > agent_r.InitPosY: if next_slot.col % 2 != 0: next_slot = next_slot.go_north() if next_slot.row > 0 else next_slot.go_west() else: next_slot = next_slot.go_south() if next_slot.row < board_size - 2 else next_slot.go_west() continue else: if up_or_down == 'd': if next_slot.go_south() != turning_slot: if next_slot.row < board_size - 1: next_slot = next_slot.go_south() else: next_slot = next_slot.go_west() up_or_down = 'u' continue else: turning_slot = turning_slot.go_west().go_west().go_north().go_north() steps.append(next_slot.go_west()) steps.append(next_slot.go_west().go_south()) next_slot = next_slot.go_west().go_south().go_south() continue else: if next_slot != turning_slot: if next_slot.row > 0: next_slot = next_slot.go_north() else: next_slot = next_slot.go_west() up_or_down = 'd' continue else: steps.append(next_slot.go_east()) steps.append(next_slot.go_east().go_north()) next_slot = next_slot.go_east().go_north().go_north() continue return steps[:board_size * board_size]
def get_steps(self, agent_r, board_size=50, agent_o=None): # This coverage strategy covers first the top left, then top right, then bottom left, then bottom right quarters of # the area. # While building this function, we assumed 100X100 dimensions next_slot = Slot(agent_r.InitPosX, agent_r.InitPosY) # flag = (agent_r.InitPosY == boardSizeY - 1 and not (agent_r.InitPosX == 0)) steps = [] counter = 0 while True: counter += 1 if counter > 100000: print("Something is wrong, counter is too big!") print(steps) break if counter > 1 and (next_slot.row, next_slot.col) == (agent_r.InitPosX, agent_r.InitPosY): break steps.append(next_slot) # TL Quarter if 0 <= next_slot.row < board_size / 2 and 0 <= next_slot.col < board_size / 2: if (next_slot.row, next_slot.col) == (board_size / 2 - 1, board_size / 2 - 1): next_slot = next_slot.go_east() continue if next_slot.col == 0: next_slot = next_slot.go_north( ) if next_slot.row > 0 else next_slot.go_east() continue if next_slot.row % 2 == 0 and next_slot.row < board_size / 2 - 2: # An even line, not the last one next_slot = next_slot.go_east( ) if not next_slot.col == board_size / 2 - 1 else next_slot.go_south( ) continue elif next_slot.row % 2 != 0 and not next_slot.row == board_size / 2 - 1: # An odd line, not before last next_slot = next_slot.go_west( ) if not next_slot.col == 1 else next_slot.go_south() continue elif next_slot.row % 2 == 0 and next_slot.row == board_size / 2 - 2: # An even line, the last one next_slot = next_slot.go_south( ) if next_slot.col % 2 != 0 else next_slot.go_east() elif next_slot.row % 2 != 0 and next_slot.row == board_size / 2 - 1: # An odd line, last line next_slot = next_slot.go_east( ) if next_slot.col % 2 != 0 else next_slot.go_north() else: print("TL: Error occurred! Should not reach here!") continue # TR Quarter elif 0 <= next_slot.row < board_size / 2 and board_size / 2 <= next_slot.col < board_size: if (next_slot.row, next_slot.col) == (board_size / 2 - 1, board_size - 1): next_slot = next_slot.go_south() continue elif next_slot.col % 2 == 0: next_slot = next_slot.go_north( ) if next_slot.row > 0 else next_slot.go_east() continue elif next_slot.col % 2 != 0: next_slot = next_slot.go_south( ) if next_slot.row < board_size / 2 - 1 else next_slot.go_east( ) continue else: print("TR: Error occurred! Should not reach here!") continue # BL Quarter elif board_size / 2 <= next_slot.row < board_size and 0 <= next_slot.col < board_size / 2: if (next_slot.row, next_slot.col) == (board_size / 2, 0): # last cell of quarter next_slot = next_slot.go_north() continue elif next_slot.col % 2 == 0: # an even column next_slot = next_slot.go_north( ) if next_slot.row > board_size / 2 else next_slot.go_west( ) continue elif next_slot.col % 2 != 0: # An odd line next_slot = next_slot.go_south( ) if next_slot.row < board_size - 1 else next_slot.go_west( ) continue else: print("BL: Error occurred! Should not reach here!") continue # BR Quarter else: if (next_slot.row, next_slot.col) == (board_size / 2, board_size / 2): # last cell of quarter next_slot = next_slot.go_west() continue elif next_slot.col == board_size - 1: next_slot = next_slot.go_south( ) if not next_slot.row == board_size - 1 else next_slot.go_west( ) continue elif next_slot.row % 2 != 0 and not next_slot.row == board_size / 2 + 1: # and odd line, not before last next_slot = next_slot.go_west( ) if next_slot.col > board_size / 2 else next_slot.go_north( ) continue elif next_slot.row % 2 != 0 and next_slot.row == board_size / 2 + 1: # and odd line, DO before last next_slot = next_slot.go_north( ) if next_slot.col % 2 == 0 else next_slot.go_west() continue elif next_slot.row % 2 == 0 and not next_slot.row == board_size / 2: # an even line, not last one next_slot = next_slot.go_east( ) if next_slot.col < board_size - 2 else next_slot.go_north( ) continue elif next_slot.row % 2 == 0 and next_slot.row == board_size / 2: # an even line, INDEED last one next_slot = next_slot.go_west( ) if next_slot.col % 2 == 0 else next_slot.go_south() continue else: print("BR: Error occurred! Should not reach here!") continue return steps
def get_steps(self, agent_r, board_size = 50, agent_o = None): """ This function return the agent steps, when deciding to cover the world, spiraling from outside to inside. Note: this coverage method is not optimal! :param agent: the agent covering the world :param board_size: self explanatory :return: list of steps """ next_slot = Slot(agent_r.InitPosX, agent_r.InitPosY) # todo: impreve performance by using extending of lists # start by going toward the closest corner if next_slot.row < board_size / 2: while next_slot.row > 0: self.steps.append(next_slot) next_slot = next_slot.go_north() continue else: while next_slot.row < board_size - 1: self.steps.append(next_slot) next_slot = next_slot.go_south() continue if next_slot.col < board_size / 2: while next_slot.col > 0: self.steps.append(next_slot) next_slot = next_slot.go_west() continue else: while next_slot.col < board_size - 1: self.steps.append(next_slot) next_slot = next_slot.go_east() continue self.steps.append(next_slot) # after reaching the closest-to-start corner, start covering the world, counter clockwise shallow_slots = [[0 for x in range(board_size)] for y in range(board_size)] shallow_slots[next_slot.row][next_slot.col] = 1 dist_from_edge = 0 while dist_from_edge < board_size / 2: if next_slot.row + dist_from_edge < board_size - 1 and next_slot.col == dist_from_edge: direction = 's' elif next_slot.row + dist_from_edge == board_size - 1 and next_slot.col + dist_from_edge < board_size - 1: direction = 'e' elif next_slot.row > dist_from_edge and next_slot.col + dist_from_edge == board_size - 1: direction = 'n' elif next_slot.row == dist_from_edge and next_slot.col + dist_from_edge >= board_size - 1: direction = 'w' if direction == 's': new_slot = next_slot.go_south() elif direction == 'e': new_slot = next_slot.go_east() elif direction == 'n': new_slot = next_slot.go_north() elif direction == 'w': new_slot = next_slot.go_west() if shallow_slots[new_slot.row][new_slot.col] == 1: dist_from_edge += 1 continue else: next_slot = new_slot self.steps.append(next_slot) shallow_slots[next_slot.row][next_slot.col] = 1 return self.steps