Exemple #1
0
        public chessBasic canMoveRoute(int x, int y, chessSquare cq)
        {
            chessBasic cb = new chessBasic();

            int[,] dir = { { -1,  2 }, {  1, -2 },
                           { -1, -2 }, { -2,  1 },
                           {  2, -1 }, { -2, -1 },
                           {  1,  2 }, {  2,  1 } };
            for (int i = 0; i < 8; i++)//騎士的8個走法
            {
                int X = x + dir[i, 0];
                int Y = y + dir[i, 1];
                if (X >= 0 && X < 8 && Y >= 0 && Y < 8)//棋盤內
                {
                    if ((cq.PSquare[x, y] == chessSquare.chessSides.Black && cq.PSquare[X, Y] == chessSquare.chessSides.Black) ||
                        (cq.PSquare[x, y] == chessSquare.chessSides.White && cq.PSquare[X, Y] == chessSquare.chessSides.White))
                    {
                        continue;                                                                                                        //不能黑棋吃黑棋、白棋吃白棋
                    }
                    if (cq.mSquare[X, Y] != chessSquare.chessName.Null)
                    {
                        cb.LCanCheck.Add(new int[] { X, Y });
                    }
                    else
                    {
                        cb.LCanWalk.Add(new int[] { X, Y });
                    }
                }
            }
            return(cb);
        }
Exemple #2
0
        public void canMoveRouteSUpdate(chessBasic cb)
        {
            if (cb == null)
            {
                throw new NullReferenceException();
            }

            //直接使用諮詢時新增之暫時物件
            LCanWalk  = cb.LCanWalk;
            LCanCheck = cb.LCanCheck;
            LSpecial  = cb.LSpecial;
        }
Exemple #3
0
 public chessBasic(chessBasic cb)
 {
     UX        = cb.UX;
     UY        = cb.UY;
     cName     = cb.cName;
     LCanWalk  = new List <int[]>();
     LCanCheck = new List <int[]>();
     LSpecial  = new List <int[]>();
     //LCanWalk = new List<int[]>(cb.LCanWalk);
     //LCanCheck = new List<int[]>(cb.LCanCheck);
     //LSpecial = new List<int[]>(cb.LSpecial);
 }
Exemple #4
0
        public chessBasic canMoveRoute(int x, int y, chessSquare cq)
        {
            cwp = DGetWalkRouteFuc();
            if (cwp == null)
            {
                cwp = new chessWalkPoint(-1, -1, -1, -1);
            }

            cq1 = cq;
            int[,] dir;
            cb = new chessBasic();
            if (cq1.PSquare[x, y] == chessSquare.chessSides.Black)
            {
                if (y == 6)
                {
                    dir = new int[, ] {
                        { -1, -1 }, { 0, -1 }, { 1, -1 }, { 0, -2 }
                    };                                                               //左,中1,右,中2
                    checkRoute(x, y, dir);
                }
                else
                {
                    dir = new int[, ] {
                        { -1, -1 }, { 0, -1 }, { 1, -1 }
                    };                                                    //左,中1,右
                    checkRoute(x, y, dir);
                }
            }
            else
            {
                if (y == 1)
                {
                    dir = new int[, ] {
                        { -1, 1 }, { 0, 1 }, { 1, 1 }, { 0, 2 }
                    };                                                           //左,中1,右,中2
                    checkRoute(x, y, dir);
                }
                else
                {
                    dir = new int[, ] {
                        { -1, 1 }, { 0, 1 }, { 1, 1 }
                    };                                                 //左,中1,右
                    checkRoute(x, y, dir);
                }
            }
            dir = new int[, ] {
                { -1, 0 }, { 1, 0 }
            };
            specialPawnCheckRoute(x, y, dir);//吃過路兵
            return(cb);
        }
Exemple #5
0
        public chessBasic canMoveRoute(int x, int y, chessSquare cq)
        {
            chessBasic cb = new chessBasic();

            int[,] dir = { { -1,  1 }, {  0,  1 },
                           {  1,  1 }, { -1,  0 },
                           {  1,  0 }, { -1, -1 },
                           {  0, -1 }, {  1, -1 } };
            for (int i = 0; i < 8; i++)//皇后8個方向
            {
                int X    = x + dir[i, 0];
                int Y    = y + dir[i, 1];
                int flag = 1;
                for (int j = 0; j < 8 && flag == 1; j++)
                {
                    if (X >= 0 && X < 8 && Y >= 0 && Y < 8)//棋盤內
                    {
                        if ((cq.PSquare[x, y] == chessSquare.chessSides.Black && cq.PSquare[X, Y] == chessSquare.chessSides.Black) ||
                            (cq.PSquare[x, y] == chessSquare.chessSides.White && cq.PSquare[X, Y] == chessSquare.chessSides.White))
                        {
                            continue;                                                                                                        //不能黑棋吃黑棋、白棋吃白棋
                        }
                        if (cq.mSquare[X, Y] != chessSquare.chessName.Null)
                        {
                            cb.LCanCheck.Add(new int[] { X, Y });
                            flag = 0;
                        }
                        else
                        {
                            cb.LCanWalk.Add(new int[] { X, Y });
                        }
                    }
                    X = X + dir[i, 0];
                    Y = Y + dir[i, 1];
                }
            }
            return(cb);
        }
