diff --git a/DOCUMENTATION b/DOCUMENTATION index e32722a..853d4f0 100644 --- a/DOCUMENTATION +++ b/DOCUMENTATION @@ -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 diff --git a/cells.py b/cells.py index f86f5a9..855db8a 100755 --- a/cells.py +++ b/cells.py @@ -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 @@ -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, @@ -739,3 +756,5 @@ def main(): game = Game(bounds, mind_list, symmetric, -1) while game.winner is None: game.tick() + + \ No newline at end of file diff --git a/minds/dennis.py b/minds/dennis.py new file mode 100644 index 0000000..3665d88 --- /dev/null +++ b/minds/dennis.py @@ -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)) ) diff --git a/minds/dennisQUIET.py b/minds/dennisQUIET.py new file mode 100644 index 0000000..617311a --- /dev/null +++ b/minds/dennisQUIET.py @@ -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)) ) diff --git a/tests/test_cells.py b/tests/test_cells.py new file mode 100644 index 0000000..15a9629 --- /dev/null +++ b/tests/test_cells.py @@ -0,0 +1,11 @@ +import unittest + +class TestCells(unittest.TestCase): + def setUp(self): + true + + + # TODO: add unit tests + +if __name__ == '__main__': + unittest.main()