Пример #1
0
        public bool ValidMove(ChessPiece[,] chessboard, ChessPiece chessPiece, Position from, Position to)
        {
            int hor = Math.Abs(to.col - from.col);
            int ver = Math.Abs(to.row - from.row);

            switch (chessPiece.type)
            {
            case ChessPieceType.Pawn:
                if (hor == 0 && ver == 1)
                {
                    return(true);
                }
                else if ((hor == 0 && ver == 2) && (chessPiece.uses == 0))
                {
                    return(true);
                }
                else if (hor == 1 && ver == 1)
                {
                    if ((chessPiece.colour != chessboard[to.row, to.col].colour) && (chessboard[to.row, to.col] != null))
                    {
                        return(true);
                    }
                }
                break;

            case ChessPieceType.Rook:
                if (hor * ver == 0)
                {
                    return(true);
                }
                break;

            case ChessPieceType.Knight:
                if (hor * ver == 2)
                {
                    return(true);
                }
                break;

            case ChessPieceType.Bishop:
                if (hor == ver)
                {
                    return(true);
                }
                break;

            case ChessPieceType.Queen:
                if (hor * ver == 0 || hor == ver)
                {
                    return(true);
                }
                break;

            case ChessPieceType.King:
                if (hor == 1 || ver == 1 || (hor == 1 && ver == 1))
                {
                    return(true);
                }
                break;
            }
            return(false);
        }
Пример #2
0
 public ChessPiece[,] CreateChessboard()
 {
     ChessPiece[,] chessboard = new ChessPiece[8, 8];
     return(chessboard);
 }