Exemple #1
0
        public static string UCIMovesFromMoveObjects(this IEnumerable <Move> moveCollection)
        {
            var moves = moveCollection.ToArray();

            if (!moves.Any())
            {
                return("");
            }

            return(string.Join(" ", moves.Select(m =>
            {
                var pString = m.MoveType == MoveType.Promotion
                    ? char.ToLower(PieceHelpers.GetCharFromPromotionPiece(m.PromotionPiece)).ToString()
                    : "";
                return $"{m.SourceIndex.ToSquareString()}{m.DestinationIndex.ToSquareString()}{pString}";
            })));
        }
Exemple #2
0
        public override string Translate(Move move, Board preMoveBoard, Board postMoveBoard)
        {
            string capture = "", promotionPiece = "", checkInfo = "", result = "";

            if (move.MoveType == MoveType.Castle)
            {
                return(CastleToSan(move));
            }


            var strSrcPiece = GetSANSourceString(preMoveBoard, move);

            if (postMoveBoard.PieceCaptured.HasValue)
            {
                capture = "x";
            }

            if (move.MoveType == MoveType.Promotion)
            {
                promotionPiece = $"={PieceHelpers.GetCharFromPromotionPiece(move.PromotionPiece)}";
            }

            if (BoardHelpers.IsColorInCheck(postMoveBoard.Occupancy, postMoveBoard.ActivePlayer))
            {
                checkInfo = "+";
                if (postMoveBoard.GameState == GameState.Checkmate)
                {
                    checkInfo = "#";
                }
            }

            //Get piece representation
            var san =
                $"{strSrcPiece}{capture}{move.DestinationIndex.ToSquareString()}{promotionPiece}{checkInfo} {result}"
                .Trim();

            return(san);
        }
Exemple #3
0
 private static char?PromotionPieceChar(Move move)
 {
     return(move.MoveType == MoveType.Promotion
         ? char.ToLower(PieceHelpers.GetCharFromPromotionPiece(move.PromotionPiece))
         : (char?)null);
 }