コード例 #1
0
        public virtual bool WouldBeInCheckAfter(Move move, Player player)
        {
            ChessUtilities.ThrowIfNull(move, "move");
            GameCreationData gcd = new GameCreationData();

            gcd.Board = Board;
            gcd.CanWhiteCastleKingSide  = CanWhiteCastleKingSide;
            gcd.CanWhiteCastleQueenSide = CanWhiteCastleQueenSide;
            gcd.CanBlackCastleKingSide  = CanBlackCastleKingSide;
            gcd.CanBlackCastleQueenSide = CanBlackCastleQueenSide;
            gcd.EnPassant = null;
            if (_moves.Count > 0)
            {
                DetailedMove last = _moves.Last();
                if (last.Piece is Pawn && new PositionDistance(last.OriginalPosition, last.NewPosition).DistanceY == 2)
                {
                    gcd.EnPassant = new Position(last.NewPosition.File, last.Player == Player.White ? 3 : 6);
                }
            }
            gcd.HalfMoveClock  = i_halfMoveClock;
            gcd.FullMoveNumber = i_fullMoveNumber;
            ChessGame copy = new ChessGame(gcd);
            Piece     p    = copy.GetPieceAt(move.OriginalPosition);

            copy.SetPieceAt(move.OriginalPosition.File, move.OriginalPosition.Rank, null);
            copy.SetPieceAt(move.NewPosition.File, move.NewPosition.Rank, p);
            return(copy.IsInCheck(player));
        }
コード例 #2
0
ファイル: ChessGame.cs プロジェクト: asibahi/Chess.NET
        void UseGameCreationData(GameCreationData data)
        {
            Board     = CloneBoard(data.Board);
            WhoseTurn = data.WhoseTurn;
            Piece e1 = GetPieceAt(File.E, 1);
            Piece e8 = GetPieceAt(File.E, 8);
            Piece a1 = GetPieceAt(File.A, 1);
            Piece h1 = GetPieceAt(File.H, 1);
            Piece a8 = GetPieceAt(File.A, 8);
            Piece h8 = GetPieceAt(File.H, 8);

            _whiteKingMoved  |= (!(e1 is King) || e1.Owner != Player.White);
            _blackKingMoved  |= (!(e8 is King) || e8.Owner != Player.Black);
            _whiteRookAMoved |= (!(a1 is Rook) || a1.Owner != Player.White || !data.CanWhiteCastleQueenSide);
            _whiteRookHMoved |= (!(h1 is Rook) || h1.Owner != Player.White || !data.CanWhiteCastleKingSide);
            _blackRookAMoved |= (!(a8 is Rook) || a8.Owner != Player.Black || !data.CanBlackCastleQueenSide);
            _blackRookHMoved |= (!(h8 is Rook) || h8.Owner != Player.Black || !data.CanBlackCastleKingSide);

            if (data.EnPassant != null)
            {
                var latestMove =
                    new DetailedMove(
                        new Move(new Square(data.EnPassant.File, data.WhoseTurn == Player.White ? 7 : 2),
                                 new Square(data.EnPassant.File, data.WhoseTurn == Player.White ? 5 : 4),
                                 ChessUtilities.GetOpponentOf(data.WhoseTurn)),
                        new Pawn(ChessUtilities.GetOpponentOf(data.WhoseTurn)),
                        false,
                        CastlingType.None);

                _moves.Add(latestMove);
            }

            _halfMoveClock  = data.HalfMoveClock;
            _fullMoveNumber = data.FullMoveNumber;
        }
コード例 #3
0
        public virtual bool WouldBeInCheckAfter(Move move, ChessPlayer player)
        {
            ChessUtility.ThrowIfNull(move, "move");
            GameCreationData gcd = new GameCreationData
            {
                Board = Board,
                CanWhiteCastleKingSide  = CanWhiteCastleKingSide,
                CanWhiteCastleQueenSide = CanWhiteCastleQueenSide,
                CanBlackCastleKingSide  = CanBlackCastleKingSide,
                CanBlackCastleQueenSide = CanBlackCastleQueenSide,
                EnPassant = null
            };

            if (_moves.Count > 0)
            {
                DetailedMove last = _moves.Last();
                if (last.Piece is Pawn && new BoardDistance(last.OriginalPosition, last.NewPosition).Y == 2)
                {
                    gcd.EnPassant = new BoardPosition(last.NewPosition.File, last.Player == ChessPlayer.White ? 3 : 6);
                }
            }
            gcd.HalfMoveClock  = _halfMoveClock;
            gcd.FullMoveNumber = _fullMoveNumber;
            ChessGame copy = new ChessGame(gcd);

            copy.ApplyMove(move, true);
            return(copy.IsInCheck(player));
        }
