HackyAI refactoring

This starts cleaning up HackyAI with the goal of removing some of the code warts and making it more maintainable.
This avoids introducing any (intentional) behavioral changes - these will be done in later PRs.