def follow_arrow (grid, ant): radius = ant.get_radius() orientation = ant.get_orientation() location = ant.get_location() old_location = grid[location] grid[location] = (old_location[0], EMPTY, old_location[2]) if grid[location][0] == UP_SYM: # print "up" ant.set_location(radius[(9 - 2*(orientation)) % 8]) force_orientation(ant,UP) elif grid[location][0] == RIGHT_SYM: # print "right" ant.set_location(radius[(11 - 2*(orientation)) % 8]) force_orientation(ant,RIGHT) elif grid[location][0] == DOWN_SYM: # print "down" ant.set_location(radius[(13 - 2*(orientation)) % 8]) force_orientation(ant,DOWN) elif grid[location][0] == LEFT_SYM: # print "left" ant.set_location(radius[(7 - 2*(orientation)) % 8]) force_orientation(ant,LEFT) new_location = ant.get_location() # print "new location is ", new_location grid[new_location] = (grid[new_location][0], ANT, grid[new_location][2])
def get_back_pheromone(ant,move): orientation = ant.get_orientation() if (orientation + move) % 4 == 0: return DOWN_SYM elif (orientation + move) % 4 == 1: return LEFT_SYM elif (orientation + move) % 4 == 2: return UP_SYM elif (orientation + move) % 4 == 3: return RIGHT_SYM
def set_orientation(ant,side): orientation = ant.get_orientation() ant.set_orientation((orientation + side) % 4) ant.set_radius()
def force_orientation(ant,side): orientation = ant.get_orientation() ant.set_orientation(side) ant.set_radius()