Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions DOCUMENTATION
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ the only thing absolutely required for a mind that doesn't instantly
lose is this:

class AgentMind:
def act(self, view, msg):
return cells.Action(cells.ACT_EAT)
def __init__(self, junk):
self.my_plant = None

def act(self, view, msg):
return cells.Action(cells.ACT_EAT)


Minds can have other class methods to assist in writing the act
Expand Down
21 changes: 20 additions & 1 deletion cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,21 @@ def run_agents(self):
self.winner = -1

self.agent_map.unlock()


def reload_minds (self) :
''' Attempts to reload the mind modules. '''
for mind in self.mind_list :
mindmodule = mind[1]

try :
reload(mindmodule)
print '%s was reloaded.' % str(mind)
except :
print '%s failed to reload.' % str(mind)


self.minds = [m[1].AgentMind for m in self.mind_list]

def tick(self):
if not self.headless:
# Space starts new game
Expand All @@ -320,6 +334,9 @@ def tick(self):
self.show_energy = not self.show_energy
elif event.key == pygame.locals.K_a:
self.show_agents = not self.show_agents
elif event.key == pygame.locals.K_r:
self.reload_minds()

elif event.type == pygame.locals.MOUSEBUTTONUP:
if event.button == 1:
print self.agent_map.get(event.pos[0]/2,
Expand Down Expand Up @@ -739,3 +756,5 @@ def main():
game = Game(bounds, mind_list, symmetric, -1)
while game.winner is None:
game.tick()


30 changes: 30 additions & 0 deletions minds/dennis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import random, cells
import math

class AgentMind():
def __init__(self, junk):
pass

def act(self, view, msg):
'''Vars'''
me = view.get_me()
my_pos = (mx,my) = me.get_pos()

for agent in view.get_agents():
#print "Agent!"
pass

'''EAT'''
if (me.energy < 50) :
print "My health is: " + str(me.energy) + " So I am Eating"
return cells.Action(cells.ACT_EAT)

'''SPAWN
#if 0 == random.randrange(0,2) and me.energy > 200:
print "Spawn"
return cells.Action(cells.ACT_SPAWN,(mx+1, my+1, self))
'''

'''MOVE'''
print "I am at X,Y: " + str(me.x) + ", " + str(me.y)
return cells.Action(cells.ACT_MOVE,(mx + 1 + random.randrange(-1,1), my + 1+ random.randrange(-1,1)) )
20 changes: 20 additions & 0 deletions minds/dennisQUIET.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import random, cells
import math

class AgentMind():
def __init__(self, junk):
self.x = 1
pass

def act(self, view, msg):
me = view.get_me()
my_pos = (mx,my) = me.get_pos()

for agent in view.get_agents():
#print "Agent!"
pass

if (me.energy < 50) :
return cells.Action(cells.ACT_EAT)

return cells.Action(cells.ACT_MOVE,(mx + 1 + random.randrange(-1,1), my + 1+ random.randrange(-1,1)) )
11 changes: 11 additions & 0 deletions tests/test_cells.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import unittest

class TestCells(unittest.TestCase):
def setUp(self):
true


# TODO: add unit tests

if __name__ == '__main__':
unittest.main()