File: Memory.py

package info (click to toggle)
cyphesis-cpp 0.5.16-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 5,084 kB
  • ctags: 3,627
  • sloc: cpp: 30,418; python: 4,812; xml: 4,674; sh: 4,118; makefile: 902; ansic: 617
file content (35 lines) | stat: -rw-r--r-- 1,213 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#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)