迈向规范化任务链编写|Towards canonical task chain-writing #10679
Replies: 6 comments 11 replies
-
素材 +1 共有三个任务了使用模版 Roguelike@StageTraderRefresh.png,但是每个任务都把同样的 roi 和 action 复制了一遍。 原先的任务流为 "Roguelike@StageTraderRefreshWithDice": {
"template": "Roguelike@StageTraderRefresh.png",
"action": "ClickSelf",
"roi": [230, 47, 211, 182],
"next": [
"Roguelike@StageTraderRefreshWithDiceConfirm",
"Roguelike@StageTraderRefreshWithDiceNotAvaiable",
"Roguelike@StageTraderInvestSystem",
"Roguelike@TraderRandomShopping",
"Roguelike@StageTraderLeave"
],
"exceededNext": [
"Roguelike@StageTraderInvestSystem",
"Roguelike@TraderRandomShopping",
"Roguelike@StageTraderLeave"
]
},
"Sami@Roguelike@StageTraderRefresh": {
"template": "Roguelike@StageTraderRefresh.png",
"action": "ClickSelf",
"roi": [230, 73, 212, 141],
"next": ["Sami@Roguelike@StageTraderRefreshConfirm"]
},
"Sarkaz@Roguelike@StageTraderRefresh": {
"template": "Roguelike@StageTraderRefresh.png",
"action": "ClickSelf",
"roi": [230, 73, 212, 141],
"next": ["Sarkaz@Roguelike@StageTraderRefreshConfirm"]
}, 修正后的任务流为 "Roguelike@StageTraderRefresh": {
"roi": [230, 47, 211, 182],
"action": "ClickSelf"
},
"Roguelike@StageTraderRefreshWithDice": {
"baseTask": "Roguelike@StageTraderRefresh",
"template": "Roguelike@StageTraderRefresh.png",
"next": [
"Roguelike@StageTraderRefreshWithDiceConfirm",
"Roguelike@StageTraderRefreshWithDiceNotAvaiable",
"Roguelike@StageTraderInvestSystem",
"Roguelike@TraderRandomShopping",
"Roguelike@StageTraderLeave"
],
"exceededNext": [
"Roguelike@StageTraderInvestSystem",
"Roguelike@TraderRandomShopping",
"Roguelike@StageTraderLeave"
]
},
"Sami@Roguelike@StageTraderRefresh": {
"template": "Roguelike@StageTraderRefresh.png",
"next": ["Sami@Roguelike@StageTraderRefreshConfirm"]
},
"Sarkaz@Roguelike@StageTraderRefresh": {
"template": "Roguelike@StageTraderRefresh.png",
"next": ["Sarkaz@Roguelike@StageTraderRefreshConfirm"]
}, 此外,field 的顺序也应当有讲究。单个任务实际上指定了任务触发的 guard 和任务实际的 action。(此处甚至可以引入 Process Algebra 等形式化验证的内容)roi 参数应为 guard 的一部分。 |
Beta Was this translation helpful? Give feedback.
-
我認為自動化將原本的任務列表规范化任务链编写更現實一點,因為一個一個打太坐牢了 ``` import yaml
# Function to fill in template parameters dynamically
def fill_template_parameters(template, parameters):
for key, value in parameters.items():
placeholder = f"{{{{{key}}}}}"
if isinstance(template, dict):
for k, v in template.items():
if isinstance(v, str) and placeholder in v:
template[k] = v.replace(placeholder, str(value))
elif isinstance(template, str):
template = template.replace(placeholder, str(value))
return template
# Function to normalize task chain and automate parameter inputs
def normalize_task_chain_with_dynamic_params(task_data):
templates = {}
normalized_tasks = {}
# Step 1: Extract common templates based on 'roi', 'action', and 'template'
for task_name, task_details in task_data.items():
# Convert list to tuple to make it hashable for dictionary keys
roi = tuple(task_details.get('roi', []))
action = task_details.get('action', '')
template = tuple(task_details.get('template', '')) if isinstance(task_details.get('template', ''), list) else task_details.get('template', '')
# Create a unique key based on 'roi', 'action', and 'template' to identify common templates
template_key = (roi, action, template)
# Check if this template already exists
if template_key not in templates:
template_name = f"TemplateTask_{len(templates) + 1}"
templates[template_key] = {
"template_name": template_name,
"roi": "{{roi}}", # Placeholder
"action": "{{action}}", # Placeholder
"template": "{{template}}" # Placeholder
}
# Step 2: Create a normalized task using the baseTask (template) and pass dynamic parameters
base_task = templates[template_key]['template_name']
parameters = {
'roi': task_details.get('roi', []),
'action': task_details.get('action', ''),
'template': task_details.get('template', '')
}
# Fill template with parameters dynamically
filled_template = fill_template_parameters(templates[template_key].copy(), parameters)
normalized_tasks[task_name] = {
"baseTask": base_task,
"next": task_details.get('next', []),
"parameters": parameters, # Include the parameters for transparency
"filled_template": filled_template # Show the filled template for reference
}
# Step 3: Generate the final normalized task chain with templates and tasks
normalized_chain = {
"templates": {tpl['template_name']: tpl for tpl in templates.values()},
"tasks": normalized_tasks
}
return normalized_chain
# Example task data for dynamic parameter testing
task_data = {
"Roguelike@StageTraderRefreshWithDice": {
"template": "Roguelike@StageTraderRefresh.png",
"action": "ClickSelf",
"roi": [230, 47, 211, 182],
"next": [
"Roguelike@StageTraderRefreshWithDiceConfirm",
"Roguelike@StageTraderRefreshWithDiceNotAvaiable"
]
},
"Sami@Roguelike@StageTraderRefresh": {
"template": "Roguelike@StageTraderRefresh.png",
"action": "ClickSelf",
"roi": [230, 73, 212, 141],
"next": ["Sami@Roguelike@StageTraderRefreshConfirm"]
}
}
# Normalize the task chain with dynamic parameter inputs
normalized_chain_dynamic = normalize_task_chain_with_dynamic_params(task_data)
# Save the normalized task chain to a new YAML file
normalized_yaml_dynamic_path = '/mnt/data/normalized_task_chain_dynamic_params.yaml'
with open(normalized_yaml_dynamic_path, 'w') as f:
yaml.dump(normalized_chain_dynamic, f, default_flow_style=False)
# Return the path to the normalized YAML file
normalized_yaml_dynamic_path
自動化樣本參數輸入的步驟:
識別動態欄位:範本將包含佔位元(例如,、、 ),需要根據特定於任務的數據進行填充。{{roi}}{{action}}{{template}}
提取相關參數:對於每個任務,提取參數(、 等)並將其傳遞到範本中。roiaction
自動填充參數:實施一個系統,當任務引用基本範本時,該系統會自動將佔位元替換為特定於任務的數據。
方法:
動態範本系統:使用佔位元定義範本。當任務使用 時 ,它將提供必要的參數,這些參數會自動插入到範本中。baseTask
解釋:
佔位元替換:範本定義、 和 等佔位元。當任務引用範本時,實際值(例如 , )會使用該函數自動替換為範本。{{roi}}{{action}}{{template}}roiactionfill_template_parameters()
Dynamic Parameters:字典包含每個任務的特定值。這些值將動態插入到範本中,從而允許每個任務重複使用相同的範本,但具有不同的值。parameters
結果:現在,每個任務都包含對基本範本的引用和帶有實際參數值的填充範本。 |
Beta Was this translation helpful? Give feedback.
-
validated_normalized_task_chain_with_template_handling.zip |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
素材 +1 |
Beta Was this translation helpful? Give feedback.
-
如何选择 MatchTemplate 与 OcrDetect以我个人的习惯和经验来说,尽可能对所有目标内容为常规文字的内容使用 OcrDetect,无法使用的再改用 MatchTemplate。 OcrDetect 的优缺点
MatchTemplate 的优缺点
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
先占个位置,糊点乱七八糟的东西,并抛砖——啊,没有砖但是想要白嫖玉。
Introduction
当讨论 MAA 的时候,我们往往会将 MAA 分为五个部分:
tasks.json
文件和template
文件夹共同构成的任务链信息;(这跟我一个直接用 C++ 接口运行 MAA 的用户又有什么关系呢?)任务链无疑是 MAA 运行的基石之一。当运行一个 接口任务1 时,
Assistant
会根据任务类型创建对应的InterfaceTask
的子类的对象,后者将根据接口任务的参数启用需要的插件并调用预先编写好的任务链。任务链运行时不断检测各插件的触发条件——比如特定任务执行前或执行后,若条件满足则运行插件,以实现更复杂的操作。本 discussion 建立的目的主要是分享与讨论一些任务链编写实践,尝试归纳、总结一些其中值得推广的部分。虽说不是什么规范,但日积月累,或许能为未来的开发者提供一些便利。
可能的讨论话题有:
MatchTemplate
与OcrDetect
;sub
;Footnotes
为了消除歧义,我们将集成文档中提及的可由
AsstAppendTask
接口创建的任务,即StartUp
,CloseDown
,Fight
,Recruit
,Infrast
,Mall
,Award
,Roguelike
,Copilot
,SSSCopilot
,Depot
,OperBox
,Reclamation
,Custom
,SingleStep
,VideoRecognition
共 16 项,称为接口任务。 ↩Beta Was this translation helpful? Give feedback.
All reactions