New Burrow Tweaks

I managed to locate and resolve a problem I was having with
new burrow creation. Originally when the burrow was full, it would create a new
burrow (default population = 3) but not remove 3 from the original burrow. This
was a calculation glitch that took me considerably longer to locate than fix
(much like proof reading your own writing means you often skim over mistakes).
Now when a burrow hits population 8 (max), a new burrow is created with
population 3and the existing burrow drops to population 5.

Herbivore AI Flee Tweaks

Setting up this AI to respond reasonably is tricky indeed!
In its original setup, the herbivores would have a chance-roll to flee from any
carnivores in range (when in “smell [for food]” mode). The problem is that this
check happens so frequently that they would inevitably flee. Also, in the basic
level with one food source, herbivores would never be able to reach the food
source if a Carnivore was in the way.

In order to make things more consistent, I tried some
tweaking experiments:

·Herbivore flee checks can only happen if the
Carnivore is in stalk/chase mode. If the Carnivore is feeding, mating, or
relaxing, the Herbivore will ignore it

oNOTE: This potentially complicates the AI
because it is checking for the ‘nearest’ threat, but there might be a second
Carnivore also close by that IS a threat

·Herbivores now also flee in ‘burrow’ mode (as
well as ‘smell’ mode)

Increasing Dynamic Nature of the Ecosystem

I’ve also decided to implement a couple of relatively easy
elements to provide for a more dynamic environment:

·Plants now have a finite “health” – when
Herbivores eat from the plant, its health drops. The plant is slowly
regenerating all the time. If the plant is at 100%, a secondary counter counts
up (much like Herbivore burrows) and when this hits its cap, a new plant is
generated somewhere on the map.

oI was thinking how it would be neat for events
to occur that trigger all the plants to pollenate (say, a big rainstorm or
“spring season”), but that’s not essential at this point.

Where to go from here?

Well, the Independent Study is at an end, but this game is
not even a game yet! Future steps will be to revisit the player’s involvement
in the game, and ensure that the player has noticeable “impact” on the world.
This, in part, requires the ecosystem to stay relatively stable, which is
problematic considering how dynamic the environment is.

I’ve started to realize that to make the player’s actions
have a noticeable effect, this AI system
setup might not work best. It may require a more static, simplistic programmed
AI that is clearly a “routine” (players notice a pattern). That way, removing a
component (through harvesting) would disrupt the routine.

I’ll also need to introduce the Natives at some point, which
shouldn’t be too hard to do. After all, they are iterations on
carnivore/herbivore AI anyway.

Lastly, I’ve realized that I’ve been developing in a vacuum to
some extent. I plan to get some NRM/environmental educators/experts in on this
so I can get more feedback into what makes sense to them, and what helps
illustrate best what they teach. Perhaps a more simplistic game (with more
clear impact) would work better?

"Animal Food Source Priority" AI
system research

This is a secondary issue in the scheme of things, but I
wanted to address it to better balance the ecosystem. Animals typically do not
feed off of a single type of food, though they will have a priority of
preferences. What happens when the animal’s preferred food source is not
available? They default to a secondary, ‘less desirable’ food source so they
can survive. With some animals, this simply involves choosing a different kind
of plant, or hunting a smaller animal. This can also lead to cannibalism, where
the animal hunts its own kind for food.

With regards to primary/secondary food sources, I have
conceptualized the following:

·Herbivores

oprimary: plants

osecondary: ?unsure (it isn’t necessary for this
to occur, but if I do implement this I may consider introducing a water-based
food source)

·Carnivores

oprimary: Herbivores

osecondary: Natives*

·Natives

oprimary: Carnivores

osecondary: Natives (natives raid other native
villages for “food” – I will leave this vague as to whether the food is the
native’s food supplies, or the natives themselves)

Conceptual Implementation

Currently, when an animal chooses its food source, a search
is done for the closest valuable instance of the food source on screen. That is
why all the herbivores seem to head for the same resource all the time
(something I may have to tweak later). To incorporate a secondary food source,
all I need to do is perform a “ranged” check for the primary food source. If
the distance is too great, search for the secondary food source.

Once that is established, I would have to modify the “kill”
collision system so the animal would actually kill the secondary food source.
If a Carnivore attacked a Native, for example, a random roll would determine
who would survive (unlike an Herbivore, which is a guaranteed kill). The
hunting/feeding systems should be able to stay the same.

What happens if the creature is hunting its secondary food
source and its primary food source comes in range? I would have to accommodate
a check so it can switch back to its primary food source, as I think that would
make sense (presuming it doesn’t “look” funny onscreen).

What to do Next?

I’m not able to make this implementation in Week 9, as the
design relies on Natives, which are not yet implemented in any form. Instead, I
think I will concentrate on tweaking the current systems and improving the
problematic “Herbivore Flee”, as well as the “Herbivore Population Expansion”
systems.

“Animal/Native Threat Response” AI system
Implementation

I’ve had a number of outside distractions this past week,
hence the delay in posting and working on the implementation (apologies!) I’ve got a basic Herbivore “flee” response when carnivores
get too close.

Figure 1 - RED HIGHLIGHT - Herbivore in move stage when Carnivore is out of range

Figure 2 - RED HIGHLIGHT - when Carnivore in range, Herbivore flees

However, there are some issues with it – some problems I
anticipated, and a couple I didn’t!

·There are occasions where the Carnivore is able
to stay close enough to the Herbivore to create a repetitive chase/flee action
which forces the Herbivore off of the screen!

oA band-aid fix would be to implement walls to
prevent creatures from leaving

oAnother approach to investigate would be to
tweak the ranges so the carnivores cannot continually chase (or that the
herbivores flee to a reasonable safe distance)

·Despite some variety in the random chance
generation, the Herbivore still manages to flee too easily. This happens
because the random chance generation runs so often that the chance aspect seems imperceptible.

oI could make the random chance more slim, which
would mean a lower chance the Herbivore “sees” the carnivore in range

·Glitches where the Herbivore gets “trapped”
fleeing between two Carnivores. The AI goes wonky , running back and forth.

oPossibly check last “flee” direction. If it was
the opposite, then force a third direction?

·Herbivores spawn on a Carnivore (that’s not
hunting) and try to flee but seem to be “stuck”

oMore investigation, I suppose!

·Herbivores flee during the search for food, but
not while feeding or returning to the burrow

oWondering if I should leave them vulnerable
during feeding?

oHaving them flee returning to burrow can work,
but the concern is if a carnivore is by the burrow, they’ll never return!

Needless to say, there’s a lot that needs to get fixed in
this system. It also raises the question of:

a)Is there a simpler way to approach this design?

b)How necessary IS the fleeing AI? I think it’s
pretty necessary, but these ARE alien creatures and perhaps I can come up with
an alternative (say, a porcupine defending itself with spikes, or a turtle
hiding in its shell – making it unappetizing for the Carnivore). That’s
definitely an easier design!

I didn’t bother working on the Carnivore fight/flight,
mainly because the Herbivore’s AI is much more core to the experience.

"Animal/Native Threat Response" AI
system research

It’s essential that the animal AIs have a “fight or flight”
instinct built-in. After all, it’s a natural response for self-preservation!
But how do we include this in the simulation in a simple and effective way?

Herbivores

Deer fleeing from motorbike in Far Cry 3

Currently, the herbivores go along their food-locating path.
If a carnivore stalks and chases them, they don’t react. Going back to the
rabbit template, they will usually check periodically to see if they’re being
stalked, and then bolt if they are.

Essentially, we need to incorporate a periodic “predator
proximity” check. If a predator is within a certain range, change to a new
state “flight”, and run away from the predator. The herbivore’s flight speed
will probably have to be faster than the carnivore, so it can get away (but
getting this right will require testing). The carnivore AI should already stop
chasing/stalking if the animal is out of range, so that’s handy.

However, we can’t have them always running away, or
carnivores may never catch them (and die from hunger). So we’ll have to build
in a random roll. Perhaps, on each check for predators, the herbivore will have
a 50% chance (or maybe less) of flight mode. That way, it’s possible for the
carnivore to reach the herbivore before it runs away.

An additional tweak could be to allow for an initial “leap”
for carnivores when they chase, where they cover a lot of ground quickly. This
would allow for any herbivore within “leap range” to be caught, but any
herbivore beyond leap range gets away. That’s a fairly definitive condition
which should work nicely.

