Game Development Reference
In-Depth Information
questions the AI will ask is, ''Is the monster's health low?'' The evaluation should
be made by the monster, not the AI. If the AI looks directly at the controls, it can
only ask the question, ''What is the value of the CurrentHealth control?'' These
questions are not the same. If we use the same AI for two different monsters—
one that has a maximum health of 10 and another with a maximum health of
100—a value of 10 returned for one monster will probably have the opposite
interpretation if it is returned for the other monster. If we change the imple-
mentation of our simple monster and use a checkbox for high health/low health,
we should not have to change the AI.
Even something as simple as the checkbox for seeing players will go through an
interface. A blind monster might hear players and at times be close enough to
touch them. The real question the AI wants answered is, ''Do I detect players well
enough to attack them or flee from them?'' Our monster is visually oriented, but
our AI interface will be in terms of detection.
We will add a three-part public interface to the monster. The AI will use this
interface to ask questions and to supply thoughts. If we do a good job with the
interface, we could use it for all kinds of monsters and many kinds of AI to drive
them. To begin, right-click Monster.vb in the Solution Explorer window and
select View Code. Just below the Public Class Monster line, type the following
and press Enter:
#Region "Public Interfaces For the AI"
Visual Basic will create an End Region line for you. Regions have no effect on the
program, but they do help you group like pieces of code together. Note the minus
sign to the left; you can collapse a region to hide the code inside while you work
on other parts of your code. You can also do this to the individual Sub and
Function blocks.
Inside the region, we will add the three parts of the interface. We will start with
the easiest one first. Add the following lines of code to the region:
Public Function DetectsPlayers() As Boolean
'If we had more than one way of detecting a player,
'we would OR them all together.
Return (SeesPlayersCheckBox.Checked)
End Function
We marked the function with the Public keyword because we want outside code
to be able to ask the monster if it detects players. Because we return a value, this
 
Search Nedrilad ::




Custom Search