Exemplo n.º 1
0
        private static void InterpretRegex(string moveNotation, out string coordinatesFromMove,
                                           out string checkOrCheckMate, out string pieceUppercase,
                                           Move move, string pattern, bool isCapture, out char promotion)
        {
            Match  match = Regex.Match(moveNotation, pattern);
            string file;

            if (match.Success)
            {
                coordinatesFromMove = match.Groups["coordinates"].Value;
                checkOrCheckMate    = match.Groups["checkOrCheckMate"].Value;
                pieceUppercase      = match.Groups["pieceUppercase"].Value != "" ? match.Groups["pieceUppercase"].Value : "P";
                move.IsCapture      = isCapture;
                file = match.Groups["file"].Value;
                if (file != "")
                {
                    move.Y = MoveNotationCoordinatesConverter.ConvertChessCoordinateFileToArrayIndex(file);
                }
                promotion = match.Groups["promotion"].Value != "" ? match.Groups["promotion"].Value.First() : ' ';
            }
            else
            {
                throw new InvalidOperationException("Invalid move!");
            }
        }
Exemplo n.º 2
0
        internal static Move TransformIntoMoveInstance(Piece item, Cell currentCell)
        {
            Move move   = new Move();
            var  coords = MoveNotationCoordinatesConverter.ConvertChessCoordinatesToArrayIndexes(currentCell.X, currentCell.Y);

            move.Coordinate = coords;
            move.Name       = item.Name;
            move.PieceColor = item.PieceColor;
            return(move);
        }
Exemplo n.º 3
0
        private static void ConvertNotationMoveIntoMove(PieceColor pieceColor, string coordinatesFromMove, char promotion, string checkOrCheckMate, string pieceUppercase, Move move)
        {
            var coordinate = MoveNotationCoordinatesConverter.ConvertChessCoordinatesToArrayIndexes(coordinatesFromMove);

            move.Coordinate  = coordinate;
            move.Promotion   = CreatePiece(promotion, pieceColor);
            move.Name        = ConvertPieceInitialFromMoveToPieceName(pieceUppercase);
            move.PieceColor  = pieceColor;
            move.IsCheck     = checkOrCheckMate.Length == 1 ? true : false;
            move.IsCheckMate = checkOrCheckMate.Length == 2 ? true : false;
            move.Coordinates = coordinatesFromMove;
        }