Carnivores

Getting attacked by a Lion in Far Cry 3

Now carnivores are more complicated, because they are
predators. There are times when a tiger will stalk a man, and other times when
it will simply run away. The trick with this is how to determine what should
happen? Playing Far Cry 3 recently,
the addition of wild animals can be a real nuisance, where you’ll be fighting
(or about to) a pirate outpost and a tiger will come out and attack you J Animals in Far Cry 3 are too aggressive, IMO, but
it works for that kind of game.

One reason for the carnivores to attack the player (or
natives) would be in a hunger-related situation. If the carnivore needs to eat,
it will be more receptive to attacking any available food source. This would
probably be when the carnivore cannot locate any of its primary food sources
nearby. A “distance-to-food sources” check would be required, and this can be
addressed in the subsequent AI Implementation section (week 8)

Another reason for the carnivores to attack the player (or
natives) would be self-defense (proximity). Perhaps the player (or natives) get
too close, and the tiger gets aggressive. Perhaps the carnivore will initially
get aggressive, but if it gets injured by the player/natives, it will go into
flight mode. This requires a new variable – health – to be implemented for the
tiger.

Natives require the carnivores for a food source, so the
carnivore would need to be able to be caught, but the native implementation is
for another phase of the project. We’ll focus on the player’s interactions with
the carnivore for now.

"Animal/Native population expansion" AI system implementation

I’m in the midst of trying to implement my reproduction
cycle for the herbivores, and noticed a problem. Currently, when a herbivore
leaves the burrow, its place is held by the burrow;

oHowever, when a carnivore kills the herbivore,
this value is not removed. It’s tricky to track back and remove, unless each
herbivore somehow tracks the instance of the burrow it comes from. Presuming I
do this, then when the herbivore is killed I have a way to reset that burrow
(potentially)

oAlternatively, I could remove the placeholder in
the burrow for the herbivore. However, this can lead to the situation of
herbivores tracking back to their home burrows, only to find there’s no place
for them anymore. This will probably result in more code being needed. Bleh.

UPDATE: I managed to figure out how to track
things back using instance IDs, and was able to use my former (rather than
latter) suggestion. Whoop! **This does not seem to work in the HTML5-version, for some annoying reason!

Herbivore Reproduction

I decided to go with a “two or more in burrow, add to
counter” breeding cycle. When it adds up to enough, a new baby is born. I have
test code for randomly ‘producing a litter’, but at the moment it’s not needed.
Since the herbivores breed, and the carnivores don’t, it’s inevitably unbalanced.
The next step is to get the Carnivore Reproductive cycle active. Once that’s
going, I can come back to this.

Carnivore Reproduction

This is one of those times where I’m going to actively twist
something to fit my objectives. I want the player to need to harvest plants +
crystals, both of which are needed by other animals. The plants are for
herbivore food, but the crystals are from a cave formation, where carnivores
choose to breed. Therefore, I need to design a reason for why animals breed in
a cave (lions, by comparison, never seem to seek shelter –granted, how much of
that is there in their natural habitat!)

My process for carnivore breeding will go something like
this:

1.Carnivore feeds, this increases their desire to
mate

oFor simplicity at this point, after a feed the
carnivore will be ‘in heat’

2.Being in the ‘heat’ state means the carnivore finds
another carnivore and if both are in heat, they will mate. (Will I need to make
this M/F or not bother? Gendered species = more work!)

3.Once this mating has happened, one of the
carnivores will switch to “birthing” state, and go to the nearest crystal cave
to have their litter

4.When the carnivore collides with the cave, they
will go inside and after a counter, a litter will be born. Again, due to
simplicity, there will be one baby and they will be born as adults.

Note: Male + Female carnivores are mating!

UPDATE 1: I managed to implement the carnivore breeding (all
the way up to the searching for a cave state). I had some unexpected problems –
primarily determining how to deal with male + female. I initially just had
“carnivore” as a type, so gender was not labeled. However, I couldn’t come up
with a reasonable system to decide who would be pregnant J I could have gone the
way of making a pair of carnivores meet up and then go together to a cave. However,
I thought it would take too many carnivores out of the ecosystem feeding, plus
that’s not how typical carnivores breed anyway!

