Sheeplings Website and AI Thoughts
For years I’ve only used complete content management systems, such as Drupal or WordPress. When the time came to design a Sheeplings website I decided to examine exactly what I need: a few simple pages and some php magic to track the downloads and page views and whatnot. In other words, I need specialized features, but not a big system. In these cases it’s easier to re-invent the wheel.
So, I took the plunge into HTML 4.01 and CSS 2 and all that jazz, and came up with a basic design for the site. Take a look, and if you find that it doesn’t look okay, please let me know!
I showed the Sheeplings site to a friend yesterday, and after looking at the screenshots on the page, his immediate response was along the lines of: ”I suppose this is a sheep-herding game with force-repulsion? I have an excellent algorithm for the sheep movement!”
The algorithm in question is a very simple subsumption one, consisting mostly of vector additions. It’s basically what I’m already doing, with two exceptions: the algorithm uses fixed destinations instead of – as I do it – define a vector and a duration to follow this vector. With all the acceleration and decceleration going on it’s easier to do it like this.
The other difference is of great consequence. So far I’ve been doing basic collision detection, and the sheep AI has decided whether or not to take a new action when it has collided with something. Instead, the new algorithm suggests that inverted vectors to objects surrounding it are added, in order to make the sheep avoid collisions. Elegance! Brilliance! I’m so ashamed of myself that I didn’t think of this.
A similar thing happened when I was making Mega Brain Splashing 4: I had implemented A* pathfinding for the robot movements, but noted that it took way too much time when dozens and dozens of them were present. I thought of sub-dividing the map and make layers to the pathfinding – first get to the correct area and then search for the player inside the area, and so on. I guess this would have worked, but the same friend of mine came up with an alternative solution: potential fields. Easier, faster, and performs almost as good as proper pathfinding. Dammit!
Speaking of subsumption algorithms, I looked up the subsumption architecture. It seems to be a layered AI architecture in which complex behaviour is achieved from the emergent combination of different asonchrynous layers. Each layer is pre-wired, but due to their interaction interesting behaviours can apparently be achieved. Read more about it here!
Speaking of layers, I might mention the simple Sheeplings AI. There are priority layers for actions that the different characters can perform; for example:
- High priority: running away, jumping (and being carried off, but this is a special case)
- Medium priority: walking someplace
- Low priority: eating grass, looking around, wiggling the ears
In order to quit doing an action, it must be exchanged for an action of higher priority. Otherwise, the character continues until the current action is done, and then decides what to do next.
It’s interesting to speculate how the sheep in my game would behave with a sumbsumption architecture, but I really don’t think it’s worth the effort for this game.
