コード例 #1
0
ファイル: MustMeet.py プロジェクト: alon/antmeeting
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])
コード例 #2
0
ファイル: MustMeet.py プロジェクト: alon/antmeeting
def move(grid, ant, side, pheromone):
    radius = ant.get_radius()
    location = ant.get_location()
    symbol = ant.get_symbol()
    old_location = grid[location] 
    grid[location] = (old_location[0], EMPTY, old_location[2])    
    new_location = radius[2*side + 1]
    ant.set_location(new_location)        
    set_orientation(ant,side)
    if pheromone == EMPTY:
        grid[new_location] = (grid[new_location][0], ANT, grid[new_location][2])
    else:
        grid[new_location] = (pheromone, ANT, symbol)
コード例 #3
0
ファイル: MustMeet.py プロジェクト: alon/antmeeting
 def is_pheromone_in_radius(self, ant):
     radius = ant.get_radius()
     for i in [1,3,5,7]:
         if (self[radius[i]][2] != ant.get_symbol()) and (self[radius[i]][2] != EMPTY) and (self[radius[i]][2] != OBSTACLE):
             return [radius[i],i]
     return 0
コード例 #4
0
ファイル: MustMeet.py プロジェクト: alon/antmeeting
 def is_ant_in_radius(self, ant):
     radius = ant.get_radius()
     for i in range(0,8):
         if self[radius[i]][1] == ANT:
             return 1
     return 0
コード例 #5
0
ファイル: MustMeet.py プロジェクト: alon/antmeeting
 def is_empty(self,ant,side):
     radius = ant.get_radius()
 #    print self[ant.radius[2*side+1][0],ant.radius[2*side+1][1]]
     if self[radius[2*side+1][0],radius[2*side+1][1]][0] == EMPTY:
         return 1
     return 0    
コード例 #6
0
ファイル: MustMeet.py プロジェクト: alon/antmeeting
 def is_obstacle(self,ant,side):
     radius = ant.get_radius()
     if self[radius[2*side+1][0],radius[2*side+1][1]][0] == OBSTACLE:
         return 1
     return 0