Created
May 28, 2024 14:17
-
-
Save LewisGet/a7b9a0105f25f465efa5e3ccd57dc481 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Status: | |
def __init__(self, hunger, health, stamina, age): | |
self._hunger = hunger | |
self._health = health | |
self._stamina = stamina | |
self._age = age | |
class Task: | |
def __init__(self, name, status): | |
self.name = name | |
self.status = status.clone() | |
class TaskHistory: | |
def __init__(self, uuid, task, is_completed, completed_status): | |
self.ower = uuid | |
self.task = task.clone() | |
self.completed = is_completed | |
self.completed_status = completed_status.clone() | |
class TaskScheduler: | |
def __init__(self, status, task_list, task_history, bias=None): | |
self.tasks = task_list | |
self.status = status | |
self.bias = bias if bias else [1.0] * len(task_list) # init bias 1.0 | |
self.history = task_history | |
def add_task(self, task): | |
self.tasks.append(task) | |
self.bias.append(1.0) # 新增任務時,初始化 bias 為 1.0 | |
def update_bias(self): | |
# 根據歷史記錄調整 bias | |
for i, task in enumerate(self.tasks): | |
if task.name in (log.task.name for log in task_history if _task.completed): | |
self.bias[i] *= 1.2 # 成功完成的任務有更高的權重 | |
def get_task(self): | |
# 計算每個任務的加權分數 | |
scores = {} | |
for i, task in enumerate(self.tasks): | |
total_diff = 0 | |
for attr in dir(self.status): | |
if attr.startswith("get"): | |
status_value = getattr(self.status, attr)() | |
task_value = getattr(task.status, attr)() | |
total_diff += abs(status_value - task_value) | |
# 考慮行為偏好(bias)和歷史記錄 | |
total_score = total_diff * self.bias[i] | |
scores[task.name] = total_score | |
# 選擇分數最高的任務 | |
selected_task = max(scores, key=scores.get) | |
return selected_task |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment