Knowing when to block is almost a science and trying to distill those nuggets of knowledge into hard, inflexible code is challenging. The computer will block each attacking creature 50% of the time. (If you have four attacking creatures the computer will usually block two of them.) While this might seem arbitrary it also makes the computer less predictable. (Maybe 50% should be something else like 30% but I really don’t know.)
And finally the bad news, the computer still does a few stupid things. The AI doesn’t take into account activated abilities or a creatures “worth”. The AI sees Royal Assassin, Soul Warden, and Eager Cadet as all the same, just a 1/1 creature. On the bright side the AI does take into account first strike, double strike, deathtouch, and flying. Occasionally, 20% of the time, the computer will block a non-flyer with a flyer or not attack with a creature just to surprise you.
The computer also checks to see if it can win the game by attacking with all of its creatures. I nicknamed this “assault attacking” in my code. The programming is a little tricky because it presumes that the biggest attacking creatures will be chump blocked.