TFT-Strategist/generate_weights_config.py

133 lines
4.7 KiB
Python

"""
生成完整的weights_config.yaml配置文件
"""
from src.data_provider import DataQueryAPI
import yaml
import random
def generate_weights_config():
"""生成完整的权重配置文件"""
api = DataQueryAPI()
# 获取所有数据
jobs = api.get_all_jobs()
races = api.get_all_races()
chess = api.get_all_chess()
# 生成配置字典
config = {
"base_weights": {
"synergy_level_weight": 1.0,
"synergy_count_weight": 0.5,
"chess_cost_weight": 0.1
},
"synergy_weights": {},
"chess_weights": {},
"cost_weights": {
"1": 1.0,
"2": 1.2,
"3": 1.5,
"4": 1.8,
"5": 2.0
},
"synergy_level_weights": {
"1": 1.0,
"2": 1.2,
"3": 1.5,
"4": 1.8,
"5": 2.0,
"6": 2.3,
"7": 2.6,
"8": 3.0,
"9": 3.3,
"10": 3.5
}
}
# 添加职业羁绊权重
for job in jobs:
# 根据职业类型设置不同的基础权重
base_weight = round(random.uniform(1.0, 1.6), 1)
# 对于一些特殊职业进行调整
if job['name'] == '召唤物':
base_weight = 0.7
elif job['name'] in ['重装战士', '高级工程师', '斗士']:
base_weight = 1.5
elif job['name'] in ['堡垒卫士', '强袭射手']:
base_weight = 1.4
config["synergy_weights"][job['name']] = base_weight
# 添加特质羁绊权重
for race in races:
# 根据特质类型设置不同的基础权重
base_weight = round(random.uniform(1.0, 1.6), 1)
# 对于一些特殊特质进行调整
if race['name'] in ['弑魂者', '网络之神', '鳄霸']:
base_weight = 1.6
elif race['name'] in ['圣灵使者', '源计划']:
base_weight = 1.5
config["synergy_weights"][race['name']] = base_weight
# 添加棋子权重
for c in chess:
if c.get('price') == '0':
# 召唤物权重较低
config["chess_weights"][c['displayName']] = 0.8
else:
# 根据费用调整权重基础值
cost = int(c.get('price', '1'))
base_weight = 1.0 + (cost - 1) * 0.1
# 对于一些特殊棋子进行调整
if c['displayName'] in ['佛耶戈', '扎克', '盖伦', '阿萝拉']:
base_weight = 1.7
elif c['displayName'] in ['薇恩', '赛娜', '金克丝', '布兰德']:
base_weight = 1.5
config["chess_weights"][c['displayName']] = round(base_weight, 1)
# 将配置写入YAML文件
with open('data/weights_config.yaml', 'w', encoding='utf-8') as f:
# 添加注释
f.write("# 云顶之弈阵容评分权重配置文件\n\n")
# 写入基础权重配置
f.write("# 基础权重配置\n")
yaml.dump({"base_weights": config["base_weights"]}, f, allow_unicode=True, sort_keys=False)
# 写入羁绊权重配置
f.write("\n# 羁绊权重配置(值越大,该羁绊在评分中的权重越高)\n")
f.write("synergy_weights:\n")
# 先写入职业羁绊
f.write(" # 职业羁绊\n")
for job in sorted(jobs, key=lambda x: x['name']):
f.write(f" {job['name']}: {config['synergy_weights'][job['name']]}\n")
# 再写入特质羁绊
f.write("\n # 特质羁绊\n")
for race in sorted(races, key=lambda x: x['name']):
f.write(f" {race['name']}: {config['synergy_weights'][race['name']]}\n")
# 写入棋子费用等级权重
f.write("\n# 棋子费用等级权重(费用越高权重越大)\n")
yaml.dump({"cost_weights": config["cost_weights"]}, f, allow_unicode=True, sort_keys=False)
# 写入棋子权重配置
f.write("\n# 棋子权重配置(值越大,该棋子在评分中的权重越高)\n")
f.write("chess_weights:\n")
for c_name, c_weight in sorted(config["chess_weights"].items()):
f.write(f" {c_name}: {c_weight}\n")
# 写入羁绊等级权重
f.write("\n# 羁绊等级权重(不同等级的羁绊权重不同)\n")
yaml.dump({"synergy_level_weights": config["synergy_level_weights"]}, f, allow_unicode=True, sort_keys=False)
print(f"已生成权重配置文件: data/weights_config.yaml")
print(f"职业羁绊: {len(jobs)}")
print(f"特质羁绊: {len(races)}")
print(f"棋子: {len(chess)}")
if __name__ == "__main__":
generate_weights_config()