So what I decided to do was create a male and female
carnivore. This allowed me to code them 80% the same, but then have the
divergent tasks after the mating ritual (male goes to ‘relax mode’, female goes
to find a cave to have her litter).This will compound some ecosystem issues
later (such as a potential imbalance in males and females). I think I’ll try to
compensate for this by tracking # of males + females, and then when babies are
born, using them to balance things out.

So all that’s left for this is to deal with breeding is:

·the female carnivore’s birthing (and introducing
crystal caves)

·tweak birthing rates of herbivores

·introduce a “new burrow” approach to population
growth

One thing that WILL happen is that, over time, carnivores
will continue to grow while herbivores are (currently) capped at one burrow
(max 8). We don’t have any population control (age, disease) which will have to
feature in later down the line to help manage the populations so they don’t
unbalance themselves if the player takes no action J

The female carnivore (red) looking for a cave (purple) to birth in

UPDATE 2: The prototype implementation can be found here. I
did not get to the “new burrow” approach to population growth, but I did sort
out the carnivore birthing cycle. The demonstration is functional, but it has a
couple of issues:

·it is not balanced, so inevitably carnivores
will kill off all herbivores

·an HTML5-only GM glitch (doesn’t happen on the
Windows build) does not remove dead herbivores from their burrow ‘reserve spots’.

"Animal/Native population
expansion" AI system research

It wouldn’t be much of an ecosystem if the population didn’t
fluctuate! Population growth, particularly in the case of the
carnivore-herbivore relationship, means that herbivores will be depleted in no
time.

I was trying to assess when breeding should take place. In
the case of herbivores, I will take cues from rabbits and breeding will occur
when they are in the burrow. But how do I to determine the time between
breeding cycles, and what triggers breeding?

From some baseline research, a
rabbit’s pregnancy cycle is 31 days. Technically, a rabbit could produce up to
10 litters a year, of anywhere from 1-12 babies. Wow!

Considering the simplistic
stats for the herbivores (namely, hunger), there are a couple different ways we
could attempt to determine breeding:

1.Herbivores come back to the burrow with surplus
“hunger”. A certain amount could be removed from each herbivore upon entering
the burrow, and when this hits a certain target, it is eliminated and a new
herbivore is added.

2.Tie the breeding cycle to a percentage which
goes up when there are two herbivores in the burrow. When it hits 100%, a new
herbivore is added.

As I’m aiming for a simplified ecosystem structure, I’m not
going to bother with baby-vs-adult species for the time being. When a new one
is added, it will already be adult. Perhaps later I can incorporate this
(likely, post-thesis).

The other question is how to accommodate for size of
herbivore burrows. Is there a maximum size? If so, what AI is needed to “start
a new burrow”?

·Benefits for capping the size/new burrows :

oanimal populations spread out and affect a
larger area

oone “giant” burrow would tax local food
resources

·Drawbacks for capping size/new burrows:

oMore AI work involved for the herbivore J

Another alternative, which I think I might go with:

·Having the AI split the burrow automatically,
rather than programming the herbivore to do it. This would appear as though a new
hole “popped up” somewhere. This would actually be fairly realistic, as that’s
how rabbit warrens appear to grow. I like this because it would be much more
controlled (and I think, easier to implement).

Basically the AI searches loosely for food (in the general direction of actual food), pausing to "smell" (aka see if there is food close enough). When it's within range of food, it heads directly for it without delay. When it collides with the food, it eats for an arranged delay, then returns directly to the burrow.

Herbivores in feeding stages

To briefly clarify what's going on:

PINK = Herbivore, GREEN = plant, BROWN = burrow, YELLOW = player

TOP LEFT - this is the hunger level of both herbivores. When they are in the burrow, it is a decreasing number, but when they leave the burrow it is changed to -1

HERBIVORE (pink) OVERLAY - the text changes from the different states (move, smell, located, feed, burrow), and the number value is its hunger level

I managed to store the "hunger" variable in the burrow itself, which gets transferred to the herbivore when it is created, and transferred back from the herbivore when it returns to the burrow (and instance is destroyed). Thankfully Game Maker makes it easy to reference other object's local variables (so I don't have issues with global variables conflicting across instances). I also added a player (controlled by the cursor keys) who has the ability to create plants (CTRL key) and remove plants (SHIFT key). This allows you to emulate what might happen if the food the herbivore wants gets harvested before it gets there. It also allows you to re-position the food source to watch the AI in action/adapt.