コード例 #4
0
        protected virtual void UseGameCreationData(GameCreationData data)
        {
            Board     = CloneBoard(data.Board);
            WhoseTurn = data.WhoseTurn;
            ChessPiece e1 = GetPieceAt(ChessFile.E, 1);
            ChessPiece e8 = GetPieceAt(ChessFile.E, 8);
            ChessPiece a1 = GetPieceAt(ChessFile.A, 1);
            ChessPiece h1 = GetPieceAt(ChessFile.H, 1);
            ChessPiece a8 = GetPieceAt(ChessFile.A, 8);
            ChessPiece h8 = GetPieceAt(ChessFile.H, 8);

            CanBlackCastleKingSide = CanBlackCastleQueenSide = CanWhiteCastleKingSide = CanWhiteCastleQueenSide = CastlingCanBeLegal;
            if (CastlingCanBeLegal)
            {
                if (!(e1 is King) || e1.Owner != ChessPlayer.White)
                {
                    CanWhiteCastleKingSide = CanWhiteCastleQueenSide = false;
                }
                if (!(e8 is King) || e8.Owner != ChessPlayer.Black)
                {
                    CanBlackCastleKingSide = CanBlackCastleQueenSide = false;
                }
                if (!(a1 is Rook) || a1.Owner != ChessPlayer.White || !data.CanWhiteCastleQueenSide)
                {
                    CanWhiteCastleQueenSide = false;
                }
                if (!(h1 is Rook) || h1.Owner != ChessPlayer.White || !data.CanWhiteCastleKingSide)
                {
                    CanWhiteCastleKingSide = false;
                }
                if (!(a8 is Rook) || a8.Owner != ChessPlayer.Black || !data.CanBlackCastleQueenSide)
                {
                    CanBlackCastleQueenSide = false;
                }
                if (!(h8 is Rook) || h8.Owner != ChessPlayer.Black || !data.CanBlackCastleKingSide)
                {
                    CanBlackCastleKingSide = false;
                }
            }

            if (data.EnPassant != null)
            {
                DetailedMove latestMove = new DetailedMove(new Move(new BoardPosition(data.EnPassant.File, data.WhoseTurn == ChessPlayer.White ? 7 : 2),
                                                                    new BoardPosition(data.EnPassant.File, data.WhoseTurn == ChessPlayer.White ? 5 : 4),
                                                                    ChessUtility.GetOpponentOf(data.WhoseTurn)),
                                                           new Pawn(ChessUtility.GetOpponentOf(data.WhoseTurn)),
                                                           false,
                                                           CastlingType.None);
                _moves.Add(latestMove);
            }

            _halfMoveClock  = data.HalfMoveClock;
            _fullMoveNumber = data.FullMoveNumber;
        }
