示例#1
0
        /// <summary>
        /// 估值函数
        /// </summary>
        /// <param name="Plate"></param>
        /// <param name="WhiteValue"></param>
        /// <param name="BlackValue"></param>
        private static void Evaluate(UInt64Plate Plate, out double WhiteValue, out double BlackValue)
        {
            WhiteValue = 0;
            BlackValue = 0;
            int Count = 0;

            for (int i = 0; i < 64; i++)
            {
                Count      += (Plate.plate & Plate.Mask[i]) == 0 ? 0 : 1;
                WhiteValue += (Plate.white & Plate.Mask[i]) != 0
                    ? cellValue[i]
                    : 0;// ((Plate.black & Plate.Mask[i]) != 0 ? -cellValue[i] : 0);
                BlackValue += (Plate.black & Plate.Mask[i]) != 0
                    ? -cellValue[i]
                    : 0;// ((Plate.white & Plate.Mask[i]) != 0 ? cellValue[i] : 0);
            }

            int WhiteMobility = 0;
            int BlackMobility = 0;

            UInt64     set;
            List <int> WhiteMobilityList = getidList(1, Plate, out set);
            List <int> BlackMobilityList = getidList(-1, Plate, out set);

            double tag = Count / 64F * 1;//行动力权重,格子越多,行动力权重越小,格子越多格子权重越高

            foreach (var i in WhiteMobilityList)
            {
                int        thisCellMobility = -cellValue[i];
                List <int> getSetChessList  = getSetChess(i, 1, Plate);
                if (getSetChessList.Count == 0)
                {
                    continue;
                }
                foreach (var a in getSetChessList)
                {
                    thisCellMobility += cellValue[a];
                }
                WhiteMobility += thisCellMobility;
            }

            WhiteValue = (WhiteValue * tag + (WhiteMobility + BlackMobility) * (1 - tag));

            foreach (var i in BlackMobilityList)
            {
                int        thisCellMobility = cellValue[i];
                List <int> getSetChessList  = getSetChess(i, -1, Plate);
                if (getSetChessList.Count == 0)
                {
                    continue;
                }
                foreach (var a in getSetChessList)
                {
                    thisCellMobility -= cellValue[a];
                }
                BlackMobility -= thisCellMobility;
            }

            BlackValue = (BlackValue * tag + (WhiteMobility + BlackMobility) * (1 - tag));
        }
