Esempio n. 1
0
        private void IsCheckmate(object sender, CheckedArgs e)
        {
            King king = e.King;

            foreach (Piece piece in board.Pieces)
            {
                if (piece.Color == e.Color)
                {
                    foreach (Tuple <int, int> move in board.GetAllPossibleMoves(piece))
                    {
                        Tuple <int, int> oldPosition    = piece.Position;
                        Piece            occupyingPiece = board.GetPiece(move);

                        board.UpdatePosition(piece, move);
                        DetectCheck();
                        if (king.InCheck)
                        {
                            board.UpdatePosition(piece, oldPosition);
                            if (occupyingPiece != null)
                            {
                                board.PlacePiece(occupyingPiece);
                            }
                            ;
                        }
                        else
                        {
                            board.UpdatePosition(piece, oldPosition);
                            if (occupyingPiece != null)
                            {
                                board.PlacePiece(occupyingPiece);
                            }
                            ;
                            return;
                        }
                    }
                }
            }
            OnCheckMate(this, new CheckMateArgs(king));
        }