Chipmunk 2D physics engine, plus code to put block stacks through dynamics simulation to see if they stand up.
Things look OK, but I need to do more tests.