示例#2
0
        public static Boolean CheckPlate(int Color, UInt64Plate Plate, out List <int> CellList)
        {
            UInt64 set;

            CellList = new List <int>();
            List <int> idList = getidList(Color, Plate, out set);//可能可以下子的id列表

            foreach (var id in idList)
            {
                UInt64 ChesstoSetUInt64;
                int    y = id / 8 + 1;
                int    x = id - y * 8 + 1 + 8;
                if (x <= 0 || y <= 0 || id < 0 || id > 63)
                {
                    continue;
                }
                List <int> ChesstoSet = getsetid(x, y, Color, Plate, out ChesstoSetUInt64);
                if (ChesstoSet.Count <= 1)
                {
                    continue;
                }
                CellList.Add(id);
            }
            if (CellList.Count == 0)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
示例#3
0
        public static int getColor(int id, UInt64Plate Plate)
        {
            if ((Plate.Mask[id] & Plate.white) != 0)
            {
                return(1);
            }
            if ((Plate.Mask[id] & Plate.black) != 0)
            {
                return(-1);
            }

            return(0);
        }
示例#4
0
        /// <summary>
        /// 获取可以下子的位置
        /// </summary>
        /// <param name="Color">颜色</param>
        /// <param name="Plate">棋盘</param>
        /// <param name="set">UInt64</param>
        /// <returns></returns>
        public static List <int> getidList(int Color, UInt64Plate Plate, out UInt64 set)
        {
            set = (UInt64)0;
            List <int> idList   = new List <int>();
            UInt64     surround = (Plate.plate << 8) | (Plate.plate >> 8) | Plate.plate;

            UInt64 PlateWithoutLine1_8 = surround & (~Line1_8);

            surround |= (PlateWithoutLine1_8 << 1 | PlateWithoutLine1_8 >> 1);
            surround &= ~Plate.plate;

            if (Color == -1)
            {
                UInt64 whitesurround = (Plate.white << 8) | (Plate.white >> 8) | Plate.white;
                PlateWithoutLine1_8 = whitesurround & (~Line1_8);
                whitesurround      |= (PlateWithoutLine1_8 << 1 | PlateWithoutLine1_8 >> 1);
                whitesurround      &= ~Plate.white;

                set = surround & whitesurround;
            }
            else
            {
                UInt64 blacksurround = (Plate.black << 8) | (Plate.black >> 8) | Plate.black;
                PlateWithoutLine1_8 = blacksurround & (~Line1_8);
                blacksurround      |= (PlateWithoutLine1_8 << 1 | PlateWithoutLine1_8 >> 1);
                blacksurround      &= ~Plate.black;

                set = surround & blacksurround;
            }

            //set = surround;

            for (int i = 0; i < 64; i++)
            {
                if ((set & Plate.Mask[i]) != 0)
                {
                    idList.Add(i);
                }
            }

            return(idList);
        }
示例#5
0
        public static int CacuLate(UInt64Plate Plate, int CurrentColor, int depth)
        {
            List <UInt64Plate> Depth_0 = new List <UInt64Plate>();
            List <UInt64Plate> Depth_1 = new List <UInt64Plate>();

            Depth_0.Add(Plate);
            List <int> thisturnidList = new List <int>();
            int        Color          = -CurrentColor;

            for (int d = 0; d < depth; d++)//搜索某深度下的所有着法
            {
                if (d != 0)
                {
                    Depth_0.Clear();
                }
                Depth_0.AddRange(Depth_1);
                Depth_1.Clear();
                foreach (var i in Depth_0)
                {
                    UInt64     set;
                    List <int> idList = getidList(Color, Plate, out set);//可能可以下子的id列表
                    foreach (var id in idList)
                    {
                        UInt64 ChesstoSetUInt64;
                        int    y = id / 8 + 1;
                        int    x = id - y * 8 + 1 + 8;
                        if (x <= 0 || y <= 0 || id < 0 || id > 63)
                        {
                            continue;
                        }
                        List <int> ChesstoSet = getsetid(x, y, Color, Plate, out ChesstoSetUInt64);
                        if (ChesstoSet.Count <= 1)
                        {
                            continue;
                        }
                        UInt64Plate NextPlate = setPlate(Plate, Color, ChesstoSet, ChesstoSetUInt64);
                        if (d == 0)
                        {
                            NextPlate.id = id;
                        }
                        else
                        {
                            NextPlate.id = i.id;
                        }
                        Depth_1.Add(NextPlate);
                    }
                    if (d == 0)//第一层时
                    {
                        thisturnidList = idList;
                    }
                    Color *= -1;
                }
            }

            double BlackValue_0, WhiteValue_0;

            Evaluate(Plate, out WhiteValue_0, out BlackValue_0);//计算原先分差


            Dictionary <int, int> Best = new Dictionary <int, int>();
            double Max = 0;


            Color = -CurrentColor;

            for (int i = 0; i < Depth_1.Count; i++)
            {
                if (i < 0 || i > 63)
                {
                    continue;
                }
                double blackValue, whiteValue;
                Evaluate(Depth_1[i], out whiteValue, out blackValue);

                if (Color * ((whiteValue + blackValue) - (BlackValue_0 + WhiteValue_0)) < 0)//n深度下的着法局面评估
                {
                    //局势更糟了
                    continue;
                }
                else
                {
                    if (Max < Color * ((whiteValue + blackValue) - (BlackValue_0 + WhiteValue_0)))
                    {
                        Max = Color * ((whiteValue + blackValue) - (BlackValue_0 + WhiteValue_0));
                        Best.Clear();
                    }
                    else if (Max == Color * ((whiteValue + blackValue) - (BlackValue_0 + WhiteValue_0)))
                    {
                        if (Best.ContainsKey(Depth_1[i].id))
                        {
                            Best[Depth_1[i].id]++;
                        }
                        else
                        {
                            Best.Add(Depth_1[i].id, 1);
                        }
                    }
                }
            }

            int BestinBest = -1;
            int MaxCount   = 0;

            foreach (var i in Best)
            {
                if (i.Value > MaxCount)
                {
                    BestinBest = i.Key;
                    MaxCount   = i.Value;
                }
            }


            return(BestinBest);
        }