cyphesis/rulesets/basic/mind/Memory.py
Al Riddoch 6453493c6f 2006-07-11 Al Riddoch <alriddoch@zepler.org>
* rulesets/BaseMind.cpp, rulesets/MemMap.cpp, rulesets/MemMap.h:
	  Remove commented out lookId code. Re-write findByLocation to
	  require a type as well, and use a more efficient search to find
	  the entities requested.

	* rulesets/Py_Map.cpp: Re-write find_by_location wrapper to handle
	  the extra type argument.

	* rulesets/basic/mind/Memory.py: Re-write recall_place so that
	  type and radius are now required, and make sure all types listed
	  are checked for.

	* rulesets/basic/mind/goals/common/move.py: Check if recall_place
	  has returned anything at all.
2006-07-11 17:42:22 +00:00

35 lines
1.2 KiB
Python

#This file is distributed under the terms of the GNU General Public license.
#Copyright (C) 1999 Aloril (See the file COPYING for details).
from types import *
class Memory:
def __init__(self, map):
self.events=[]
self.map=map
def destroy(self):
self.events=None
self.map=None
def recall_place(self, location, radius, otype):
if type(otype)==ListType:
for i in otype:
result = self.map.find_by_location(location, radius, i)
if len(result)!=0:
return result
else:
return self.map.find_by_location(location, radius, otype)
def remember_event(self, event):
"add new memory with age"
self.events.append([event,1.0])
def recall_event(self, event, cmp):
"return list of memories with same command"
found=[]
for (e,age) in self.events:
if apply(cmp,(event,e)): found.append(e)
return found
def forget(self):
"age memories and forgot too old ones"
for m in self.events:
m[1]=m[1]-0.1
#remove forgotten things
self.events=filter(lambda m:m[1]>const.fzero,self.events)