Beispiel #1
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();
        }
Beispiel #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);
        }
Beispiel #3
0
        private void Plate_MouseUp(object sender, MouseEventArgs e)
        {
            if (tag == -1)
            {
                int x = e.X / 30 + 1;
                int y = e.Y / 30 + 1;

                List <int> setidList;

                List <int> cellList;
                if (!Plate_Struct.CheckPlate(tag, UInt64Plate, out cellList))
                {
                    tag *= -1;
                    return;
                }

                if (!setChess(ref UInt64Plate, tag, x, y, out setidList))
                {
                    return;
                }

                Refresh(tag, setidList);
                tag *= -1;
            }

            if (tag == 1)
            {
                List <int> cellList;
                if (Plate_Struct.CheckPlate(tag, UInt64Plate, out cellList))
                {
                    int        idfromCaculate = Plate_Struct.CacuLate(UInt64Plate, -tag, 5);
                    int        y1             = idfromCaculate / 8 + 1;
                    int        x1             = idfromCaculate - y1 * 8 + 9;
                    List <int> setidList      = null;
                    if (x1 <= 0 || y1 <= 0)
                    {
                        Console.WriteLine();
                    }
                    if (!setChess(ref UInt64Plate, tag, x1, y1, out setidList))
                    {
                        return;
                    }
                    Refresh(tag, setidList);
                    tag *= -1;
                }
                else
                {
                    tag *= -1;
                    return;
                }
            }

            if (UInt64Plate.count == 64)
            {
                MessageBox.Show((UInt64Plate.whitecount > UInt64Plate.blackcount ? "Winner:White" : UInt64Plate.whitecount == UInt64Plate.blackcount ? "平局" : "Winner:Black"));
            }

            //tag *= -1;
        }
Beispiel #4
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);
        }