示例#1
0
        public static void checkAI(HashSet <AIInfo> aiInfos, int[] num, int jiang, int inputNum, AIProperty property)
        {
            bool huLian = property.huLian;
            int  N      = property.N;

            if (huLian)
            {
                for (int i = 0; i < N; i++)
                {
                    if (num[i] > 0 && i + 1 < N && num[i + 1] > 0 && i + 2 < N && num[i + 2] > 0)
                    {
                        num[i]--;
                        num[i + 1]--;
                        num[i + 2]--;
                        checkAI(aiInfos, num, jiang, inputNum, property);
                        num[i]++;
                        num[i + 1]++;
                        num[i + 2]++;
                    }
                }
            }

            for (int i = 0; i < N; i++)
            {
                if (num[i] >= 2 && jiang == -1)
                {
                    num[i] -= 2;
                    checkAI(aiInfos, num, i, inputNum, property);
                    num[i] += 2;
                }
            }

            for (int i = 0; i < N; i++)
            {
                if (num[i] >= 3)
                {
                    num[i] -= 3;
                    checkAI(aiInfos, num, jiang, inputNum, property);
                    num[i] += 3;
                }
            }

            for (int i = 0; i < N; i++)
            {
                if (num[i] != 0)
                {
                    return;
                }
            }

            AIInfo aiInfo = new AIInfo();

            aiInfo.inputNum = (int)inputNum;
            aiInfo.jiang    = (int)jiang;
            aiInfos.Add(aiInfo);
        }
示例#2
0
        public static List <AITableInfo> getAITable(long card, Dictionary <int, HashSet <long> > tmpcards, AIProperty property, int[] remainCards)
        {
            int    N     = property.N;
            double baseP = property.baseP;

            int[] num = new int[N];
            long  tmp = card;

            for (int i = 0; i < N; i++)
            {
                num[N - 1 - i] = (int)(tmp % 10);
                tmp            = tmp / 10;
            }

            int total = 0;

            for (int i = 0; i < N; i++)
            {
                total += num[i];
            }

            Dictionary <int, AITableInfo> aiTableInfos = new Dictionary <int, AITableInfo>();

            AITableInfo aiTableInfo = new AITableInfo();

            aiTableInfo.p     = 0.0d;
            aiTableInfo.jiang = true;
            int key = aiTableInfo.jiang ? 1 : 0;

            aiTableInfos[key] = aiTableInfo;
            aiTableInfo       = new AITableInfo();
            aiTableInfo.p     = 0.0d;
            aiTableInfo.jiang = false;
            key = aiTableInfo.jiang ? 1 : 0;
            aiTableInfos[key] = aiTableInfo;

            for (int inputNum = 0; inputNum <= LEVEL; inputNum++)
            {
                HashSet <long> tmpcard = tmpcards[inputNum];

                HashSet <AIInfo> aiInfos = new HashSet <AIInfo>();

                int valid = 0;

                foreach (long tmpc in tmpcard)
                {
                    int[] tmpcnum = new int[N];
                    long  tt      = tmpc;
                    for (int i = 0; i < N; i++)
                    {
                        tmpcnum[N - 1 - i] = (int)(tt % 10);
                        tt = tt / 10;
                    }

                    bool max = false;
                    for (int i = 0; i < N; i++)
                    {
                        num[i] += tmpcnum[i];
                        if (num[i] > 4)
                        {
                            max = true;
                        }
                        if (tmpcnum[i] > remainCards[property.tileType + i])
                        {
                            max = true;
                        }
                    }

                    if (!max)
                    {
                        checkAI(aiInfos, num, -1, inputNum, property);
                        valid++;
                    }

                    for (int i = 0; i < N; i++)
                    {
                        num[i] -= tmpcnum[i];
                    }
                }

                foreach (AIInfo aiInfo in aiInfos)
                {
                    key = aiInfo.jiang != -1 ? 1 : 0;
                    if (aiInfo.inputNum == 0)
                    {
                        aiTableInfos[key].p = 1.0d;
                    }
                    //if (aiTableInfos[key].p != 1)
                    if (aiTableInfos[key].p != 1)
                    {
                        key = aiInfo.jiang != -1 ? 1 : 0;
                        aiTableInfos[key].p += baseP * 1.0d / valid;
                    }
                }
            }

            List <AITableInfo> tmpAI = new List <AITableInfo>();

            foreach (var o in aiTableInfos.Values)
            {
                tmpAI.Add(o);
            }
            return(tmpAI);
        }