Monday, 30 April 2012

Group VS Induhviduals

It's been slow progress on the simulation game as I've been busy releasing a free game for Android called Gravity Pong which you should all go download now, as this makes me happy (Currently at 6 downloads and $0.05 income from AdMob).

I've also been putting some time into my next mobile game, which will be a snowboarding game built on the Box2D framework (which I'm accessing through the useful Libgdx framework).


It's very much in the beginning phase but I've been enjoying working on the pixel art.

As I've been away from my computer I've been forced to think about programming, as opposed to just blindly forging ahead. This has lead me towards some changes in my approach.

Groups Versus Individuals

Currently in my simulation game every entity is treated individually. It searches the area around itself and makes decisions based on what's there (not through a very complicated decision making process though!) A wolf may have a pack which it is connected with, but it's main goals are always what it comes up with.

I was thinking this way because I want my game to have that individual feel to it, where characters pick their next move based on how they feel, rather than just being a small part of a larger machine.

However this leads to very inefficient programming as each entity covers the same ground with its searches.

Take for example the concept of a herd of deer grazing in a clearing when a wolf approaches.

Relatively simple in concept but harder in process.

If I treat every deer seperately I have to check each of them to see if they notice the wolf, or if they're too busy eating, then check to see if they notice other deer running away etc. As each deer checks these facts they cover a lot of the same area and repeat a lot of the same checks.

What I am considering changing it to is to have groups, and I update a group which then updates it's members making it simpler to share information.

I can then check for a predator overall, then figure out who notices using only one instance of all the data.

If ideally implemented the behaviour shouldn't differ from when they are behaving entirely autonomously but will be a lot faster and simpler to implement. It also lends itself quite easily to having a leader in charge, whether an alpha male or a human with leadership skills which is something I'm looking forward to implementing.

It also makes more sense having a pack know it's den rather than having each wolf have a link to the den etc
It keeps things more compartmental, and more easily changed later.

Obviously this is a somewhat forced instance but it helps explain how I'm feeling currently about implementing this.

2 comments:

  1. I definitely think groups are a good idea if for no other reason than they actually exist in the real world, or for a more programmy statement because they are a concept in the domain model. If they can simplify some of the computation that's good too. Another thing you could try in order to simplify computation is have prioritised attention algoritms. For instance, before checking to see if a deer notices a wolf check if it notices another deer in alarm and if so you don't have to check anything else.

    How are you doing events at the moment? It might help to have an event trigger things around it. For example if a deer becomes alarmed that triggers a check on all the animals in line of effect. This might decrease the total number of computations, but it could also wreak havoc on your time system.

    ReplyDelete
    Replies
    1. One problem I'm currently having with the new system is having all creatures immediately attached to the region they're in made it very easy to do modular updating of the world map, we'll see how that ends up working though.

      Currently I don't have any events at all, although initially I was pondering doing what they did in Sims, where instead of having the Dude walking around looking for things you have the things advertising.

      So a couch advertises to the nearby area "Here I am, need to rest?" Then the dude wanders through, checks out what events are nearby and then decides to rest if his need to rest is higher than whatever else he was doing.

      So maybe I'll have regionwide events, so a bush could post a notice essentially saying "I'm over at this square if you need fruit" and it would sit there.

      Then a deer could come through and need to decide what to do so if it has no overriding goals it checks the nearby list, and there may be water advertising etc but its hungry so it then decides "I want fruit" and goes looking for the bush.

      Delete