using System.Collections.Generic; using UnityEngine; namespace Wizard; public static class AIHandPtnCalculator { public class PriorityComparer : IComparer { private EnemyAI _ai; private List _playPtn; private List _priorityList; public PriorityComparer(EnemyAI ai, List playPtn) { _ai = ai; _playPtn = new List(playPtn); CreatePriorityList(); } public int Compare(int leftIndex, int rightIndex) { AIVirtualCard aIVirtualCard = _ai.CurrentVirtualField.AllyHandCards[leftIndex]; AIVirtualCard aIVirtualCard2 = _ai.CurrentVirtualField.AllyHandCards[rightIndex]; float num = _priorityList[leftIndex]; float num2 = _priorityList[rightIndex]; if (num > num2) { return -1; } if (num < num2) { return 1; } int cost = aIVirtualCard.Cost; int cost2 = aIVirtualCard2.Cost; if (cost < cost2) { return -1; } if (cost > cost2) { return 1; } if (leftIndex >= rightIndex) { return 1; } return -1; } private void CreatePriorityList() { List allyHandCards = _ai.CurrentVirtualField.AllyHandCards; _priorityList = new List(); for (int i = 0; i < allyHandCards.Count; i++) { AIVirtualCard card = allyHandCards[i]; _priorityList.Add(card.GetPriority(_playPtn)); } } } public static List>> CreateSortedPlayPtnList(EnemyAI ai) { List>> list = new List>>(); int count = ai.CurrentVirtualField.AllyHandCards.Count; int num = (int)Mathf.Pow(2f, count); List list2 = new List(); for (int i = 0; i < num; i++) { ConvertHandPtnIndexToList(i, count, list2); PrioritySortHand(ai, list2); Tuple> item = new Tuple> { first = i, second = new List(list2) }; bool flag = false; for (int j = 0; j < list.Count; j++) { if (list[j].second.Count > list2.Count) { flag = true; list.Insert(j, item); break; } } if (!flag) { list.Add(item); } } return list; } public static void ConvertHandPtnIndexToList(int handPtnIndex, int handCount, List dstList) { int num = handPtnIndex; dstList.Clear(); for (int i = 0; i < handCount; i++) { int num2 = (int)Mathf.Pow(2f, handCount - i - 1); if (num / num2 > 0) { num -= num2; dstList.Add(i); } } } public static int ConvertPlayPtnToHandPtnIndex(List playPtn, int handNum) { int num = 0; for (int i = 0; i < playPtn.Count; i++) { int num2 = (int)Mathf.Pow(2f, handNum - playPtn[i] - 1); num += num2; } return num; } public static void PrioritySortHand(EnemyAI ai, List handList) { IComparer comparer = new PriorityComparer(ai, handList); handList.Sort(comparer); } public static ulong CalculatePlayPtnHash(AIVirtualField field, List playPtn) { if (playPtn == null || playPtn.Count <= 0) { return 0uL; } ulong num = 0uL; for (int i = 0; i < playPtn.Count; i++) { AIVirtualCard aIVirtualCard = field.AllyHandCards[playPtn[i]]; num += (ulong)((long)aIVirtualCard.GetHash() * (long)(i + 1)); } return num; } }