Game Development Reference
The other thermostats we have analyzed so far used their set points as start times,
not end times. These latest thermostats determine the stage of heating or cooling
required based on the number of degrees between the set point and the current
temperature, the amount of time the current staging level has been running, and
the current stage of operation.
Recall the discussion from Chapter 1 that AI is not physics. With our latest
thermostat, we now have two different methods of operation. Old-style ther-
mostats start heating at the set point time, and newer thermostats attempt to
finish heating at the set point time. The fact that both methods of operation are
valid can be seen as evidence that our thermostat example is more like AI than
like physics. Rocks on cliffs do not get to choose the method of their falling.
The addition of more set points does not raise the level of complexity in the
operation of the thermostat very much. The prior thermostat isolated the set
points reasonably well, so the number of them will influence the speed of the
code but not the complexity. This decoupling allows the code to scale up without
increasing in complexity.
The increase in the level of complexity in this example comes from the imple-
mentation of anticipation and the staged output. The thermostat knows that
large swings require a second stage. The first stage can almost always hold the
house at a given temperature, but changes larger than five degrees are best
satisfied with a second stage. The thermostat also calls for the next stage if the
temperature does not climb rapidly enough. To make this calculation, the
thermostat must track run time at the current stage and well as temperature gain
at that stage. The stage called for also depends on the current output, because the
unit will not revert to a lower stage if the set point has not yet been met. This
algorithm calls for new data and many interactions. The thermostat is thinking
about the process, so once again, knowledge representation creeps into the
Implementation is left to the student.
The projects in this chapter lead the programmer from simple and effective if-
then statements to a more data-driven approach. Hard-coded methods start out
simple, fast, and effective, but can wind up brittle and hard to manage. Hard-
coded AI can be both the smartest possible AI and the stupidest.