Exemplo n.º 1
0
        /// <summary>
        /// 设置棋盘
        /// </summary>
        /// <param name="Plate">棋盘</param>
        /// <param name="currentColor">当前需要被设置的颜色</param>
        /// <param name="setid">需要被设置的格子id</param>
        /// <param name="set">需要被设置的格子id组成的UInt64</param>
        /// <returns></returns>
        public static Plate_Struct.UInt64Plate setPlate(Plate_Struct.UInt64Plate Plate, int currentColor, List <int> setid, UInt64 set)
        {
            Plate.Lastplate      = Plate.plate;
            Plate.Lastblack      = Plate.black;
            Plate.Lastwhite      = Plate.white;
            Plate.lastblackcount = Plate.blackcount;
            Plate.lastwhitecount = Plate.whitecount;

            if (currentColor == -1)
            {
                Plate.blackcount += setid.Count;
                Plate.whitecount -= setid.Count - 1;
                Plate.black      |= set;
                Plate.plate      |= set;
                Plate.white      &= (~set);
            }
            else if (currentColor == 1)
            {
                Plate.whitecount += setid.Count;
                Plate.blackcount -= setid.Count - 1;
                Plate.white      |= set;
                Plate.plate      |= set;
                Plate.black      &= (~set);
            }
            Plate.count = Plate.whitecount + Plate.blackcount;
            return(Plate);
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Plate"></param>
        /// <param name="currentColor"></param>
        /// <param name="x">行数1-8</param>
        /// <param name="y">列数1-8</param>
        /// <returns></returns>
        private Boolean setChess(ref Plate_Struct.UInt64Plate Plate, int currentColor, int x0, int y0, out List <int> setid) //-1:Black 1 White
        {
            int    id0 = y0 * 8 + x0 - 9;                                                                                    //id
            UInt64 set;

            if (x0 <= 0 || y0 <= 0 || id0 < 0 || id0 > 63)
            {
                setid = new List <int>();
                //return false;
            }
            setid = Plate_Struct.getsetid(x0, y0, currentColor, Plate, out set);
            if (set == Plate.Mask[id0])
            {
                return(false);
            }
            else
            {
                Plate = Plate_Struct.setPlate(Plate, currentColor, setid, set);
            }


            MainForm.getInstance().setLabel("White:" + Plate.whitecount + "      Black:" + Plate.blackcount);

            return(true);
        }
Exemplo n.º 3
0
        public Plate()
        {
            InitializeComponent();
            m_Black = Color.Black;
            m_White = Color.White;
            tag     = -1;
            this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            this.SetStyle(ControlStyles.DoubleBuffer, true);
            this.SetStyle(ControlStyles.UserPaint, true);
            this.SetStyle(ControlStyles.ResizeRedraw, true);

            Color c = this.BackColor;

            Bitmap   bmp = new Bitmap(this.Width, this.Height);
            Graphics gc  = Graphics.FromImage(bmp);
            Pen      p   = new Pen(new SolidBrush(Color.Black), 1);

            for (int i = 0; i <= 10; i++)
            {
                gc.DrawLine(p, new Point(1 + i * 30, 1), new Point(1 + i * 30, 240));
                gc.DrawLine(p, new Point(1, 1 + i * 30), new Point(240, 1 + i * 30));
            }
            p.Width = 2;
            gc.DrawLine(p, new Point(0, 0), new Point(0, 240));
            gc.DrawLine(p, new Point(0, 0), new Point(240, 0));
            gc.DrawLine(p, new Point(240, 0), new Point(240, 240));
            gc.DrawLine(p, new Point(0, 240), new Point(240, 240));

            UInt64Plate = Plate_Struct.getPlate();
            drawPlate(gc, UInt64Plate);


            gc.Dispose();
            this.BackgroundImage = (Image)bmp.Clone();
        }
Exemplo n.º 4
0
        private void drawPlate(Graphics gc, Plate_Struct.UInt64Plate Plate)
        {
            for (int y = 1; y <= 8; y++)
            {
                for (int x = 1; x <= 8; x++)
                {
                    if ((Plate.Mask[(y - 1) * 8 + (x - 1)] & Plate.plate) == 0)
                    {
                        continue;
                    }
                    if ((Plate.Mask[(y - 1) * 8 + (x - 1)] & Plate.white) != 0)
                    {
                        drawChess(gc, m_White, x, y);
                    }

                    if ((Plate.Mask[(y - 1) * 8 + (x - 1)] & Plate.black) != 0)
                    {
                        drawChess(gc, m_Black, x, y);
                    }
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 获取需要被翻的列表
        /// </summary>
        /// <param name="id0"></param>
        /// <param name="currentColor"></param>
        /// <param name="Plate"></param>
        /// <returns></returns>
        private static List <int> getSetChess(int id0, int currentColor, Plate_Struct.UInt64Plate Plate)
        {
            List <int> directionList = Plate_Struct.DirectionArray.ToList();
            List <int> setid         = new List <int>();
            int        x0            = id0 - id0 / 8 * 8 + 1;
            int        y0            = id0 / 8 + 1;

            //int id0 = y0 * 8 + x0 - 9;//id
            //set = Plate.Mask[id0];
            setid.Add(id0);
            for (int a = 1; ; a++)
            {
                if (directionList.Count == 0)
                {
                    break;
                }
                for (int i = 0; i < directionList.Count; i++)//8个方向
                {
                    int id = id0 + directionList[i] * a;
                    if (id < 0 || id > 63)//超出边界时,不计算这个方向
                    {
                        directionList.RemoveAt(i);
                        i--;
                        continue;
                    }
                    int y = id / 8 + 1;
                    int x = id - (y - 1) * 8 + 1;

                    int dx = Math.Abs(x - x0);
                    int dy = Math.Abs(y - y0);

                    if (!(dx == 0 || dx == a) || !(dy == 0 || dy == a))//不连续,跨行或跨列,移除方向
                    {
                        directionList.RemoveAt(i);
                        i--;
                        continue;
                    }
                    else
                    {
                        int Color = Plate_Struct.getColor(id, Plate);
                        if (Color == currentColor && a == 1)
                        {
                            directionList.RemoveAt(i);
                            i--;
                            continue;
                        }
                        if (Color == 0)
                        {
                            directionList.RemoveAt(i);
                            i--;
                            continue;
                        }
                        if (Color == currentColor && a > 1)
                        {
                            for (int j = 1; j <= a; j++)
                            {
                                //set |= Plate.Mask[id0 + directionList[i] * j];
                                if (j != a)
                                {
                                    setid.Add(id0 + directionList[i] * j);
                                }
                            }
                            directionList.RemoveAt(i);
                            i--;
                            continue;
                        }
                    }
                }
            }
            return(setid);
        }