コード例 #5
0
        protected virtual void UseGameCreationData(GameCreationData data)
        {
            Board     = CloneBoard(data.Board);
            WhoseTurn = data.WhoseTurn;

            Piece[] eighthRank = Board[0];
            Piece[] firstRank  = Board[7];

            CanBlackCastleKingSide = CanBlackCastleQueenSide = CanWhiteCastleKingSide = CanWhiteCastleQueenSide = CastlingCanBeLegal;
            InitialWhiteKingFile   = (File)Array.IndexOf(firstRank, new King(Player.White));
            InitialBlackKingFile   = (File)Array.IndexOf(eighthRank, new King(Player.Black));
            if (CastlingCanBeLegal)
            {
                CanBlackCastleKingSide  = data.CanBlackCastleKingSide;
                CanBlackCastleQueenSide = data.CanBlackCastleQueenSide;
                CanWhiteCastleKingSide  = data.CanWhiteCastleKingSide;
                CanWhiteCastleQueenSide = data.CanWhiteCastleQueenSide;
            }
            InitialBlackRookFileQueensideCastling = CanBlackCastleQueenSide ? (File)Array.IndexOf(eighthRank, new Rook(Player.Black)) : File.None;
            InitialBlackRookFileKingsideCastling  = CanBlackCastleKingSide ? (File)Array.LastIndexOf(eighthRank, new Rook(Player.Black)) : File.None;
            InitialWhiteRookFileQueensideCastling = CanWhiteCastleQueenSide ? (File)Array.IndexOf(firstRank, new Rook(Player.White)) : File.None;
            InitialWhiteRookFileKingsideCastling  = CanWhiteCastleKingSide ? (File)Array.LastIndexOf(firstRank, new Rook(Player.White)) : File.None;

            if (InitialBlackRookFileQueensideCastling == File.None)
            {
                CanBlackCastleQueenSide = false;
            }
            if (InitialBlackRookFileKingsideCastling == File.None)
            {
                CanBlackCastleKingSide = false;
            }
            if (InitialWhiteRookFileKingsideCastling == File.None)
            {
                CanWhiteCastleKingSide = false;
            }
            if (InitialWhiteRookFileQueensideCastling == File.None)
            {
                CanWhiteCastleQueenSide = false;
            }

            if (data.EnPassant != null)
            {
                DetailedMove latestMove = new DetailedMove(new Move(new Position(data.EnPassant.File, data.WhoseTurn == Player.White ? 7 : 2),
                                                                    new Position(data.EnPassant.File, data.WhoseTurn == Player.White ? 5 : 4),
                                                                    ChessUtilities.GetOpponentOf(data.WhoseTurn)),
                                                           new Pawn(ChessUtilities.GetOpponentOf(data.WhoseTurn)),
                                                           false,
                                                           CastlingType.None);
                _moves.Add(latestMove);
            }

            i_halfMoveClock  = data.HalfMoveClock;
            i_fullMoveNumber = data.FullMoveNumber;
        }
コード例 #6
0
 protected virtual void AddDetailedMove(DetailedMove dm)
 {
     _moves.Add(dm);
 }
コード例 #7
0
ファイル: ChessGame.cs プロジェクト: ProgramFOX/Chess.NET
        protected virtual void UseGameCreationData(GameCreationData data)
        {
            Board = CloneBoard(data.Board);
            WhoseTurn = data.WhoseTurn;
            Piece e1 = GetPieceAt(File.E, 1);
            Piece e8 = GetPieceAt(File.E, 8);
            Piece a1 = GetPieceAt(File.A, 1);
            Piece h1 = GetPieceAt(File.H, 1);
            Piece a8 = GetPieceAt(File.A, 8);
            Piece h8 = GetPieceAt(File.H, 8);
            CanBlackCastleKingSide = CanBlackCastleQueenSide = CanWhiteCastleKingSide = CanWhiteCastleQueenSide = CastlingCanBeLegal;
            if (CastlingCanBeLegal)
            {
                if (!(e1 is King) || e1.Owner != Player.White)
                    CanWhiteCastleKingSide = CanWhiteCastleQueenSide = false;
                if (!(e8 is King) || e8.Owner != Player.Black)
                    CanBlackCastleKingSide = CanBlackCastleQueenSide = false;
                if (!(a1 is Rook) || a1.Owner != Player.White || !data.CanWhiteCastleQueenSide)
                    CanWhiteCastleQueenSide = false;
                if (!(h1 is Rook) || h1.Owner != Player.White || !data.CanWhiteCastleKingSide)
                    CanWhiteCastleKingSide = false;
                if (!(a8 is Rook) || a8.Owner != Player.Black || !data.CanBlackCastleQueenSide)
                    CanBlackCastleQueenSide = false;
                if (!(h8 is Rook) || h8.Owner != Player.Black || !data.CanBlackCastleKingSide)
                    CanBlackCastleKingSide = false;
            }

            if (data.EnPassant != null)
            {
                DetailedMove latestMove = new DetailedMove(new Move(new Position(data.EnPassant.File, data.WhoseTurn == Player.White ? 7 : 2),
                                                                    new Position(data.EnPassant.File, data.WhoseTurn == Player.White ? 5 : 4),
                                                                    ChessUtilities.GetOpponentOf(data.WhoseTurn)),
                                          new Pawn(ChessUtilities.GetOpponentOf(data.WhoseTurn)),
                                          false,
                                          CastlingType.None);
                _moves.Add(latestMove);
            }

            _halfMoveClock = data.HalfMoveClock;
            _fullMoveNumber = data.FullMoveNumber;
        }