YUS200619 commited on
Commit
7a44bc9
·
verified ·
1 Parent(s): 02e6797

Upload environment/consequences.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. environment/consequences.py +54 -0
environment/consequences.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import replace
4
+ import random
5
+ from typing import Dict
6
+
7
+ from .state import EpisodeState, RelationshipState, clamp01
8
+
9
+
10
+ def _copy_state(state: EpisodeState) -> EpisodeState:
11
+ return replace(
12
+ state,
13
+ relationships=replace(state.relationships),
14
+ decisions=[*state.decisions],
15
+ history=[*state.history],
16
+ )
17
+
18
+
19
+ def apply_action(state: EpisodeState, event_id: str, action_id: str, action_data: Dict) -> EpisodeState:
20
+ new_state = _copy_state(state)
21
+
22
+ new_state.energy = clamp01(state.energy + float(action_data.get("energy_delta", 0.0)))
23
+ new_state.sprint_health = clamp01(state.sprint_health + float(action_data.get("sprint_delta", 0.0)))
24
+
25
+ rel = new_state.relationships
26
+ for person, delta in action_data.get("relationship_delta", {}).items():
27
+ if hasattr(rel, person):
28
+ setattr(rel, person, clamp01(getattr(rel, person) + float(delta)))
29
+ new_state.relationships = RelationshipState(**vars(rel)).clamped()
30
+
31
+ if event_id == "E1_staging" and action_id == "fix_directly":
32
+ new_state.staging_fixed = True
33
+ if event_id == "E4_leave":
34
+ if action_id == "ping_sundar":
35
+ new_state.leave_status = "approved" if random.random() > 0.20 else "pending"
36
+ elif action_id == "cancel_leave":
37
+ new_state.leave_status = "cancelled"
38
+ if event_id == "E5_appraisal" and action_id == "block_wednesday":
39
+ new_state.appraisal_done = True
40
+ if event_id == "E6_oncall" and action_id == "yes_people_pleaser":
41
+ new_state.oncall_accepted = True
42
+
43
+ new_state.decisions.append(
44
+ {
45
+ "day": state.day,
46
+ "event_id": event_id,
47
+ "action_id": action_id,
48
+ "energy_before": state.energy,
49
+ "energy_after": new_state.energy,
50
+ }
51
+ )
52
+
53
+ new_state.history.append(f"{event_id}:{action_id}")
54
+ return new_state.normalized()