Game Development Reference
In-Depth Information
function WorldState:GetUtility()
local lifeScore = 100 * self.survivalChance;
local attackScore = 100 - self.opponentHp;
attackScore = attackScore + (attackScore * self.killChance);
return lifeScore + attackScore;
end
The first line of this function considers the agent ' s chance for life. It multiplies 100
(the max hit points) by the survival chance of the agent. The attack score considers
the agent
s desire to kill the player. It is equal to the amount of damage done (max
hit points minus current hit points). The attack score is further modified by the kill
chance. The kill chance is the percentage chance that another attack on the following
turn will result in the player
'
s death. If there is no chance, it has no effect on the
score. If there is a 100% chance, it will double the attack score. Anything in between
is possible. Finally, the life score and attack score are added together and returned.
Each line of code in this utility function directly affects the behavior and personality
of this agent.
'
n The agent prefers states in which it is alive and has a good chance at remaining
so.
n The agent prefers states in which the player is more injured.
n The agent greatly prefers states in which the player is near death.
This is by far the simplest utility-based system I
ve ever written, but it does a great
job showing how all the pieces fit together. In order to test this out during the writing
of this chapter, I created a mini combat RPG game. It
'
'
s not part of the Teapot Wars
'
code like everything else in this chapter has been; it
s a stand-alone console program
that runs a single Lua file. I ' ve included it with the GameCode4 source code in case
you want to play around with it. You can find it at \Dev\Extra\UtilityDemo\. The
utility.lua file contains all the code. Just run the UtilityDemo.exe program to play the
game.
Agents Can Complain About Work Just Like Us
Rat Race used a system called UtilEcon, which stood for Utility Economy. The
system was designed to be a goal-oriented system where agents would
wander around the world and trade utility with each other through speech.
We had a speech system tied into this, so there were different types of
utility for different types of conversations. That way you
d tend to hear the
gossipy people in the office say the gossip lines, while the workaholics
would say the work lines. The system worked really well and added quite a
bit to the atmosphere.
'
Oh look, there
'
s Joy complaining again.
 
Search WWH ::




Custom Search