We're going to integrate the baker model into an actual game AI which can perform the task.
Let's create a class named BakerAI
, derived from GameAI
(for Unity) and Baker.AI
(client interface defined in Baker.cs)
public class BakerAI : GameAI<Baker>, Baker.AI{ }
We implement Goal<T> Goal()
and T Model()
; since we do not have a heuristic for the goal, only the goal condition is provided.
override public Goal<Baker>[] Goals()
=> new Goal<Baker>[]{( x => x.state == Baker.Cooking.Cooked, null )};
Now let's provide the model:
override public Baker Model()
=> new Baker(this){ temperature = temperature, bake = bake };
Reconstructing the model before planning is advisable; in a dynamic game environment, the effects of an action are not guarranted.
In this example, the temperature (which really should be a property of an oven object) and bake amount (which would be a property of the pie) are stored by the game AI.
Last, we implement Baker.AI
.
public void SetTemperature(int degrees) => temperature = degrees;
public void Bake() => bake += temperature/2;
All in! BakerAI
may then be added to a Unity game object. Upon starting, the planner will automatically drive behavior.