コード例 #1
0
ファイル: HuUtil.cs プロジェクト: isoundy000/mahjong_AI
        public static void testHu()
        {
            string     init  = "1万,1万";
            string     gui   = "1万";
            List <int> cards = MaJiangDef.stringToCards(init);

            Console.WriteLine(HuUtil.isHu(cards, MaJiangDef.stringToCard(gui)));
        }
コード例 #2
0
ファイル: HuUtil.cs プロジェクト: isoundy000/mahjong_AI
        public static void testTing()
        {
            string     init  = "1万,1万,1筒,3筒,2筒,2条,3条,4条,东,东";
            string     gui   = "1筒";
            List <int> cards = MaJiangDef.stringToCards(init);

            Console.WriteLine(MaJiangDef.cardsToString(HuUtil.isTing(cards, MaJiangDef.stringToCard(gui))));
            Console.WriteLine(MaJiangDef.cardsToString(HuUtil.isTingExtra(cards, MaJiangDef.stringToCards(gui))));
        }
コード例 #3
0
        private static void testHu()
        {
            List <int> total = new List <int>();

            for (int i = MaJiangDef.WAN1; i <= MaJiangDef.JIAN_BAI; i++)
            {
                total.Add(i);
                total.Add(i);
                total.Add(i);
                total.Add(i);
            }
            //Collections.shuffle(total);

            List <int> cards = new List <int>();

            for (int i = 0; i < 14; i++)
            {
                int tmp = total[0];
                total.RemoveAt(0);
                cards.Add(tmp);
            }

            cards.Sort();
            Console.WriteLine("before " + MaJiangDef.cardsToString(cards));

            List <int> gui = new List <int>();

            int step = 0;

            int[] remain = new int[43] {
                0,
                4, 4, 4, 4, 4, 4, 4, 4, 4,
                4, 4, 4, 4, 4, 4, 4, 4, 4,
                4, 4, 4, 4, 4, 4, 4, 4, 4,
                4, 4, 4, 4,
                4, 4, 4,
                1, 1, 1, 1, 1, 1, 1, 1
            };
            List <int> bannedCards = new List <int>();

            while (total.Count != 0)
            {
                if (HuUtil.isHuExtra(cards, gui, 0))
                {
                    cards.Sort();
                    Console.WriteLine("after " + MaJiangDef.cardsToString(cards));
                    Console.WriteLine("step " + step);
                    break;
                }
                step++;
                int outRet = outAI(cards, gui, remain, bannedCards);
                cards.Remove((int)outRet);
                int tmp = total[0];
                total.RemoveAt(0);
                cards.Add(tmp);
            }
        }
コード例 #4
0
ファイル: AIEntry.cs プロジェクト: isoundy000/mahjong_AI
        public static void RegisterAI()
        {
            Console.WriteLine(" ====== AI start ======");

            HuUtil.load();
            AIUtil.load();

            Console.WriteLine(" ====== AI end ======");
        }
コード例 #5
0
        public static double calc(List <int> input, List <int> guiCard)
        {
            List <int> cards = new List <int>();

            for (int i = 0; i < MaJiangDef.MAX_NUM; i++)
            {
                cards.Add(0);
            }
            foreach (int c in input)
            {
                cards[c - 1] = cards[c - 1] + 1;
            }

            int guiNum = 0;

            foreach (int gui in guiCard)
            {
                guiNum        += cards[gui - 1];
                cards[gui - 1] = 0;
            }

            List <int> ting = HuUtil.isTingCard(cards, guiNum);

            if (ting.Count != 0)
            {
                return(ting.Count * 10);
            }

            long wan_key  = 0;
            long tong_key = 0;
            long tiao_key = 0;
            long feng_key = 0;
            long jian_key = 0;

            for (int i = MaJiangDef.WAN1; i <= MaJiangDef.WAN9; i++)
            {
                int num = cards[i - 1];
                wan_key = wan_key * 10 + num;
            }
            for (int i = MaJiangDef.TONG1; i <= MaJiangDef.TONG9; i++)
            {
                int num = cards[i - 1];
                tong_key = tong_key * 10 + num;
            }
            for (int i = MaJiangDef.TIAO1; i <= MaJiangDef.TIAO9; i++)
            {
                int num = cards[i - 1];
                tiao_key = tiao_key * 10 + num;
            }
            for (int i = MaJiangDef.FENG_DONG; i <= MaJiangDef.FENG_BEI; i++)
            {
                int num = cards[i - 1];
                feng_key = feng_key * 10 + num;
            }
            for (int i = MaJiangDef.JIAN_ZHONG; i <= MaJiangDef.JIAN_BAI; i++)
            {
                int num = cards[i - 1];
                jian_key = jian_key * 10 + num;
            }

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

            List <AITableInfo> wanAITableInfo = AITable.table[wan_key];

            tmp.Add(wanAITableInfo);

            List <AITableInfo> tongAITableInfo = AITable.table[tong_key];

            tmp.Add(tongAITableInfo);

            List <AITableInfo> tiaoAITableInfo = AITable.table[tiao_key];

            tmp.Add(tiaoAITableInfo);

            List <AITableInfo> fengAITableInfo = AITableFeng.table[feng_key];

            tmp.Add(fengAITableInfo);

            List <AITableInfo> jianAITableInfo = AITableJian.table[jian_key];

            tmp.Add(jianAITableInfo);

            List <double> ret = new List <double>();

            calcAITableInfo(ret, tmp, 0, false, 0.0d);

            double result = 0.0d;

            foreach (double d in ret)
            {
                if (d > result)
                {
                    result = d;
                }
            }
            return(result);
        }
