Exemplo n.º 1
0
        private static IMove ParseMove(string move)
        {
            if (move.Length < 4 || move.Length > 5)
            {
                throw new ArgumentException("The move {0} cannot be parsed as a chess move");
            }
            ChessFile startFile = (ChessFile)Enum.Parse(typeof(ChessFile), move[0].ToString());
            ChessRow  startRow  = (ChessRow)Enum.Parse(typeof(ChessRow), move[1].ToString());

            ChessFile endFile = (ChessFile)Enum.Parse(typeof(ChessFile), move[2].ToString());
            ChessRow  endRow  = (ChessRow)Enum.Parse(typeof(ChessRow), move[3].ToString());

            ChessPiece promotionPiece;

            if (move.Length == 5)
            {
                promotionPiece = (ChessPiece)Enum.Parse(typeof(ChessPiece), move[5].ToString());
            }
            else
            {
                promotionPiece = ChessPiece.noPromotion;
            }

            Square startSquare = new Square(startFile, startRow);
            Square endSquare   = new Square(endFile, endRow);

            return(new Move(startSquare, endSquare, promotionPiece));
        }
Exemplo n.º 2
0
 public Square(ChessFile startFile, ChessRow startRow)
 {
     _startFile = startFile;
     _startRow  = startRow;
 }