print 'Running Simulation - Moving food around, picking up, dropping' # Deprecated filename = 'nn_precise_100k.p' size = 50; env1 = Env(size,0) env2 = Env(size,1); for i in range (0,20): 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;
Env(mapsize, foodTypes[0]), Env(mapsize, foodTypes[1]), Env(mapsize, foodTypes[2]), Env(mapsize, foodTypes[3]) ] for e in env: e.makeGradient() for i in range(0, 100): e.makeFoodRandom() e.updateMap() animats = [] for a in range(0, 20): animats.append( Animat(random.randrange(0, mapsize), random.randrange(0, mapsize), env, foodTypes, 1500, 1000)) fig = plt.figure() ims = [] toPlot = zeros((mapsize, mapsize)) Animat.foodTargeting = False Animat.allowDeath = False trainingTicks = 10000 # Training session for i in range(0, trainingTicks): for e in env: e.tick() Animat.startTick() for a in animats: stillAlive = a.tick() if not stillAlive:
matplotlib.use('TKAgg') import sys sys.path.append("..") from Environment.Env import Env from Animat.Animat import Animat import time from numpy import zeros import random import matplotlib.pyplot as plt import matplotlib.animation as animation print 'Running Simulation 2' mapSize = 15 food = Env(mapSize) a = Animat.randomStart(mapSize, mapSize) food.makeGradient() for iteration in range(1, 10): # Pick a random spot foody = random.randrange(0, mapSize) foodx = random.randrange(0, mapSize) print str(foody) + ' ' + str(foodx) food.map[foody, foodx] = 5 # random number # pass animat object our map # food = a.goToLocation(foody,foodx,food) # animat should behave appropriately # it should return the map unmodified # check to see if the animat did the right thing
e.updateMap() animats = []; for a in range(0,20): animats.append(Animat(random.randrange(0,mapsize),random.randrange(0,mapsize),env,foodTypes,1500,1000)); #fig = plt.figure() #ims = [] #toPlot = zeros((mapsize,mapsize)); Animat.allowDeath = False trainingTicks = 7000 # Training session for i in range(0,trainingTicks): for e in env: e.tick() Animat.startTick() for a in animats: stillAlive = a.tick() if not stillAlive: print a.energy for e in env: #e.map[a.y,a.x] = e.map.max() if e.map.max() > 0 else 1; e.binaryGradient[a.y,a.x] = e.binaryGradient.max() if e.binaryGradient.max() > 0 else 1; #e.simpleMap[a.y,a.x] = e.simpleMap.max() if e.simpleMap.max() > 0 else 1; #e.simpleMap[a.y,a.x] = 10; #toPlot[a.y,a.x] = 5; #print "e.simpleMap.max() is :"+str(e.simpleMap.max()); Animat.endTick() if i % 100 == 0: #for e in env: #im = plt.imshow(env[0].map+env[1].map)
from Environment.Env import Env from Animat.Animat import Animat from Animat.NNInitializer import NNInitializer import time from numpy import zeros import random import matplotlib.pyplot as plt import matplotlib.animation as animation if len(sys.argv) < 2: print "Filename required for neural net" exit() print 'Running Animat Simulations' #Load initial Neural Net filename = sys.argv[1] #Init Environment and food sources env = Env(250) env.makeGradient() for i in range(1, 2): env.makeFoodRandom() env.updateMap() #Create Animat a = Animat(0, 0, env, filename) while (1): a.tick()
import matplotlib.animation as animation print 'Running Simulation - Find food' #filename = 'nn_scents_based.p' filename = 'nn_precise_100k.p' #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()
import sys sys.path.append("..") from Environment.Env import Env from Animat.Animat import Animat import time from numpy import zeros import random import matplotlib.pyplot as plt import matplotlib.animation as animation print "Running Simulation 1" mapSize = 20 env = Env(mapSize) a = Animat.randomStart(mapSize, mapSize) # Create figure for plotting our environment fig = plt.figure() ims = [] # Walk around the map randomly, for 100 iterations for t in range(1, 100): # time.sleep(.05) # print 'Time: '+str(t) # Pick a random spot to move to randomSpot = random.randrange(1, 4 + 1) if randomSpot == 1: # north if env.canMove(a.y, a.x, a.y - 1, a.x):
print 'Running Simulation - Find food' #filename = 'nn_scents_based.p' filename = 'nn_precise_100k.p' #Init Environment and food sources env = [Env(50, 0), Env(50, 1)] for e in env: e.makeGradient() for i in range(0, 100): e.makeFoodRandom() e.updateMap() #Create Animat animats = [ Animat(25, 25, env, filename), Animat(10, 40, env, filename), Animat(45, 10, env, filename), Animat(30, 40, env, filename) ] fig = plt.figure() ims = [] for i in range(0, 50000): for e in env: e.tick() for a in animats: a.tick() for e in env: e.map[a.y, a.x] = e.map.max() if i % 100 == 0:
from Animat.Animat import Animat from Animat.NNInitializer import NNInitializer import time from numpy import zeros import random import matplotlib.pyplot as plt import matplotlib.animation as animation if len(sys.argv) < 2: print "Filename required for neural net" exit() print 'Running Animat Simulations' #Load initial Neural Net filename = sys.argv[1] #Init Environment and food sources env = Env(250) env.makeGradient() for i in range (1, 2): env.makeFoodRandom() env.updateMap() #Create Animat a = Animat(0,0,env, filename) while(1): a.tick()
#Init Environment and food sources foodTypes = [0,1,2,3]; mapsize = 100; env = [Env(mapsize,foodTypes[0]),Env(mapsize,foodTypes[1]), Env(mapsize,foodTypes[2]),Env(mapsize,foodTypes[3])]; for e in env: e.makeGradient() for i in range (0,100): e.makeFoodRandom() e.updateMap() animats = []; numAnimats = 20; for a in range(0,numAnimats): animats.append(Animat(random.randrange(0,mapsize),random.randrange(0,mapsize),env,foodTypes)); Animat.allowDeath = False; fig = plt.figure() ims = [] toPlot = zeros((mapsize,mapsize)); # Training session for i in range(0,15000): for e in env: e.tick() Animat.startTick() for a in animats: a.tick() for e in env: e.binaryGradient[a.y,a.x] = e.binaryGradient.max() if e.binaryGradient.max() > 0 else 1;
Env(mapsize, foodTypes[0]), Env(mapsize, foodTypes[1]), Env(mapsize, foodTypes[2]), Env(mapsize, foodTypes[3]) ] for e in env: e.makeGradient() for i in range(0, 100): e.makeFoodRandom() e.updateMap() animats = [] numAnimats = 20 for a in range(0, numAnimats): animats.append( Animat(random.randrange(0, mapsize), random.randrange(0, mapsize), env, foodTypes)) Animat.allowDeath = True fig = plt.figure() ims = [] toPlot = zeros((mapsize, mapsize)) # Training session for i in range(0, 7000): for e in env: e.tick() for a in animats: a.tick() for e in env: e.binaryGradient[a.y, a.x] = e.binaryGradient.max( ) if e.binaryGradient.max() > 0 else 1
] for e in env: e.makeGradient() for i in range(0, 100): e.makeFoodRandom() e.updateMap() fig = plt.figure() ims = [] toPlot = zeros((mapsize, mapsize)) animats = [] deadAnimats = [] for a in range(0, 20): animats.append( Animat(random.randrange(0, mapsize), random.randrange(0, mapsize), env, foodTypes, 1000, 500)) Animat.allowDeath = False # Training session for i in range(0, 9000): for e in env: e.tick() for a in animats: isAlive = a.tick() if not isAlive: animats.remove(a) deadAnimats.append(a) if len(animats) <= 0: print "All animats dead" break #for e in env:
import matplotlib.animation as animation print 'Running Simulation - Find food' #filename = 'nn_scents_based.p' filename = 'nn_precise_100k.p' #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()