refactor: _wildcards static→实例级 WildcardRegistry
Root cause: static HashSet跨测试/跨变体污染+硬编码名→编码映射 Changes: - WildcardRegistry: 实例级wildcard管理(IsWildcard/CountWildcards/Clone) - GameState: 新增Wildcards属性(含Clone) - MahjongTile: 移除static_wildcards,IsWildcard仅查编码50-59 +ToString(tile,wildcards)重载用于游戏上下文显示 - MeldsSolver: _wildcards字段→构造函数注入(WildcardRegistry?) - PhaseMachine: _wildcards字段+构造注入 - Deal(): State.Wildcards.Clear()+AddRange替代static ConfigureWildcards +NameToEncoding查表替代switch硬编码 - RandomMahjongAI/HumanMahjongPlayer: state.Wildcards替代static调用 - HumanMahjongPlayer.CheckTing: 补wildcardCount参数(之前遗漏) - ExecuteWinClaim: IsFinished=true→Settle()(之前Phase漏设) Test: CoreTests清理ConfigureWildcards()→WildcardRegistry测试 Impact: 零static state→不同变体/测试完全隔离,未来支持随机宝牌
This commit is contained in:
@ -42,11 +42,13 @@ public class MahjongPhaseMachine
|
||||
private readonly bool _require258;
|
||||
private readonly Dictionary<string, FanConfig> _fanConfig;
|
||||
private readonly bool _jiHuSelfDrawOnly;
|
||||
private readonly WildcardRegistry _wildcards;
|
||||
|
||||
public MahjongPhaseMachine(List<PhaseConfig> phases, MeldsSolver solver,
|
||||
int wildcardCount = 0, bool require258 = false,
|
||||
Dictionary<string, FanConfig>? fanConfig = null,
|
||||
bool jiHuSelfDrawOnly = false)
|
||||
bool jiHuSelfDrawOnly = false,
|
||||
WildcardRegistry? wildcards = null)
|
||||
{
|
||||
_phases = phases;
|
||||
_solver = solver;
|
||||
@ -54,6 +56,7 @@ public class MahjongPhaseMachine
|
||||
_require258 = require258;
|
||||
_fanConfig = fanConfig ?? new();
|
||||
_jiHuSelfDrawOnly = jiHuSelfDrawOnly;
|
||||
_wildcards = wildcards ?? new();
|
||||
}
|
||||
|
||||
public PhaseConfig? GetPhase(string name) => _phases.FirstOrDefault(p => p.Name == name);
|
||||
@ -141,7 +144,7 @@ public class MahjongPhaseMachine
|
||||
{
|
||||
// Check if player has 4 identical tiles in hand (暗杠)
|
||||
var hand = state.Hands[playerId];
|
||||
return hand.GroupBy(t => t).Any(g => g.Count() >= 4 && !MahjongTile.IsWildcard(g.Key));
|
||||
return hand.GroupBy(t => t).Any(g => g.Count() >= 4 && !_wildcards.IsWildcard(g.Key));
|
||||
}
|
||||
|
||||
private bool CanBuKong(MahjongGameState state, string playerId)
|
||||
|
||||
Reference in New Issue
Block a user