fix: DSL total字段从未被引擎校验+广东牌库数修正
Root cause: 1. Deal()完全忽略 _rules.Deck.Total → 牌库大小由 includeFlags 决定 2. Guangdong DSL: total=136 但 include_flowers=true → 实际144张 3. DS与引擎脱节导致广东无限对局(flaky test根因之一) 修复: - Deck构造加 expectedTotal 可选参数,不一致时抛 InvalidOperationException - Deal()传 _rules.Deck.Total → 所有DSL变更牌数时必须引擎一致 - Guangdong DSL: total 136→144(广东麻将含花牌=144张) Breaks: 无(向后兼容,expectedTotal默认null=不校验)
This commit is contained in:
@ -4,7 +4,7 @@ public class MahjongDeck
|
||||
{
|
||||
public List<int> Tiles { get; private set; } = new();
|
||||
|
||||
public MahjongDeck(bool includeHonors = false, bool includeFlowers = false, int wildcardCount = 0)
|
||||
public MahjongDeck(bool includeHonors = false, bool includeFlowers = false, int wildcardCount = 0, int? expectedTotal = null)
|
||||
{
|
||||
var allTiles = MahjongTile.AllTiles(includeHonors, includeFlowers, wildcardCount);
|
||||
foreach (var t in allTiles)
|
||||
@ -19,6 +19,15 @@ public class MahjongDeck
|
||||
// Add extra wildcard tiles
|
||||
for (int i = 0; i < wildcardCount; i++)
|
||||
Tiles.Add(MahjongTile.WildcardBase + i);
|
||||
|
||||
// Validate against DSL total if specified
|
||||
if (expectedTotal.HasValue && Tiles.Count != expectedTotal.Value)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"牌库大小不匹配: 引擎生成 {Tiles.Count} 张, DSL 声明 {expectedTotal.Value} 张。" +
|
||||
$" includeHonors={includeHonors} includeFlowers={includeFlowers} wildcardCount={wildcardCount}." +
|
||||
$" 请检查 DSL deck.total 字段与 include_honors/include_flowers 的一致性。");
|
||||
}
|
||||
}
|
||||
|
||||
public void Shuffle(Random? rng = null)
|
||||
|
||||
@ -685,7 +685,8 @@ public class MahjongRoom
|
||||
}
|
||||
}
|
||||
|
||||
var deck = new MahjongDeck(includeHonors, includeFlowers, wildcardCount);
|
||||
var deck = new MahjongDeck(includeHonors, includeFlowers, wildcardCount,
|
||||
expectedTotal: _rules.Deck.Total);
|
||||
deck.Shuffle(_rng);
|
||||
|
||||
State.Deck = deck.Tiles;
|
||||
|
||||
@ -17,7 +17,7 @@ deck:
|
||||
generator: mahjong
|
||||
include_honors: true
|
||||
include_flowers: true
|
||||
total: 136
|
||||
total: 144
|
||||
|
||||
deal:
|
||||
cards_per_player: 13
|
||||
|
||||
Reference in New Issue
Block a user