コード例 #1
0
        public Game Copy()
        {
            var gameCopy = new Game {
                Board = new Board()
            };

            gameCopy.WhitePlayer = WhitePlayer.Copy();
            gameCopy.BlackPlayer = BlackPlayer.Copy();

            CopyPieces(WhitePlayer, gameCopy);
            CopyPieces(BlackPlayer, gameCopy);

            gameCopy.Ended         = Ended;
            gameCopy.IsStaleMate   = IsStaleMate;
            gameCopy.CurrentPlayer = CurrentPlayer.Color == Color.White ? gameCopy.WhitePlayer : gameCopy.BlackPlayer;
            if (Winner != null)
            {
                gameCopy.Winner = Winner.Color == Color.White ? gameCopy.WhitePlayer : gameCopy.BlackPlayer;
            }
            gameCopy.WhitePlayer.Material = WhitePlayer.Material;
            gameCopy.BlackPlayer.Material = BlackPlayer.Material;
            gameCopy.Hash            = Hash;
            gameCopy.EnPassantFile   = EnPassantFile;
            gameCopy.InitialPosition = InitialPosition;
            foreach (var hash in HashHistory)
            {
                gameCopy.HashHistory.Push(hash);
            }
            gameCopy.CommandCount = CommandCount;
            gameCopy.MovesSinceLastCaptureOrPawnMove = MovesSinceLastCaptureOrPawnMove;
            gameCopy.SetPieceFastAccess();
            return(gameCopy);
        }
コード例 #2
0
        public string GetFEN()
        {
            var sb = new StringBuilder();

            for (Rank rank = Rank._8; rank >= 0; rank--)
            {
                var emptyCount = 0;
                for (File file = File.A; file <= File.H; file++)
                {
                    var square = Board.Squares[(int)file + (int)rank * 8];
                    if (square.Piece == null)
                    {
                        emptyCount++;
                    }
                    else
                    {
                        if (emptyCount > 0)
                        {
                            sb.Append(emptyCount);
                            emptyCount = 0;
                        }
                        sb.Append(square.Piece.FenChar);
                    }
                }
                if (emptyCount > 0)
                {
                    sb.Append(emptyCount);
                    emptyCount = 0;
                }
                if (rank > Rank._1)
                {
                    sb.Append("/");
                }
            }

            sb.Append(" ");
            sb.Append(CurrentPlayer == WhitePlayer ? "w" : "b");
            sb.Append(" ");
            //todo: also check king and rook placement and movecount
            var castlWhite = WhitePlayer.CastlingToFEN();
            var castlBlack = BlackPlayer.CastlingToFEN();

            sb.Append(castlWhite + castlBlack);
            if (castlWhite + castlBlack == "")
            {
                sb.Append("-");
            }
            sb.Append(" ");

            var enpRank = CurrentPlayer == WhitePlayer ? "6" : "3";

            sb.Append(EnPassantFile.HasValue ? EnPassantFile.Value.ToString().ToLower() + enpRank : "-");
            sb.Append(" ");
            sb.Append(MovesSinceLastCaptureOrPawnMove);
            sb.Append(" ");
            sb.Append(CommandCount / 2 + 1);

            return(sb.ToString());
        }
コード例 #3
0
ファイル: Game.cs プロジェクト: venator21/chessgame
 public Game()
 {
     GameStatus    = GameStatus.InProgress;
     WhitePlayer   = new WhitePlayer();
     BlackPlayer   = new BlackPlayer();
     CurrentPlayer = WhitePlayer;
     board         = new Board();
 }