示例#1
0
        private bool checkForKing(figure kingMy)
        {
            figureColor oppColor = kingMy.getColor() == figureColor.White ? figureColor.Black : figureColor.White;
            figure      oppKing  = getKing(oppColor);

            return(Math.Abs(kingMy.x - oppKing.x) > 1 || Math.Abs(kingMy.y - oppKing.y) > 1);
        }
示例#2
0
        private bool checkForKnight(figure kingMy)
        {
            int ix;
            int iy;

            for (int i = 0; i <= Knight.stepsForCheck.Length - 1; i++)
            {
                ix = kingMy.x + Knight.stepsForCheck[i].dx;
                iy = kingMy.y + Knight.stepsForCheck[i].dy;
                if (ix <= 7 && iy <= 7 && ix >= 0 && iy >= 0 && board[iy, ix] != null && board[iy, ix].getColor() != kingMy.getColor() && board[iy, ix].getName() == figureType.Knight)
                {
                    return(false);
                }
            }
            return(true);
        }
示例#3
0
        private bool checkForPawn(figure kingMy)
        {
            figureColor kingColor = kingMy.getColor();
            int         ix;
            int         iy;

            for (int i = 0; i <= Pawn.stepForCheck[kingColor].Length - 1; i++)
            {
                ix = kingMy.x + Pawn.stepForCheck[kingColor][i].dx;
                iy = kingMy.y + Pawn.stepForCheck[kingColor][i].dy;
                if (ix <= 7 && ix >= 0 && iy <= 7 && iy >= 0 && board[iy, ix] != null && board[iy, ix].getColor() != kingMy.getColor() && board[iy, ix].getName() == figureType.Pawn)
                {
                    return(false);
                }
            }
            return(true);
        }
示例#4
0
        public bool isValidMove_Ch(int x1, int y1, int x2, int y2)
        {
            figure savedFigure = board[y2, x2];

            board[y2, x2]   = board[y1, x1];
            board[y2, x2].x = x2;
            board[y2, x2].y = y2;
            board[y1, x1]   = null;

            bool res = !isChecked();

            board[y1, x1]   = board[y2, x2];
            board[y1, x1].y = y1;
            board[y1, x1].x = x1;
            board[y2, x2]   = savedFigure;

            return(res);
        }
示例#5
0
        private bool checkForDia(figure kingMy)
        {
            bool res = true;

            for (int i = 0; (i <= Bishop.stepsForCheck.Length - 1) && res; i++)
            {
                int ix = kingMy.x + Bishop.stepsForCheck[i].dx;
                int iy = kingMy.y + Bishop.stepsForCheck[i].dy;
                while (ix <= 7 && iy <= 7 && ix >= 0 && iy >= 0)
                {
                    if (board[iy, ix] != null)
                    {
                        res = res && ((board[iy, ix].getColor() == kingMy.getColor()) ||
                                      (board[iy, ix].getName() != figureType.Queen && board[iy, ix].getName() != figureType.Bishop));
                        break;
                    }
                    ix += Bishop.stepsForCheck[i].dx;
                    iy += Bishop.stepsForCheck[i].dy;
                }
            }
            return(res);
        }