Files
card-game-engine/RuleEngine/Core/GameState.cs
xiaoou 3c6748bf06 [verified] feat: 麻将规则引擎 Demo 完整实现
RuleEngine 核心类:
- MahjongTile.cs — int编码 (1-29万条筒, 31-37字, 41-48花, 50-59宝牌)
- MeldsSolver.cs — 标准回溯 + wildcard缺口填充 + 七对/十三幺/全不靠
- PhaseMachine.cs — 回合机(摸打碰杠胡 + 优先级仲裁)
- ScoreEngine.cs — 番型计分 + 互斥图
- DslLoader.cs — YAML DSL加载 + 能力检查

4个DSL: 四川血战/广东鸡平胡/国标麻将/武汉麻将
控制台Demo: 交互模式 + 自动模式(--auto)
测试: 33个测试用例, 32个通过
2026-07-03 17:51:59 +08:00

72 lines
2.7 KiB
C#

namespace RuleEngine.Core;
using RuleEngine;
public class GameEvent
{
public string Type { get; set; } = "";
public string Player { get; set; } = "";
public string? Description { get; set; }
public int? Tile { get; set; }
}
public class MahjongGameState
{
public string Phase { get; set; } = "";
public Dictionary<string, List<int>> Hands { get; set; } = new();
public Dictionary<string, List<Meld>> Exposed { get; set; } = new();
public Dictionary<string, List<int>> FlowerPool { get; set; } = new();
public List<int> Deck { get; set; } = new();
public List<int> DiscardPool { get; set; } = new();
public int? LastDiscard { get; set; }
public string? LastDiscardPlayer { get; set; }
public string CurrentPlayer { get; set; } = "";
public List<string> PlayerOrder { get; set; } = new();
public string Dealer { get; set; } = "";
public int RoundNumber { get; set; }
public Dictionary<string, int> Scores { get; set; } = new();
public List<string> HuPlayers { get; set; } = new();
public List<string> AlivePlayers { get; set; } = new();
public Dictionary<string, bool> FuFlags { get; set; } = new();
public bool IsDeckExhausted { get; set; }
public List<GameEvent> RecentEvents { get; set; } = new();
public int FlowerReplaced { get; set; }
public MahjongGameState Clone()
{
return new MahjongGameState
{
Phase = Phase,
Hands = Hands.ToDictionary(kv => kv.Key, kv => new List<int>(kv.Value)),
Exposed = Exposed.ToDictionary(kv => kv.Key, kv => kv.Value.Select(m => m.Clone()).ToList()),
FlowerPool = FlowerPool.ToDictionary(kv => kv.Key, kv => new List<int>(kv.Value)),
Deck = new List<int>(Deck),
DiscardPool = new List<int>(DiscardPool),
LastDiscard = LastDiscard,
LastDiscardPlayer = LastDiscardPlayer,
CurrentPlayer = CurrentPlayer,
PlayerOrder = new List<string>(PlayerOrder),
Dealer = Dealer,
RoundNumber = RoundNumber,
Scores = new Dictionary<string, int>(Scores),
HuPlayers = new List<string>(HuPlayers),
AlivePlayers = new List<string>(AlivePlayers),
FuFlags = new Dictionary<string, bool>(FuFlags),
IsDeckExhausted = IsDeckExhausted,
RecentEvents = new List<GameEvent>(RecentEvents),
FlowerReplaced = FlowerReplaced
};
}
public void AddEvent(string type, string player, int? tile = null, string? desc = null)
{
RecentEvents.Add(new GameEvent
{
Type = type,
Player = player,
Tile = tile,
Description = desc
});
}
}