From 362d964e4b312c96c789962682378dd33d59369f Mon Sep 17 00:00:00 2001 From: RectangleTangle Date: Wed, 4 Apr 2012 17:05:02 -0700 Subject: [PATCH 1/5] Reloads modules with the key command. --- cells.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/cells.py b/cells.py index f86f5a9..fc30786 100755 --- a/cells.py +++ b/cells.py @@ -306,6 +306,21 @@ def run_agents(self): 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 +335,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 +757,7 @@ def main(): game = Game(bounds, mind_list, symmetric, -1) while game.winner is None: game.tick() + + + +#/home/rectangletangle/cells/minds/mind1.py From 07d1cded9f22a92ce9c025e7d3e1c31e0bcd8b98 Mon Sep 17 00:00:00 2001 From: Scott Date: Wed, 4 Apr 2012 17:23:57 -0700 Subject: [PATCH 2/5] fixed documentation minal mind --- DOCUMENTATION | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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 From 691f13e98237f0d5769292e0a4936d2438b22d85 Mon Sep 17 00:00:00 2001 From: Dennis Marwood Date: Wed, 4 Apr 2012 17:26:55 -0700 Subject: [PATCH 3/5] added a couple of simple minds --- minds/dennis.py | 30 ++++++++++++++++++++++++++++++ minds/dennisQUIET.py | 20 ++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 minds/dennis.py create mode 100644 minds/dennisQUIET.py 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)) ) From e5fb3bbb4b59f950209f665c81bc37653900eb51 Mon Sep 17 00:00:00 2001 From: RectangleTangle Date: Wed, 4 Apr 2012 18:01:05 -0700 Subject: [PATCH 4/5] A bit of cleanup. --- cells.py | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/cells.py b/cells.py index fc30786..855db8a 100755 --- a/cells.py +++ b/cells.py @@ -305,22 +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] - - + ''' 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 @@ -336,8 +335,8 @@ def tick(self): elif event.key == pygame.locals.K_a: self.show_agents = not self.show_agents elif event.key == pygame.locals.K_r: - self.reload_minds() - + self.reload_minds() + elif event.type == pygame.locals.MOUSEBUTTONUP: if event.button == 1: print self.agent_map.get(event.pos[0]/2, @@ -758,6 +757,4 @@ def main(): while game.winner is None: game.tick() - - -#/home/rectangletangle/cells/minds/mind1.py + \ No newline at end of file From ded037fff8f4c231cf242dc67c8da87886bee52b Mon Sep 17 00:00:00 2001 From: Russ Date: Wed, 4 Apr 2012 22:50:15 -0700 Subject: [PATCH 5/5] added (non-working) unit test file and folder --- tests/test_cells.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 tests/test_cells.py 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()