-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
128 lines (106 loc) · 4.17 KB
/
models.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import random
from enum import Enum
class Thing:
'''A base class for all objects in the simulation.'''
def __init__(self, name):
'''
:param name: The name of the thing.
:type name: str
'''
self.name = name # type: str
def __eq__(self, other):
if not type(self) is type(other):
return False
return self.name == other.name
def __hash__(self):
return hash(self.name)
def __ne__(self, other):
return not(self == other)
def __str__(self):
return self.name
class Object(Thing):
'''An object during the simulation that can be found by characters.'''
def __init__(self, name, location=None, owner=None):
'''
:param name: The name of the object.
:type name: str
:param location: The location of the object. Defaults to None.
:type location: str
:param owner: The character who owns the object or None if the object has no owner. Defaults to None.
:type owner: Character
'''
Thing.__init__(self, name)
#assert owner is None or isinstance(owner, Character)
self.location = location # type: str
self.owner = owner # type: Character
class Location(Thing):
'''Each character exists at some location at any point of time'''
def __init__(self, name):
Thing.__init__(self, name)
class Knowledge:
'''Piece of knowledge that a character has and may spread to other characters through conversation'''
def __init__(self, source, subject, action, target, timestamp, value = 0):
'''Knowledge format: SOURCE told me that SUBJECT performed ACTION on TARGET'''
self.source = source # type: Character. Character that gave this information
self.subject = subject # type: Character
self.action = action # type: Actions
self.target = target # type: Character
self.timestamp = timestamp # type: int
self.value = value # type: float. Auxillary numerical value, currently used with LIKES action to tell the value of relationship
def equality_tuple(self):
return (self.subject, self.action, self.target, self.timestamp, self.value)
def __eq__(self, other):
return self.equality_tuple() == other.equality_tuple()
def __hash__(self):
return hash(self.equality_tuple())
def __ne__(self, other):
return not(self == other)
def importantKnowledge(self):
return self.action in [Actions.KILL, Actions.BEAT_UP, Actions.INSULT, Actions.OWNED_BY]
class Actions(Enum):
'''Enumeration of rudimentary actions characters can perform and can be witnessed and stored as knowledge'''
KILL = "killed"
BEAT_UP = "beat up"
INSULT = "insulted"
CONVERSE = "conversed with"
LOCATED_IN = "located in"
NOT_LOCATED_IN = "not located in"
OWNED_BY = "owned by"
LIKES = "likes"
NONE = "none"
'''These actions can be witnessed by other characters at the same location'''
@property
def is_witnessed(self):
if self in [Actions.KILL, Actions.BEAT_UP]:
return True
else:
return False
'''
Knowledge with this action is discarded if knowledge recepient is target of the knowledge
eg If I got beat up, someone telling me about it does not make a difference
'''
@property
def ignore_if_self_is_target(self):
return self in [Actions.KILL, Actions.BEAT_UP, Actions.OWNED_BY]
@property
def react_badly_if_conflicting_subjects(self):
return self in [Actions.KILL, Actions.BEAT_UP]
@property
def react_badly_if_conflicting_targets(self):
return False
'''Receiving knowledge with these actions should be always put into the story'''
@property
def importantEvent(self):
return self in [Actions.KILL, Actions.BEAT_UP, Actions.INSULT]
'''Types of motivation a character can have'''
class GoalType(Enum):
GET_OBJECT = 1
BEFRIEND = 2
KILL = 3
NONE = 4
class Goal:
'''Represents the goals of characters between each other'''
def __init__(self, type, target1 = None, target2 = None):
self.type = type # type: GoalType
self.target1 = target1 # type: Character
self.target2 = target2 # type: Character