2026-06-12 19:40:21 +08:00

48 lines
2.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# game-service
`game-service` 承接 HyApp 的游戏启动、订单账务、自研游戏匹配结算、后台游戏配置和统计 outbox。
## 自研游戏边界
- `dice`:自研骰子,复用 `game_dice_matches`,平局不结算并继续重投。
- `rock`:自研石头剪刀布,复用 `game_dice_matches`,平局退款并结算为 draw。
- `room-rps`:语音房内猜拳,在 `internal/service/roomrps`,有独立状态机和 IM 事件,不参与自研游戏机器人策略。
## 机器人职责边界
- `robot-service` 负责机器人账号池:登记、状态、随机抽取。
- `game-service` 负责机器人局策略:档位奖池、新用户保护、成熟用户自然期目标胜率、奖池水位、风控准入、`forced_result` 和策略日志。
-`robot_user_win_rate_percent` 只允许作为线上遗留数据库列存在server/admin/API 不读写、不暴露、不做兼容分支。
## 自研机器人策略
公共策略在 `internal/domain/selfgame`
- 每个 `app_code + game_id + stake_coin` 使用独立档位奖池。
- 黑色水位不抽机器人,用户继续等待真人匹配。
- 新用户保护不读取成熟用户正常随机逻辑,不读取旧胜率字段。
- 新用户连输保护统计真人局和机器人局的已结算非平局结果,但只在下一次机器人补位局写 `forced_result`
- 成熟用户不做定向消耗,不按连赢、净赢或下注行为输出 `force_human_lose`
- 成熟用户自然期目标胜率由后台配置,默认 53%;配置 50% 时完全自然随机,高于 50% 时只向上补正用户赢且不消耗新手补贴额度。
- `rock` 平局不计有效机器人局,不消耗保护局数,不消耗个人补贴额度。
- 每次策略决策写 `game_self_game_strategy_logs`,用于后台复盘和风控解释。
## 关键数据表
- `game_self_game_stake_pools`:自研游戏档位奖池。
- `game_self_game_stake_pool_transactions`:档位奖池流水。
- `game_self_game_new_user_policies`:新用户保护策略。
- `game_self_game_user_protection_states`:用户保护状态。
- `game_self_game_user_protection_events`:保护消费幂等事件。
- `game_self_game_risk_rules`:风控分层规则。
- `game_self_game_strategy_logs`:机器人策略决策日志。
## 验证
常用验证命令:
```bash
go test ./services/game-service/internal/domain/selfgame ./services/game-service/internal/service/dice ./services/game-service/internal/storage/mysql
go test ./services/game-service/...
```