-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpheromone-driver.py
More file actions
33 lines (23 loc) · 820 Bytes
/
pheromone-driver.py
File metadata and controls
33 lines (23 loc) · 820 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from pheromone import pheromone
import numpy as np
import moves
import random
from mapworks import visualization
np.set_printoptions(formatter={'float': lambda x: "{0:0.3f}".format(x)})
def getObstacleData(size,prob):
return np.random.choice(a=[False, True], size=(size,size), p=[1-prob, prob])
def addEnemy():
x = random.randint(0,19)
y = random.randint(0,19)
print("Enemy added:" ,x, y)
ph.addEnemy(x,y)
obstacles = getObstacleData(20,0.1)
ph = pheromone(obstacles,moves.adjacent_octile(),decayRate=0,dropOff=0.0)
for i in range(40):
addEnemy()
for turn in range(10):
if(turn%1 == 0):
addEnemy()
# TODO: make sure directory exists
visualization.saveColorGradedMap("pheromone-sample/{}".format(turn),ph.map,underRange=(0.,0.,1.))
ph.propogate()