コード例 #1
0
        public string Export(Game game)
        {
            Board          currentBoard          = game.BoardTimeline.Current;
            GameConditions currentGameConditions = game.StartingConditions.CalculateEndingGameConditions(currentBoard, game.PreviousMoves.GetStartToCurrent());

            return(ConvertCurrentGameStateToFEN(currentBoard, currentGameConditions));
        }
コード例 #2
0
ファイル: Game.cs プロジェクト: zeisthegd/UnityChessLib
        /// <summary>Creates a Game instance of a given mode with a standard starting Board.</summary>
        /// <param name="mode">Describes which players are human or AI.</param>
        /// <param name="startingConditions">Conditions at the time the board was set up.</param>
        public Game(Mode mode, GameConditions startingConditions)
        {
            Mode                           = mode;
            CurrentTurnSide                = Side.White;
            StartingConditions             = startingConditions;
            BoardTimeline                  = new Timeline <Board>();
            PreviousMoves                  = new Timeline <HalfMove>();
            enPassantCaptureSquareTimeline = new Timeline <Square>();

            BoardTimeline.AddNext(new Board());
            enPassantCaptureSquareTimeline.AddNext(Square.Invalid);
            UpdateAllPiecesLegalMoves(BoardTimeline.Current, enPassantCaptureSquareTimeline.Current, Side.White);
        }
コード例 #3
0
        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}");
        }