The problem is "card.widgets", I'm afraid.
A Card interface has a .widgets attribute, and a Prototype interface has a .widgets attribute, but a Contraption interface does not. While it is occasionally desirable to iterate over the widgets of a contraption instance (as in this case) from the inside, it is somewhat undesirable to expose the same information to code outside the contraption, since it would violate the principle of encapsulation.
Making something along these lines work in a contraption would require a somewhat different approach. Perhaps instead of a grid of buttons you could use a single Canvas widget, capture "click[]" events sent to it, and turn the neighbor-checking logic we used previously "inside-out". It would be a bit more code, but the advantage would be that you could design the system to work for a configurable, arbitrary-sized grid.