Пример #1
0
        private void CheckForCheckmateOrTie()
        {
            if (WhiteKing.IsAtacked(this) && BlackKing.IsAtacked(this))
            {
                throw new ApplicationException("What the f**k just happened?");
            }

            if (WhiteKing.IsAtacked(this) || BlackKing.IsAtacked(this))
            {
                if (WhiteKing.IsAtacked(this))
                {
                    if (WhiteFigures().All(fig => fig.GetPossibleMoves(this).Count == 0))
                    {
                        OnMate?.Invoke(FigureSide.Black);
                    }
                }

                if (BlackKing.IsAtacked(this))
                {
                    if (BlackFigures().All(fig => fig.GetPossibleMoves(this).Count == 0))
                    {
                        OnMate?.Invoke(FigureSide.White);
                    }
                }
            }
            else
            if (WhiteFigures().All(fig => fig.GetPossibleMoves(this).Count == 0) ||
                BlackFigures().All(fig => fig.GetPossibleMoves(this).Count == 0))
            {
                OnTie?.Invoke();
            }
        }