-
Notifications
You must be signed in to change notification settings - Fork 4
/
random_adm.py
65 lines (51 loc) · 2.79 KB
/
random_adm.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
import random
from swagger_client.models import ActionTypeEnum, InjuryLocationEnum, CharacterTagEnum
from align_system.utils import logging
from align_system.algorithms.abstracts import ActionBasedADM
from align_system.utils import get_swagger_class_enum_values
log = logging.getLogger(__name__)
class RandomADM(ActionBasedADM):
def __init__(self, **kwargs):
pass
def choose_action(self, scenario_state, available_actions, alignment_target, **kwargs):
action_to_take = random.choice(available_actions)
# Action requires a character ID
if action_to_take.action_type in {ActionTypeEnum.APPLY_TREATMENT,
ActionTypeEnum.CHECK_ALL_VITALS,
ActionTypeEnum.CHECK_PULSE,
ActionTypeEnum.CHECK_RESPIRATION,
ActionTypeEnum.MOVE_TO_EVAC,
ActionTypeEnum.TAG_CHARACTER,
ActionTypeEnum.CHECK_BLOOD_OXYGEN}:
if action_to_take.character_id is None:
action_to_take.character_id = random.choice([
c.id
for c in scenario_state.characters
if hasattr(c, "unseen") and not c.unseen
])
if action_to_take.action_type == ActionTypeEnum.APPLY_TREATMENT:
if action_to_take.parameters is None:
action_to_take.parameters = {}
if 'treatment' not in action_to_take.parameters:
action_to_take.parameters['treatment'] = random.choice(
[s.type for s in scenario_state.supplies if s.quantity > 0])
if 'location' not in action_to_take.parameters:
action_to_take.parameters['location'] = random.choice(
get_swagger_class_enum_values(InjuryLocationEnum))
elif action_to_take.action_type == ActionTypeEnum.TAG_CHARACTER:
if action_to_take.parameters is None:
action_to_take.parameters = {}
if 'category' not in action_to_take.parameters:
action_to_take.parameters['category'] = random.choice(
get_swagger_class_enum_values(CharacterTagEnum))
# Action requires an aid ID
elif action_to_take.action_type == ActionTypeEnum.MOVE_TO_EVAC:
if "aid_id" not in action_to_take.parameters:
action_to_take.parameters["aid_id"] = random.choice([
aid.id
for aid in scenario_state.environment.decision_environment.aid
])
# Required since Dry Run Evaluation
action_to_take.justification = "Random choice"
choice_info = {}
return action_to_take, choice_info