Skip to content

Commit cb0d60e

Browse files
author
lsampras
committed
updated for compatibility with newer point implementation
1 parent ea86b73 commit cb0d60e

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

pheromone-driver.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from pheromone import pheromone
22
import numpy as np
3-
import next_moves
3+
import moves
44
import random
55
np.set_printoptions(formatter={'float': lambda x: "{0:0.3f}".format(x)})
66

@@ -14,7 +14,7 @@ def addEnemy():
1414
ph.addEnemy(x,y)
1515

1616
obstacles = getObstacleData(20,0.1)
17-
ph = pheromone(obstacles,next_moves.adjacent_octile(),decayRate=0,dropOff=0.0)
17+
ph = pheromone(obstacles,moves.adjacent_octile(),decayRate=0,dropOff=0.0)
1818

1919
for i in range(40):
2020
addEnemy()

pheromone.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
import matplotlib.pyplot as plt
33
from matplotlib import colors
44
import matplotlib as mpl
5+
from point import Point
56
class pheromone(object):
67
def __init__(self,obstacleData,possible_moves,decayRate = 0.7,dropOff = 0.1):
78
# initialize map size of obstacles and set obstacles position as -1
89
self.map = np.zeros(shape = obstacleData.shape, dtype = np.float32) - obstacleData
910
self.obstacleData = obstacleData
1011
self.dropOff = dropOff
1112
self.moves = possible_moves
12-
self.moves.append((0,0))
13+
self.moves.append(Point(0,0))
1314
self.multiplier = (1 - decayRate) #normalize
1415
self.temp = np.zeros(shape = self.map.shape,dtype = np.float32)
1516
self.cmap = mpl.cm.Reds
@@ -20,6 +21,10 @@ def __init__(self,obstacleData,possible_moves,decayRate = 0.7,dropOff = 0.1):
2021
def addEnemy(self,x,y):
2122
self.map[x][y] = 1.0
2223

24+
25+
def decay(self):
26+
self.map = self.map*self.multiplier
27+
2328
def propogate(self):
2429
for i,rows in enumerate(self.map):
2530
for j,value in enumerate(rows):
@@ -34,8 +39,8 @@ def propogate_point(self,value,x,y):
3439
delta = 0
3540
changes = []
3641
for move in self.moves:
37-
finalx = x + move[0]
38-
finaly = y + move[1]
42+
finalx = x + move.x
43+
finaly = y + move.y
3944
if(finalx >= 0 and finalx < self.map.shape[0]):
4045
if(finaly >= 0 and finaly < self.map.shape[1]):
4146
if(self.obstacleData[finalx][finaly] == False):

0 commit comments

Comments
 (0)