Game Development Reference
In-Depth Information
set points are matched to getting up in the morning, being away all day, being
home in the evening, and being asleep at night. The amount of state data has gone
from five items to nine. There are four set points, each with a time and tem-
perature. There is also the mode switch, which decides between heating and
cooling. This sums to nine pieces of state data. So two actions, nine pieces of
state data, and two pieces of world data multiply to 36. Care must be taken in
the coding and design to minimize the number of interactions between all of the
A More Sophisticated Implementation
We could implement a fully generalized user interface for this thermostat, but
that would go beyond what is needed to illustrate the point. Our implementation
will have the expected four set points, but we will not create a user interface for
setting them. At this point, it is worth asking, ''Where does the state data live? Is it
part of the world or is it part of the AI?'' The ambient temperature and the time
are clearly world data. Our set points could be in either place. If the thermostat
needed to remember what it was doing the last time it ran, that data would be
part of the AI. It would be part of the AI's knowledge representation of how the
world used to be—a piece of data it is remembering to help it think about how it
wants to act now.
1. Go to the code for House.vb and delete the three lines that make up the
SetPointUpDown ValueChanged event handler. We will keep the four set
points in the world data.
2. Add the following three lines to House.vb:
'Here are the thermostat programmed values.
Public ReadOnly SetTemps() As Integer = {70, 64, 68, 60}
Public ReadOnly SetTimes() As Integer = {6, 9, 17, 21}
The () by the names denote that the variables are arrays. The arrays are
public so that they can be accessed by the AI code in a different file. They
are read-only because we do not expect to change them, and any attempt to
do so is a bug we want to catch. The arrays are initialized with the values
shown in {} . The temperature values are in Fahrenheit degrees. The times
are in hours, using a 24-hour clock familiar to people who have experience
with the military or a European train schedule. Our thermostat will not
bother with minutes, only the hour. The sequence of values corresponds to
morning, day, evening, and night.
Search Nedrilad ::

Custom Search