Exemple #6
0
        public chessBasic canMoveRoute(int x, int y, chessSquare cq)
        {
            cq1 = cq;
            chessBasic cb = new chessBasic();

            int[,] dir = { { -1,  1 }, {  0,  1 },
                           {  1,  1 }, { -1,  0 },
                           {  1,  0 }, { -1, -1 },
                           {  0, -1 }, {  1, -1 } };
            for (int i = 0; i < 8; i++)//國王的8個走法
            {
                int X = x + dir[i, 0];
                int Y = y + dir[i, 1];
                if (X >= 0 && X < 8 && Y >= 0 && Y < 8)//棋盤內
                {
                    if ((cq1.PSquare[x, y] == chessSquare.chessSides.Black && cq1.PSquare[X, Y] == chessSquare.chessSides.Black) ||
                        (cq1.PSquare[x, y] == chessSquare.chessSides.White && cq1.PSquare[X, Y] == chessSquare.chessSides.White))
                    {
                        continue;                                                                                                          //不能黑棋吃黑棋、白棋吃白棋
                    }
                    if (cq1.mSquare[X, Y] != chessSquare.chessName.Null)
                    {
                        cb.LCanCheck.Add(new int[] { X, Y });
                    }
                    else
                    {
                        cb.LCanWalk.Add(new int[] { X, Y });
                    }
                }
            }

            if (x == 4 && y == 0 && cq1.PSquare[4, 0] == chessSquare.chessSides.White)
            {
                //白國王[4,0]白城堡[0,0]
                if (cq1.mSquare[0, 0] == chessSquare.chessName.Rook && Rule1((int)chessSquare.chessSides.White, (int)chessSquare.chessName.King, (int)chessSquare.chessSides.White, (int)chessSquare.chessName.Rook, 0) &&
                    Rule2(y, 4, 0) && Rule3(0, y, 4, 0))
                {
                    cb.LSpecial.Add(new int[] { 2, 0, (int)chessSquare.chessSpecial.S_No2 });
                }
                //白國王[4,0]白城堡[7,0]
                if (cq1.mSquare[7, 0] == chessSquare.chessName.Rook && Rule1((int)chessSquare.chessSides.White, (int)chessSquare.chessName.King, (int)chessSquare.chessSides.White, (int)chessSquare.chessName.Rook, 1) &&
                    Rule2(y, 4, 7) && Rule3(0, y, 4, 7))
                {
                    cb.LSpecial.Add(new int[] { 6, 0, (int)chessSquare.chessSpecial.S_No2 });
                }
            }
            else if (x == 4 && y == 7 && cq1.PSquare[4, 7] == chessSquare.chessSides.Black)
            {
                // 黑國王[4,7]黑城堡[0,7]
                if (cq1.mSquare[0, 7] == chessSquare.chessName.Rook && Rule1((int)chessSquare.chessSides.Black, (int)chessSquare.chessName.King, (int)chessSquare.chessSides.Black, (int)chessSquare.chessName.Rook, 0) &&
                    Rule2(y, 4, 0) && Rule3(1, y, 4, 0))
                {
                    cb.LSpecial.Add(new int[] { 2, 7, (int)chessSquare.chessSpecial.S_No2 });
                }
                //黑國王[4,7]黑城堡[7,7]
                if (cq1.mSquare[7, 7] == chessSquare.chessName.Rook && Rule1((int)chessSquare.chessSides.Black, (int)chessSquare.chessName.King, (int)chessSquare.chessSides.Black, (int)chessSquare.chessName.Rook, 1) &&
                    Rule2(y, 4, 7) && Rule3(1, y, 4, 7))
                {
                    cb.LSpecial.Add(new int[] { 6, 7, (int)chessSquare.chessSpecial.S_No2 });
                }
            }
            return(cb);
        }