Example #1
0
        public override int IsCanMove(int y, int x)
        {
            if (!this.IsValidData(y, x))
            {
                return(0);
            }
            int multiple = 1;

            if (this.color == Colors.BLACK)
            {
                multiple = -1;
            }
            if (board.GetFigure(y, x) == null)
            {
                if (x == this.x && y == (this.y + 1 * multiple))
                {
                    return(1);
                }
                if (x == this.x && y == (this.y + 2 * multiple) && board.GetFigure(y - 1 * multiple, x) == null && this.IsFirstStep)
                {
                    return(2);
                }
            }
            if ((x == this.x + 1 || x == this.x - 1) && y == this.y + 1 * multiple)
            {
                Figure figure = this.board.GetFigure(y, x);
                if (figure != null && figure.GetColor() != this.color)
                {
                    return(3);
                }
                else
                {
                    figure = this.board.GetFigure(y - 1 * multiple, x);
                    if (figure != null && figure.GetColor() != this.color && figure.GetType() == typeof(Pawn) && (figure as Pawn).IsAfterFirstStep && (figure as Pawn).FirstStep == board.GetCountSteps() - 1)
                    {
                        return(4);
                    }
                }
            }
            return(0);
        }
Example #2
0
 public void RemoveFigure(Figure figure)
 {
     if (figure != null)
     {
         if (figure.GetColor() == Colors.BLACK)
         {
             this.black_figures.Remove(figure);
         }
         else
         {
             this.white_figures.Remove(figure);
         }
     }
 }
Example #3
0
        public bool IsCheck(Figure fig, int y, int x)
        {
            Figure temp  = GetFigure(y, x);
            int    tempy = fig.GetY();
            int    tempx = fig.GetX();

            Move(fig, y, x);
            if (fig.GetColor() == Colors.BLACK && IsUnderAttack(this.black_king.GetY(), this.black_king.GetX(), Colors.BLACK) > 0 || (fig.GetColor() == Colors.WHITE && IsUnderAttack(this.white_king.GetY(), this.white_king.GetX(), Colors.WHITE) > 0))
            {
                Move(fig, tempy, tempx);
                AddFigure(temp);
                return(true);
            }
            Move(fig, tempy, tempx);
            AddFigure(temp);
            return(false);
        }