feat(赛马): 为马匹添加序号并优化积分结算展示

- 为 Horse 模型添加 index 字段,用于唯一标识马匹序号
- 在报名时自动分配递增序号,并在所有展示中使用固定序号排序
- 新增积分变化计算功能,在比赛结果中展示每位用户的积分变化和总结描述
- 支持通过序号或马匹名下注,优化用户交互体验
- 添加用户上次马名记忆功能,允许重复使用马名报名
- 更新测试用例以验证序号展示和积分变化功能
This commit is contained in:
2026-04-04 22:43:46 +08:00
parent 2214e22b80
commit 64020cb0e6
5 changed files with 190 additions and 56 deletions

View File

@@ -57,12 +57,11 @@ class RaceEngine:
bar_width = 20
lines = [f"【第{room.tick_count}回合】"]
# Sort by position descending for readability
sorted_horses = sorted(room.horses.values(), key=lambda h: h.position, reverse=True)
sorted_horses = sorted(room.horses.values(), key=lambda h: h.index)
for horse in sorted_horses:
progress = min(horse.position / distance, 1.0)
filled = int(progress * bar_width)
bar = "" * filled + "" * (bar_width - filled)
lines.append(f" {horse.name:<6} |{bar}| {horse.position:.1f}m")
lines.append(f" {horse.index:02d}{horse.name} |{bar}| {horse.position:.1f}m")
return "\n".join(lines)