Attention: We are retiring the ASP.NET Community Blogs. Learn more >

Terrarium : Some data about saving energy

As I mentioned in my last post, it's important to conserve energy in the Terrarium game. So, if you are moving - maybe looking for your next meal - and are not under any threat of attack, it is wise to meander along rather than sprint. Likewise, it is much better writing code which allows you to avoid being attacked as opposed to running away from a fight.

In my code I manage my moving and speed through some helper routines, the most useful of these allows me to move away from another organism (either animal or plant species).

Private Sub MoveAwayFrom(ByVal org As OrganismState)
    Dim comingFrom As Direction = DirectionRelativeToMe(org)
    If comingFrom = Direction.DownLeft Then
        BeginMoving(New MovementVector(New Point(Position.X + 10, Position.Y + 10), mCurrentMovingSpeed))
    ElseIf comingFrom = Direction.UpRight Then
        BeginMoving(New MovementVector(New Point(Position.X - 10, Position.Y - 10), mCurrentMovingSpeed))
    ElseIf comingFrom = Direction.UpLeft Then
        BeginMoving(New MovementVector(New Point(Position.X + 10, Position.Y - 10), mCurrentMovingSpeed))
    Else
        BeginMoving(New MovementVector(New Point(Position.X - 10, Position.Y + 10), mCurrentMovingSpeed))
    End If
End Sub

 

As you can see, the speed with which I move is determined before calling this routine and can be based upon an "Urgency" calculation to determine whether I should be moving at my slowest speed, my fastest speed, or somewhere in between. Here is a snippet of code which sits in my Attacked event handler and adjusts the speed to my fastest speed if I really need it:

mCurrentMovingSpeed = Me.c_MaxSpeed
MoveAwayFrom(attacker)

 

All-in-all, controlling your energy is very important. I ran two tests on a new build of Herbert and used a global variable to track how far he moved from birth to death and how old he was when he died. In the first test, he is born and moves at full speed from that moment on, in the second test he moved at a speed of 4; here's a brief rundown of the results:


In both cases Herbert joined the Terrarium with approx 40% energy

/

When speed was set to 4, Herbert was able to complete approximately 293 turns with each turn taking up just over .3% of energy. In contrast, when the speed was set at 32, Herbert was only able to complete between 3 and 6 turns.

When speed was set to 4, Herbert was able to travel a distance of 982 compared to only 140 when speed was set at 32.

No Comments