#env.makeFood(20,20);
env.updateMap()

#Create Animat
#a = Animat(0,0,env, filename)

# This should really be inside the animat class, since that's the one that'll make
# a decision on what action to take.


actions = ['north','south','east','west','stay','eat','pickup','drop'];
#state = getState();


for i in range(0,300):
	env.tick()
	#a.tick()
	# Show animat on map, which we'll display
	#env.map[a.y,a.x] = env.map.max();

env.tick()

print 'Finished!'

def getState(self):
	# Pick 1 or 0 for each state, add to total,
	# then shift total << 
	
	# temp states, just for example
	# in reality, this stuff will come from the animat itself
	energyThreshold = 80;
Beispiel #2
0
#Init Environment and food sources
env = Env(50)
for i in range(0, 10):
    env.makeFoodRandom()
    #env.makeFood(20,20);
env.updateMap()

#Create Animat
ID = 1
a = Animat(0, 0, env, filename, 1)

fig = plt.figure()
ims = []
for i in range(0, 1000):
    print "Tick: " + str(i)
    env.tick()
    if a.alive:
        a.tickStateMachine()
    env.map[a.y, a.x] = env.map.max()
    im = plt.imshow(env.map)
    im.set_cmap('spectral')
    ims.append([im])

env.tick()

print 'Finished ticking'

ani = animation.ArtistAnimation(fig, ims, interval=10, blit=True, repeat=False)
plt.colorbar()
plt.show()
Beispiel #3
0
	env1.makeFoodRandom();
	env2.makeFoodRandom();
env1.updateMap()
env2.updateMap()

animats = [Animat(25,25,[env1,env2],filename),Animat(10,40,[env1,env2],filename)];

stateMachine = ['notholding','notholding'];

fig = plt.figure()
ims = []

toEat = [random.randrange(0,2),random.randrange(0,2)];
toFollow = [0 if toEat == 1 else 1,0 if toEat == 1 else 1];
for i in range(0,1000):
	env1.tick()
	env2.tick()
	for index,a in enumerate(animats):
		if stateMachine[index] == 'fail':
			toEat[index] = random.randrange(0,2);
			toFollow[index] = 0 if toEat == 1 else 1;
			stateMachine[index] = 'notholding';
		stateMachine[index] = a.followGradient(stateMachine[index],
			toEat[index],toFollow[index]);
		#print str(stateMachine)
		env1.map[a.y,a.x] = env1.map.max();
		env2.map[a.y,a.x] = env2.map.max();
	#if i % 100 == 0:
	print 'Tick: '+str(i);
	im = plt.imshow(env1.map+env2.map)
	im.set_cmap('spectral');
print 'Running Simulation 4 - Food generator test'
mapSize = 100
food = Env(mapSize)
#a = Animat.randomStart(mapSize,mapSize)
food.makeGradient()
print 'Made gradient.'

food.addFoodGenerator(20,20,10)
food.addFoodGenerator(90,50,50)
food.addFoodGenerator(25,88,200)

ims = []
fig = plt.figure()
for iterations in range(0,1000):
	food.tick()
	# animation
	im = plt.imshow(food.map)
	ims.append([im])
	if (iterations % 100 == 0):
		print 'Iteration: '+str(iterations)
	
food.addFoodGenerator(45,75,5)
for iterations in range(1000,2000):
	food.tick()
	# animation
	im = plt.imshow(food.map)
	ims.append([im])
	if (iterations % 100 == 0):
		print 'Iteration: '+str(iterations)