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:
xiaoou
2026-07-04 20:05:26 +08:00
parent 0dbb7c2d15
commit c2b5136085
9 changed files with 108 additions and 46 deletions

View File

@ -39,6 +39,14 @@ public class MahjongTileTests
public void IsWildcard_50_True() => Assert.True(MahjongTile.IsWildcard(50));
[Fact]
public void IsWildcard_普通牌_False() => Assert.False(MahjongTile.IsWildcard(1));
[Fact]
public void ToString_配置wildcard_显示癞子标记()
{
var wc = new WildcardRegistry();
wc.Add(35);
Assert.Equal("🀫中", MahjongTile.ToString(35, wc));
}
}
public class DeckTests
@ -84,12 +92,6 @@ public class MeldsSolverTests
{
private readonly MeldsSolver _solver = new(new Dictionary<string, FanConfig>());
public MeldsSolverTests()
{
// Reset wildcards to avoid contamination from integration tests
MahjongTile.ConfigureWildcards([]);
}
// === 标准胡牌 ===
[Fact]
public void _4面子1对_ShouldWin()