Skip to content

Commit

Permalink
Move Memory class to inherting
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix Kolbe committed Jan 9, 2014
1 parent 81086ca commit f4b8ed6
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 34 deletions.
33 changes: 2 additions & 31 deletions goap/src/goap/goap.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,36 +33,6 @@



class Memory(object):

def __init__(self):
self._memory = {}

def __repr__(self):
return '<Memory %s>' % self._memory

def declare_variable(self, name, value=None):
if name not in self._memory:
self._memory[name] = value

def get_value(self, name):
return self._memory[name]

def set_value(self, name, value):
self._memory[name] = value

# def matches(self, memory):
# for (k, v) in self._memory.iteritems():
# if k in memory._memory and memory._memory[k] != v:
# return False
# return True


# def __call__(self):
# return self
# NOTE: cleanup Memory singleton
# Memory = Memory()



class WorldState(object):
Expand Down Expand Up @@ -134,10 +104,11 @@ def get(cls, name):

@classmethod
def print_dict(cls):
return '<Conditions: %s>' % cls._conditions_dict
return '<Conditions %s>' % cls._conditions_dict

@classmethod
def initialize_worldstate(cls, worldstate):
"""Initialize the given worldstate with all known conditions and their current values."""
for condition in cls._conditions_dict.values():
condition.update_value(worldstate)

Expand Down
34 changes: 33 additions & 1 deletion goap/src/goap/inheriting.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,38 @@
from goap import *


class Memory(object):
"""ATM a class to store condition data not representing real world."""

def __init__(self):
self._memory = {}

def __repr__(self):
return '<Memory %s>' % self._memory

def declare_variable(self, name, value=None):
if name not in self._memory:
self._memory[name] = value

def get_value(self, name):
return self._memory[name]

def set_value(self, name, value):
self._memory[name] = value

# def matches(self, memory):
# for (k, v) in self._memory.iteritems():
# if k in memory._memory and memory._memory[k] != v:
# return False
# return True


# def __call__(self):
# return self
# NOTE: cleanup Memory singleton
# Memory = Memory()


#class MemoryAction(Action):
#
# def __init(self, memory, preconditions, effects):
Expand Down Expand Up @@ -108,7 +140,7 @@ def __init__(self, memory, variable):
memory.declare_variable(self._state_name)

def __repr__(self):
return '<MemoryCondition: var=%s>' % self._variable
return '<MemoryCondition var=%s>' % self._variable

def get_value(self):
return self._memory.get_value(self._state_name)
Expand Down
2 changes: 1 addition & 1 deletion goap/test/GOAPTestMemory.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def testPlannerNeg(self):
self.assertIsNone(plan, 'There should be no plan')

def testPlannerNegPos(self):
"""Atm this happens to fail easily as the planner randomly follows up and downs
"""Atm this happens to fail easily as the planner randomly follows up and down actions.
action benefits needed..
"""
print '==', self.testPlannerPos.__name__
Expand Down
3 changes: 2 additions & 1 deletion goap/test/MemoryTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

import unittest

from goap.goap import Memory
from goap.inheriting import Memory


class MemoryTest(unittest.TestCase):
Expand Down Expand Up @@ -61,6 +61,7 @@ def test_declare_none_after_value(self):
self.assertEqual(self.mem.get_value(name), value, 'Memory variable not consistent')


@unittest.skip('removed feature')
class MemoryTestSingletons(unittest.TestCase):

def setUp(self):
Expand Down

0 comments on commit f4b8ed6

Please sign in to comment.