コード例 #6
0
        public static double calc(List <int> input, List <int> guiCard, int[] remainCards)
        {
            List <int> cards = new List <int>();

            for (int i = 0; i < MaJiangDef.MAX_NUM; i++)
            {
                cards.Add(0);
            }
            foreach (int c in input)
            {
                cards[c - 1] = cards[c - 1] + 1;
            }

            int guiNum = 0;

            foreach (int gui in guiCard)
            {
                guiNum        += cards[gui - 1];
                cards[gui - 1] = 0;
            }

            List <int> ting = HuUtil.isTingCard(cards, guiNum);

            if (ting.Count != 0)
            {
                return(ting.Count * 10);
            }

            long wan_key  = 0;
            long tong_key = 0;
            long tiao_key = 0;
            long feng_key = 0;
            long jian_key = 0;

            for (int i = MaJiangDef.WAN1; i <= MaJiangDef.WAN9; i++)
            {
                int num = cards[i - 1];
                wan_key = wan_key * 10 + num;
            }
            for (int i = MaJiangDef.TONG1; i <= MaJiangDef.TONG9; i++)
            {
                int num = cards[i - 1];
                tong_key = tong_key * 10 + num;
            }
            for (int i = MaJiangDef.TIAO1; i <= MaJiangDef.TIAO9; i++)
            {
                int num = cards[i - 1];
                tiao_key = tiao_key * 10 + num;
            }
            for (int i = MaJiangDef.FENG_DONG; i <= MaJiangDef.FENG_BEI; i++)
            {
                int num = cards[i - 1];
                feng_key = feng_key * 10 + num;
            }
            for (int i = MaJiangDef.JIAN_ZHONG; i <= MaJiangDef.JIAN_BAI; i++)
            {
                int num = cards[i - 1];
                jian_key = jian_key * 10 + num;
            }

            AIProperty property;

            property.N = 9; property.baseP = 36.0d / 136; property.huLian = true;

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

            property.tileType = MaJiangDef.WAN1;
            List <AITableInfo> dynamicWanAITableInfo = getAITable(wan_key, _everyNormalCards, property, remainCards);

            dynamicMaxPossible.Add(dynamicWanAITableInfo);

            property.tileType = MaJiangDef.TONG1;
            List <AITableInfo> dynamicTongAITableInfo = getAITable(tong_key, _everyNormalCards, property, remainCards);

            dynamicMaxPossible.Add(dynamicTongAITableInfo);

            property.tileType = MaJiangDef.TIAO1;
            List <AITableInfo> dynamicTiaoAITableInfo = getAITable(tiao_key, _everyNormalCards, property, remainCards);

            dynamicMaxPossible.Add(dynamicTiaoAITableInfo);

            property.N        = 4; property.baseP = 16.0d / 136; property.huLian = false;
            property.tileType = MaJiangDef.FENG_DONG;
            List <AITableInfo> dynamicFengAITableInfo = getAITable(feng_key, _everyFengCards, property, remainCards);

            dynamicMaxPossible.Add(dynamicFengAITableInfo);

            property.N        = 3; property.baseP = 12.0d / 136; property.huLian = false;
            property.tileType = MaJiangDef.JIAN_ZHONG;
            List <AITableInfo> dynamicJianAITableInfo = getAITable(jian_key, _everyJianCards, property, remainCards);

            dynamicMaxPossible.Add(dynamicJianAITableInfo);

            List <double> ret = new List <double>();

            calcAITableInfo(ret, dynamicMaxPossible, 0, false, 0.0d);

            double result = 0.0d;

            foreach (double d in ret)
            {
                if (d > result)
                {
                    result = d;
                }
            }
            return(result);
        }