A smart spider

So, this week-end I decided to get a break to my Machine Learning course and paint a bit of stuff, including the kid's wood house.

There is a side with a plastic windows, and my task was to paint the wood, trying to go as much as possible with the brush inside the hole between the wood and the plastic:

Now, while I did just started from the top, a spider that was hidden in the hole between the plastic and the wood a bit more down, did the first smart thing: he (or she?) did come out. He learned that if I would have continued, I would have reach his hideout with the brush and killed him. He did a second smart thing: he went on the windows, on the plastic side, not on the wood side. Then he waited a bit, and as I was painting the wood from up to down… he moved across the plastic side to go up “against the gradient” and reach a calm, safe area.

I wander what is the neural structure that even in a such a simple creature allowed him to make the right decisions to maximise his fitness and how much powerful computers we would need to match these abilities.