ChessDotNet.Variants.Atomic.AtomicChessGame.KingIsGone C# (CSharp) Method

KingIsGone() public method

public KingIsGone ( Player player ) : bool
player Player
return bool
        public virtual bool KingIsGone(Player player)
        {
            Cache<bool> cache = player == Player.White ? kingIsGoneCacheWhite : kingIsGoneCacheBlack;
            if (cache.CachedAt == Moves.Count)
            {
                return cache.Value;
            }

            for (int f = 0; f < BoardWidth; f++)
            {
                for (int r = 1; r <= BoardHeight; r++)
                {
                    Piece p = GetPieceAt((File)f, r);
                    if (p is King && p.Owner == player)
                    {
                        return cache.UpdateCache(false, Moves.Count);
                    }
                }
            }
            return cache.UpdateCache(true, Moves.Count);
        }

Usage Example

        protected virtual bool WouldBeSuicideOrInvalidSelfMoveInCheck(Move move, Player player)
        {
            ChessUtilities.ThrowIfNull(move, nameof(move));
            var copy = new AtomicChessGame(Board, player);

            copy.ApplyMove(move, true);
            bool ownKingIsGone   = copy.KingIsGone(player);
            bool otherKingIsGone = copy.KingIsGone(ChessUtilities.GetOpponentOf(player));

            if (ownKingIsGone)
            {
                return(true);
            }
            else if (otherKingIsGone)
            {
                return(false);
            }
            else
            {
                return(copy.IsInCheck(player));
            }
        }
All Usage Examples Of ChessDotNet.Variants.Atomic.AtomicChessGame::KingIsGone