diff --git a/PdkFriendServer/Logic/CardTracker.cs b/PdkFriendServer/Logic/CardTracker.cs index 978e2849..3c4c6b77 100644 --- a/PdkFriendServer/Logic/CardTracker.cs +++ b/PdkFriendServer/Logic/CardTracker.cs @@ -29,13 +29,6 @@ namespace PdkFriendServer.Logic // 对手约束:[pos-2] = 该对手 pass 过的牌型列表 private readonly List[] _opponentConstraints; - // 当前轮次 pass 计数 - private int _passStreak; - private bool _isNewRound; - - // 每个位置的炸弹计数 - private readonly int[] _bombCounts = new int[3]; - public CardTracker() { _opponentConstraints = new List[3]; @@ -64,33 +57,22 @@ namespace PdkFriendServer.Logic var currentMax = view.MaxPlayCard; if (currentMax.Ids != null && currentMax.Ids.Length > 0) { - // 如果是新出牌(不是上一轮的) + // 新出牌 → 记录 if (_lastMaxPlay.Ids == null || !_lastMaxPlay.Ids.SequenceEqual(currentMax.Ids)) { foreach (var id in currentMax.Ids) _seenCardIds.Add(id); - _passStreak = 0; - _isNewRound = false; } - else if (_lastMaxPlay.Ids != null) + else { // 同一手牌还在桌上 → 有人 pass 了 - _passStreak++; - // 记录 pass 约束(轮到谁 pass 了就是谁) int passer = currentMax.Pos > 0 - ? (currentMax.Pos % 3 + 1) // 下一位 + ? (currentMax.Pos % 3 + 1) : 0; if (passer > 0 && passer != myPos) - { RecordPassConstraint(passer, currentMax); - } } } - else - { - _isNewRound = true; - _passStreak = 0; - } _lastMaxPlay = new PlayOutCardPdkF { @@ -99,10 +81,6 @@ namespace PdkFriendServer.Logic Type = currentMax.Type, Ids = currentMax.Ids?.ToArray() }; - - // 3. 追踪炸弹计数 - for (int i = 0; i < 3; i++) - _bombCounts[i] = view.ZhaDans[i]; } /// @@ -113,16 +91,13 @@ namespace PdkFriendServer.Logic _seenCardIds.Clear(); _lastMyHandIds = null; _lastMaxPlay = new PlayOutCardPdkF(); - _passStreak = 0; - _isNewRound = true; foreach (var c in _opponentConstraints) c.Clear(); - Array.Clear(_bombCounts, 0, 3); } // ---- 查询接口 ---- /// 返回外面还有多少未知卡 - public int UnknownCount => 48 - _seenCardIds.Count; + public int UnknownCount => 52 - _seenCardIds.Count; /// 在外面可能存在的炸弹数(按 rank 计) public int BombsOutside(TCardInfoPdkF[] myHand) diff --git a/PdkFriendServer/Logic/IsmctsBot.cs b/PdkFriendServer/Logic/IsmctsBot.cs index b69ce3dc..22198b6c 100644 --- a/PdkFriendServer/Logic/IsmctsBot.cs +++ b/PdkFriendServer/Logic/IsmctsBot.cs @@ -295,7 +295,7 @@ namespace PdkFriendServer.Logic hands[nextPos - 1] = new List(); hands[oppPos - 1] = new List(); - var allCards = GenerateDeck(); + var allCards = GetDeckCopy(); var unknown = allCards.Where(c => !myHand.Any(h => h.ID == c.ID)).ToList(); // 使用 CardTracker 进行约束采样 @@ -495,13 +495,29 @@ namespace PdkFriendServer.Logic return best; } - private static List GenerateDeck() + // 静态牌池:52张牌,只创建一次 + private static readonly TCardInfoPdkF[] FullDeck; + static IsmctsBot() { - var d = new List(); int id = 1; + FullDeck = new TCardInfoPdkF[52]; + int id = 1; foreach (int f in new[] { 1, 2, 3, 4 }) for (int n = 1; n <= 13; n++) - d.Add(new TCardInfoPdkF { ID = (byte)id++, Flower = (byte)f, GameNum = (byte)(n == 1 ? 14 : n == 2 ? 16 : n), GameState = 1 }); - return d; + FullDeck[id - 1] = new TCardInfoPdkF + { + ID = (byte)id, + Flower = (byte)f, + GameNum = (byte)(n == 1 ? 14 : n == 2 ? 16 : n), + GameState = 1 + }; + } + + private static List GetDeckCopy() + { + return FullDeck.Where(c => c.ID > 0).Select(c => new TCardInfoPdkF + { + ID = c.ID, Flower = c.Flower, GameNum = c.GameNum, GameState = 1 + }).ToList(); } private void Shuffle(List l) { for (int i = l.Count - 1; i > 0; i--) { int j = _rng.Next(i + 1); (l[i], l[j]) = (l[j], l[i]); } } diff --git a/exe/PdkFriendServer/PdkFriendServer.dll b/exe/PdkFriendServer/PdkFriendServer.dll index 5a429c37..790c3a55 100644 Binary files a/exe/PdkFriendServer/PdkFriendServer.dll and b/exe/PdkFriendServer/PdkFriendServer.dll differ diff --git a/exe/PdkFriendServer/PdkFriendServer.pdb b/exe/PdkFriendServer/PdkFriendServer.pdb index e9fa3c15..68e1e801 100644 Binary files a/exe/PdkFriendServer/PdkFriendServer.pdb and b/exe/PdkFriendServer/PdkFriendServer.pdb differ diff --git a/exe/hjha-console/PdkFriendServer.dll b/exe/hjha-console/PdkFriendServer.dll index 5a429c37..790c3a55 100644 Binary files a/exe/hjha-console/PdkFriendServer.dll and b/exe/hjha-console/PdkFriendServer.dll differ diff --git a/exe/hjha-console/PdkFriendServer.pdb b/exe/hjha-console/PdkFriendServer.pdb index e9fa3c15..68e1e801 100644 Binary files a/exe/hjha-console/PdkFriendServer.pdb and b/exe/hjha-console/PdkFriendServer.pdb differ diff --git a/exe/hjha-console/hjha-console.dll b/exe/hjha-console/hjha-console.dll index e76e630a..1df05785 100644 Binary files a/exe/hjha-console/hjha-console.dll and b/exe/hjha-console/hjha-console.dll differ diff --git a/exe/hjha-console/hjha-console.pdb b/exe/hjha-console/hjha-console.pdb index b7f7bfcf..8e6067d3 100644 Binary files a/exe/hjha-console/hjha-console.pdb and b/exe/hjha-console/hjha-console.pdb differ