Not managed to get as much coding time in recently as I’d have liked as real life, work and such things have been intruding too much. But yesterday I managed to get a good, meaty coding session in over the afternoon, working on the beginnings of the AI for OMZH.
Essentially there are zombies, and there are humans, and for starters I’m trying to get it so that each zombie pursues the nearest human while each human runs away from the zombies to the best of their ability.
This is, for the rookie, a pretty major AI undertaking (as compared to moving the AI bat in Pongoloid), 150-odd lines of code in all. And inevitably, it’s not quite working properly yet.
The zombies are doing roughly what they ought to - checking the co-ordinates of every human against their own, figuring out which is the nearest human and then heading towards them. If they touch, the human becomes a zombie (infection periods can wait until later).
The humans, though, are just standing stock still and waiting to be bitten. Once they become zombies they start to move, but until then they don’t want to know.
And just to top it all off, once everyone’s a zombie they head inexorably for the top left of the screen, which they shouldn’t be doing either.
I suspect the problem with the human AI is a new boolean variable, “panicked”, which I’ve added to the “person” class. Basically humans are meant to become “panicked” if they are less than a certain distance away from a zombie.
If panicked, they then tot up whether there are more zombies above or below them onscreen, and whether there are more zombies to their right or left onscreen, and decide which way to run accordingly.
If “panicked” is false, though, it triggers placeholder code that just makes the human stand still.
So chances are that people just aren’t passing the panic test.