Пример #1
0
        internal void SetGameState()
        {
            Player opponent      = WhoseTurn;
            Player lastPlayer    = ChessUtilities.RevertPlayer(opponent);
            bool   isInCheck     = ChessUtilities.IsPlayerInCheck(opponent, this);
            var    hasValidMoves = ChessUtilities.GetValidMoves(this).Count > 0;

            if (isInCheck && !hasValidMoves)
            {
                GameState = lastPlayer == Player.White ? GameState.WhiteWinner : GameState.BlackWinner;
                return;
            }

            if (!hasValidMoves)
            {
                GameState = GameState.Stalemate;
                return;
            }

            if (isInCheck)
            {
                GameState = opponent == Player.White ? GameState.WhiteInCheck : GameState.BlackInCheck;
                return;
            }
            GameState = IsInsufficientMaterial() ? GameState.Draw : GameState.NotCompleted;
        }
Пример #2
0
        internal bool PlayerWillBeInCheck(Move move)
        {
            if (move == null)
            {
                throw new ArgumentNullException(nameof(move));
            }

            ChessGame clone = DeepClone(); // Make the move on this board to keep original board as is.
            Piece     piece = clone[move.Source];

            clone.Board[(int)move.Source.Rank, (int)move.Source.File]           = null;
            clone.Board[(int)move.Destination.Rank, (int)move.Destination.File] = piece;

            return(ChessUtilities.IsPlayerInCheck(move.Player, clone));
        }
Пример #3
0
        internal bool PlayerWillBeInCheck(Move move)
        {
            if (move == null)
            {
                throw new ArgumentNullException(nameof(move));
            }

            ChessGame clone = DeepClone();                               // Make the move on this board to keep original board as is.
            Piece?    piece = clone[move.Source.File, move.Source.Rank]; // TODO: throwing causes un-intended behavior. ?? throw new ArgumentException("Invalid move", nameof(move));

            clone.Board[(int)move.Source.Rank][(int)move.Source.File]           = null;
            clone.Board[(int)move.Destination.Rank][(int)move.Destination.File] = piece;

            return(ChessUtilities.IsPlayerInCheck(move.Player, clone));
        }