NOTE: two bugs:

if you remove ALL plants from the screen, the game borderline freezes. This only happens in HTML5 mode. I suspect placing an invisible "plant" somewhere would stop this from happening. In the Windows version the herbivores just run to 0,0 on the screen.

I was fiddling with the AI's "hopping" movement to keep it looking a bit random, rather than the easiest route which is have the AI make a beeline for the food. The side effect is sometimes the AI acts, for lack of a better term, drunk :) It will go down, then up, then down, then up, rather than move horizontally to the food source (or burrow). It is something that can be fiddled with later - at the end of the day, the herbivore always gets where it needs to go, which is fine for this test.

That achieves what I set out to do for Week 2. I will address Week 4 AI planning for "Animal/Native Population Expansion" first, and if there is still time, I'll try my hand at the Carnivore AI.

"Animal/Native hunting and
gathering" AI system research

In investigating how to simulate the animal hunting and
gathering AI, I decided to go to the source: observations about real animals (Herbivores,
Carnivores). This section of the course is primarily aimed at executing the
Herbivore’s AI. If time permits, I will attempt to implement the Carnivore’s
AI.

The Herbivore = Rabbit

I decided to base my alien herbivore off of a rabbit’s
behavior, as it seemed to be what I thought of first when presented with an
herbivore. A vegetarian, the herbivore will live in a den and only come out
when food is required. It will eventually locate food (if any exists in-range),
eat, and return to the den.

As I was basing the herbivore loosely off of a rabbit, I
decided to create a table mirroring the rabbit behavior with a programmed
behavior:

-The hunger variables for each instance must be
kept externally IF the creature instance is destroyed/created. The den could
have an array that keeps these variables for “instance destroyed” animals? Alternatively,
move creature off-screen when reaches den, move creature on-screen when
“hungry”

-A further AI system (in another AI section) will
require the creature to “take flight” if a predator is near. How will these two
systems interact? What priority (food or flight) wins for animal? This isn’t
that important at the moment, but keeping it in mind in the system design stage
means less problems later.

The Carnivore = Lion

I decided to go with a lion/cat-style carnivore, as this
provides an animal without a “den” (like the herbivore has). Lions tend to have
a range they live in, and wander around in that range. This adds another
dynamic to the environment as well. I’ve made a “den” for the carnivores to
mate in, giving them some location they must periodically return to. This also
ties the mating den (a crystalline cave) into the dependency (this crystal is a
power source the player must harvest).

Lions also have different stages in their hunting. For one,
they will walk around until they locate prey nearby. Then when in range of the
prey, they will begin to stalk the prey. When they get close enough, they will
attack (chase) the prey.

Here’s the table mirroring the Lion behavior. I focused on
the idea of using “states” to track what the animal’s current goals/behavior
should be:

With this design, the biggest challenges will be managing
the animal’s states, as well as dealing with the changing range of the prey.
The mating concept, not covered in this AI section, may also be tricky because
it will need to override all other behavior.

The Natives

The natives are a combination of the two AIs. They will have
little huts they live in, and will leave to hunt when they need food. They also
require plants (the same plants as the herbivore) and must scavenge for these
as well. Considering the goals of this current AI section, this group will not
be addressed in detail in the time given. Suffice to say that if I can get the
herbivore and carnivore AI systems working, the native system shouldn’t be too
difficult to adapt to.

This past week I spent in San Francisco, at the Game Developer's Conference (GDC). As it's on the other side of the world from where I live (Qatar), it's quite the trip! Needless to say, my time this week has been limited. Discussing my Thesis project with some developers has helped me solidify it a little bit more, and has helped to ground the project.

To provide a brief summary of the objectives for my Thesis, I plan to develop a game:

where the player's actions ripple through the game environment, emphasizing their impact on the game

demonstrated by placing the player in a living ecosystem and requiring them to collect resources

providing the player with some 'difficult' choices

the player must harvest resources, but limit their impact on the ecosystem

teaching the concept of environmental sustainability through game mechanics

