138 lines
6.5 KiB
Python
138 lines
6.5 KiB
Python
import ActionAgent
|
|
import random
|
|
|
|
# SchoolActionAgent class inherits from ActionAgent class and is used to perform actions on a target agent.
|
|
|
|
class SchoolActionAgent(ActionAgent.ActionAgent):
|
|
|
|
location_enums = {
|
|
"home": 0,
|
|
"school": 1,
|
|
"work": 2,
|
|
"OHOP": 3,
|
|
}
|
|
|
|
actions = {
|
|
'study': ActionAgent.ActionAgent_Action('study', {'purpose': 2, 'bored': 2, 'tired': 1, 'accomplished': 2, 'lazy': -2}, 10),
|
|
'work': ActionAgent.ActionAgent_Action('work', {'money': 5, 'bored': 2, 'tired': 1, 'accomplished': 2, 'lazy': -2}, 15),
|
|
'socialize': ActionAgent.ActionAgent_Action('socialize', {'lonely': -2, 'bored': -1, 'sad': -1}, 10),
|
|
'exercise': ActionAgent.ActionAgent_Action('exercise', {'tired': 3, 'hungry': 2, 'accomplished': 2, 'lazy': -4}, 15),
|
|
'relax': ActionAgent.ActionAgent_Action('relax', {'bored': 2, 'tired': -1, 'sad': -1, 'accomplished': -1}, 25),
|
|
'eat': ActionAgent.ActionAgent_Action('eat', {'hungry': -5, 'tired': 1, 'sad': -1}, 10),
|
|
'sleep': ActionAgent.ActionAgent_Action('sleep', {'tired': -5, 'accomplished': -1, 'sad': -1}, 60),
|
|
'party': ActionAgent.ActionAgent_Action('party', {'bored': -2, 'lonely': -2, 'tired': 2, 'hungry': 2, 'money': -35}, 30),
|
|
}
|
|
|
|
actionsAvailableAtLocation = {
|
|
"home": ['eat', 'sleep', 'relax'],
|
|
"school": ['study', 'socialize', 'exercise'],
|
|
"work": ['socialize', 'work'],
|
|
"OHOP": ['socialize', 'party']
|
|
}
|
|
|
|
statBasedActions = {
|
|
"hungry": ['eat'],
|
|
"tired": ['sleep', 'relax'],
|
|
"bored": ['study', 'work', 'socialize', 'exercise', 'relax', 'party'],
|
|
"lonely": ['socialize', 'party'],
|
|
"sad": ['socialize', 'party', 'relax'],
|
|
"money": ['work', 'study'],
|
|
"accomplished": ['study', 'work', 'exercise'],
|
|
"lazy": ['study', 'work', 'exercise'],
|
|
"frustrated": ['study', 'work', 'exercise'],
|
|
"purpose": ['study', 'work', 'exercise'],
|
|
}
|
|
|
|
# List order is priority order for the stats
|
|
# cutoff is the max value for the stat which it will be triggered
|
|
statLimitsAndPriorities = {
|
|
"hungry": 10,
|
|
"tired": 12,
|
|
"bored": 8,
|
|
"money": 100,
|
|
"lonely": 10,
|
|
"sad": 10,
|
|
"frustrated": 10,
|
|
"lazy": 10,
|
|
"accomplished": 10,
|
|
"purpose": 10,
|
|
}
|
|
|
|
# 24 entries, one for each hour of the day
|
|
# 0000, 0100, 0200, 0300, 0400, 0500,
|
|
# 0600, 0700, 0800, 0900, 1000, 1100,
|
|
# 1200, 1300, 1400, 1500, 1600, 1700,
|
|
# 1800, 1900, 2000, 2100, 2200, 2300
|
|
schedule = {
|
|
"Sunday": ['home','home','home','home','home','home',
|
|
'home','home','work','work','work','work',
|
|
'work','work','work','work','work','work',
|
|
'work','home','home','home','home','home'],
|
|
"Monday": ['home','home','home','home','home','home',
|
|
'home','home','school','school','school','school',
|
|
'school','school','school','school','school','school',
|
|
'school','home','home','home','home','home'],
|
|
"Tuesday": ['home','home','home','home','home','home',
|
|
'home','home','school','school','school','school',
|
|
'school','school','school','school','school','school',
|
|
'school','home','home','home','home','home'],
|
|
"Wednesday": ['home','home','home','home','home','home',
|
|
'home','home','school','school','school','school',
|
|
'school','school','school','school','school','school',
|
|
'school','home','home','home','home','home'],
|
|
"Thursday": ['home','home','home','home','home','home',
|
|
'home','home','school','school','school','school',
|
|
'school','school','school','school','school','school',
|
|
'school','home','OHOP','OHOP','OHOP','OHOP'],
|
|
"Friday": ['home','home','home','home','home','home',
|
|
'home','home','school','school','school','school',
|
|
'school','school','school','school','school','school',
|
|
'school','home','OHOP','OHOP','OHOP','OHOP'],
|
|
"Saturday": ['home','home','home','home','home','home',
|
|
'home','home','home','home','home','home',
|
|
'home','home','home','home','home','home',
|
|
'home','home','home','home','home','home']
|
|
}
|
|
|
|
# Update Target Agent on Each Run
|
|
def update(self, curtime):
|
|
self.target.update_action(curtime)
|
|
if self.target.is_idle():
|
|
# Evaluate according to current location
|
|
currentLocation = self.schedule[curtime.day_of_week()][curtime.hour()]
|
|
|
|
self.target.get_stat('location').index = self.location_enums[currentLocation]
|
|
|
|
locationActions = self.actionsAvailableAtLocation[currentLocation]
|
|
|
|
# Evaluate according to current stats
|
|
for statName in self.statLimitsAndPriorities:
|
|
# If the stat is above the threshold, perform an action based on the stat name
|
|
# and the current location of the target agent
|
|
if self.target.get_stat(statName).get_value() >= self.statLimitsAndPriorities[statName]:
|
|
# Get the list of actions that can be performed based on the stat name
|
|
actions = self.statBasedActions[statName]
|
|
|
|
# Find the intersection of the two lists to get the available actions
|
|
availableActions = list(set(actions) & set(locationActions))
|
|
|
|
# If there are available actions, choose one at random and perform it
|
|
if len(availableActions) > 0:
|
|
action = self.actions[random.choice(availableActions)]
|
|
action.act(self.target, curtime)
|
|
return
|
|
# If no stat-based action is performed, perform a location-based action
|
|
if len(locationActions) > 0:
|
|
action = self.actions[random.choice(locationActions)]
|
|
action.act(self.target, curtime)
|
|
return
|
|
|
|
# Initializes the Target Agent's Stats
|
|
# This particular agent can start at any random point
|
|
# as any day for a college student could be like any other
|
|
def stat_init(self):
|
|
for stat in self.stats:
|
|
randomStart = random.randint(0, len(self.stats[stat]) - 1)
|
|
self.target.change_stat(stat, randomStart)
|
|
|
|
|