This adds state_as_number(), a helper method that tries to interpret state as a number, for cases we can predict. It's a generalization of what is copy-and-paste-ed into multiple other places.