private static string ConvertCurrentGameStateToFEN(Board currentBoard, GameConditions currentGameConditions) { string toMoveString = currentGameConditions.WhiteToMove ? "w" : "b"; bool areAnyCastlingsAvailable = currentGameConditions.WhiteCanCastleKingside || currentGameConditions.WhiteCanCastleQueenside || currentGameConditions.BlackCanCastleKingside || currentGameConditions.BlackCanCastleQueenside; string castlingInfoString = areAnyCastlingsAvailable ? $"{(currentGameConditions.WhiteCanCastleKingside ? "K" : "")}{(currentGameConditions.WhiteCanCastleQueenside ? "Q" : "")}{(currentGameConditions.BlackCanCastleKingside ? "k" : "")}{(currentGameConditions.BlackCanCastleQueenside ? "q" : "")}" : "-"; string enPassantSquareString = currentGameConditions.EnPassantSquare.IsValid ? SquareUtil.SquareToString(currentGameConditions.EnPassantSquare) : "-"; return($"{CalculateRankStrings(currentBoard)} {toMoveString} {castlingInfoString} {enPassantSquareString} {currentGameConditions.HalfMoveClock} {currentGameConditions.TurnNumber}"); }
// TODO handle ambiguous piece moves. public string ToAlgebraicNotation() { string moveText = ""; string pieceSymbol = Piece is Pawn ? CapturedPiece ? SquareUtil.FileIntToCharMap[Move.Start.File] : "" : pieceTypeToANSymbolMap[Piece.GetType()]; string captureText = CapturedPiece ? "x" : ""; string endSquareString = SquareUtil.SquareToString(Move.End); string suffix = CausedCheckmate ? "#" : CausedCheck ? "+" : ""; switch (Piece) { case King _: if (Move is CastlingMove) { moveText += Move.End.File == 3 ? $"O-O-O{suffix}" : $"O-O{suffix}"; } else { moveText += $"{pieceSymbol}{captureText}{endSquareString}{suffix}"; } break; case Pawn _: string pawnPromotionPieceSymbol = Move is PromotionMove promotionMove ? pieceTypeToANSymbolMap[promotionMove.AssociatedPiece.GetType()] : ""; moveText += $"{pieceSymbol}{captureText}{endSquareString}{pawnPromotionPieceSymbol}{suffix}"; break; case Knight _: case Bishop _: case Rook _: case Queen _: moveText += $"{pieceSymbol}{captureText}{endSquareString}{suffix}"; break; } return(moveText); }