-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdifficulty_controller.py
More file actions
53 lines (37 loc) · 1.39 KB
/
difficulty_controller.py
File metadata and controls
53 lines (37 loc) · 1.39 KB
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
class DifficultyController:
"""
Adjusts world difficulty based on agent performance trends.
"""
def __init__(self, config):
self.config = config
self.history = []
self.difficulty = 1.0 # baseline
# =====================================================
# UPDATE SIGNAL
# =====================================================
def observe(self, performance_score):
self.history.append(performance_score)
if len(self.history) > 50:
self.history.pop(0)
self._update_difficulty()
# =====================================================
# COMPUTE ADJUSTMENT
# =====================================================
def _update_difficulty(self):
if not self.history:
return
avg = sum(self.history) / len(self.history)
# target band: agents should not dominate or collapse
target = 1.0
# bounded adjustment
if avg > target + 0.2:
self.difficulty += 0.05 # world gets harder
elif avg < target - 0.2:
self.difficulty -= 0.05 # world gets easier
# clamp
self.difficulty = max(0.5, min(3.0, self.difficulty))
# =====================================================
# GET CURRENT DIFFICULTY
# =====================================================
def get(self):
return self.difficulty