feat: demo显示听牌状态+可胡张数
引擎: MahjongRoom.GetTingTiles(player) 返回所有可胡的unique tile Demo: 每回合后显示'听牌: X: 🀄听N张(tile1 tile2...) | Y: 未听...' 包含已胡/副露中的tile计数,兼容wildcard和258规则 示例: 听牌: AI-东: 🀄听 1张(中) | AI-南: 未听 | AI-西: 未听 | AI-北: 未听
This commit is contained in:
@ -174,10 +174,24 @@ else
|
||||
}
|
||||
}
|
||||
|
||||
// 听牌检测: 每回合后显示各玩家听牌状态
|
||||
var tingInfo = new List<string>();
|
||||
foreach (var p in room.State.AlivePlayers)
|
||||
{
|
||||
var tingTiles = room.GetTingTiles(p);
|
||||
if (tingTiles.Count > 0)
|
||||
{
|
||||
var tileNames = tingTiles.Select(MahjongTile.ToString);
|
||||
tingInfo.Add($"{p}: 🀄听 {tingTiles.Count}张({string.Join(" ", tileNames)})");
|
||||
}
|
||||
else
|
||||
tingInfo.Add($"{p}: 未听");
|
||||
}
|
||||
Console.WriteLine($" 听牌: {string.Join(" | ", tingInfo)}");
|
||||
|
||||
// Show current hands
|
||||
if (!room.IsFinished)
|
||||
{
|
||||
// In human mode, show only opponent hands (human HUD shows their own)
|
||||
Console.WriteLine();
|
||||
if (humanMode)
|
||||
{
|
||||
|
||||
@ -892,4 +892,24 @@ public class MahjongRoom
|
||||
State.Phase = "settle";
|
||||
State.AddEvent("settle", "", null, "结算");
|
||||
}
|
||||
|
||||
/// <summary>返回玩家可胡牌的所有unique tile列表(听牌检测)。Empty=未听.</summary>
|
||||
public List<int> GetTingTiles(string player)
|
||||
{
|
||||
var result = new List<int>();
|
||||
bool require258 = _rules.WinCondition?.PairMustBe258 ?? false;
|
||||
var allPossible = MahjongTile.AllTiles(_rules.Deck.IncludeHonors, false);
|
||||
var hand = State.Hands[player];
|
||||
|
||||
foreach (var tile in allPossible)
|
||||
{
|
||||
int alreadyHave = hand.Count(t => t == tile);
|
||||
if (alreadyHave >= 4) continue;
|
||||
var checkHand = new List<int>(hand) { tile };
|
||||
int wc = CountWildcardsInHand(checkHand);
|
||||
var r = _solver.CheckWin(hand, newTile: tile, wildcardCount: wc, require258Pair: require258);
|
||||
if (r != null && r.IsWin) result.Add(tile);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user