Example #1
0
        internal static IMove ParseChessmanMove(string moveString, bool color, Board board)
        {
            var to          = MoveParser.GetToPosition(moveString);
            var isPieceType = PieceParser.ParsePieceTypePredicate(moveString[0]);
            var pieces      = PiecesThatCanBeMovedTo(to, isPieceType, board);

            if (moveString.Length > 3 && moveString[1] != 'x')
            {
                pieces = SelectPiecesByPosition(moveString, pieces, board);
            }

            if (pieces.Count() != 1)
            {
                throw new ArgumentException();
            }

            var piece = pieces.First();
            var move  = new Move(piece, to, board);

            if (move.IsCapture == (moveString[1] == 'x') && piece.IsMovePossible(move))
            {
                return(move);
            }
            throw new ArgumentException();
        }
Example #2
0
        private static (Pawn, Position) GetPawnAndToPosition(string pawnMoveString, bool color, Board board)
        {
            var to    = MoveParser.GetToPosition(pawnMoveString);
            var from  = GetPawnPosition(pawnMoveString, to, color, board);
            var piece = GetPieceAtPosition(board, from);

            if (piece.Color != color || piece is Pawn)
            {
                return((Pawn)piece, to);
            }
            throw new ArgumentException();
        }