rather than overtly "lecture" the player on proper practice, the player will have to learn sustainability practice through their success in the game

With these in mind, the following key AI systems are required:

Hunting and gathering

Focusing on the herbivore's eating patterns, an AI system needs to be developed that will look at how best to simulate an animal's search for food. When a herbivore gets hungry, it will leave its burrow and explore somewhat aimlessly until it discovers a food source within range. Then it will head straight for the food, eat, and return to the burrow.

This system can be modified for use with the other elements of the system - carnivores and natives.

Population and Expansion

An AI system needs to be created to manage the population growth of the different groups. How do they reproduce and how quickly? Is there a max population size for the 'burrow', at which point they need to form another one? A simple, yet convincing system is required.

A concern raised is how to cap populations so that they don't get out of control too quickly. One idea is to have the threat of disease that can kill an animal, perhaps based on how many of that animal type there is. This will require exploration as well.

Threat Response

With focus on Herbivores (but important to all groups), a "flight" AI needs to be introduced so that the animal can react to threats somewhat realistically.

Expanding on this, the "fight or flight" AI would apply to carnivores and natives.

Food Source Priority/Alternatives

Animals rarely only eat one type of food. While the herbivores will focus on plants solely, carnivores/natives have more of a variety. An AI system has to be developed to deal with what available food sources exist (in range), and what food sources are primary/secondary.

A native's first priority food source is the carnivore, but the secondary food source could be attacking other natives for food. This system has to be explored in more detail.

I wish I has more of a systems thinker and steeped in math/physics! As it is, this will probably be a challenge for me, so I will be searching for how to implement these systems in a simple, elegant way - avoiding overly-complex systems. The success of the game in general relies on having an ecosystem that operates but can be thrown out of whack by the player, and this will require a careful balancing act to pull off!

My highest priority this week was changing the “pop-up”
message boxes to on-screen text. Pop-up message boxes don’t translate well to
web browsers, that attempt to block them J
Hence, converting it to basic text on-screen plays nicely with browsers.

This required some extra coding, as pop-up boxes not only
communicate text, but also pause the game. Without them, I had to manually code
in some “pauses” (which is fiddly). I managed a system whereby the text appears
near the town crier as if he is saying it, and then it disappears and reappears
at the top of the screen. This works well except for when a sub-mission is
introduced. It’s a big jarring, as you don’t get a “completion of the previous
objective” message (it is overridden by the new objective description). I’ll
keep working on this to see if I can fix this problem.

When town crier is
interacted with, text appears above him for a short time

The text then
disappears and is relocated to the “Mission” text in the upper-left

Objective Clarity

I’ve decided to modify the objectives text so it accurately
tells the player how many more of something they have to collect/kill/etc. I
thought this would be beneficial to avoid confusion. It caused some mild
confusion for me, however, as it wasn’t consistently updating! It took a while
to figure out.

# of Mission
Objectives Updating

Engine Bugs

This always happens in development, but the program begins
to grow in complexity it starts to have some system issues.

I’ve realized my calculations for when a sub-mission is
active or not is not fool-proof, and as such sometimes there is more than one
sub-mission! This is something that will have to remain (as it is not
game-breaking), but definitely something to redesign on a subsequent development
pass of this game.

The prototype, rough as it is, has achieved much of what I
set out to do in the outset. The following are some areas I will investigate
for implementation. As many of these are fairly involved, I can’t guarantee
they’ll be implemented:

-Bug Fixes
(sub-missions + repetition) – make it so there is only one sub-mission run,
and devise a system to track previous missions so they don’t repeat so
obviously (maybe develop a ‘tracking array’)

-Database
of mission terms – create a simple database that the computer can pull
objects, creatures, and descriptions from (this appeases the “Descriptive” approach for diversifying
missions, mentioned last week)

-Aborted
Missions – have the player begin a mission only to have it “fail” and for
them to retreat (there was no way to complete this mission). This is most
easily represented by a “rescue-attempt turned ambush”, as the rescue was a
ruse.

§How
I implement this, however, is the REAL mission!

-Negotiation
Missions – have the player go between two groups to settle a dispute.

§This
kind of mission is very hard to implement in a stripped-down form, as it is the
most narrative-heavy (with what the sides want, dialogue choices, etc)