In this lecture, we're going to start building the agent class.
So open up your basic agent class that you've already created.
At the top, we need to add in the link library.
We'll be using that a little later for sorting our goals based on their priority.
So it'll be system dot link.
Okay.
We also need to add a little helper class at the top, which will define our goals.
Now, usually in these systems you can create just a single goal that the agent has, and the agent
can go off and satisfy that goal and then come back.
But in this case, we're going to create a whole bunch of goals that have sub goals and that will make
the system a little bit more flexible if you want the agent doing really complex tasks.
So we'll create a public class for sub goal.
And it's going to be quite short, but it's going to have a dictionary, of course, so public dictionary
and it'll be the same structure that we've been using all along because we need to keep it very consistent
and let's call it as goals in here.
And then we're going to also have a public bool remove.
The reason being is that some agents you want to be able to give them a goal when they've satisfied
that goal, then the goal gets removed from their list of intentions that they want to do.
So, for example, in the case of the patient, the patient might need to be treated.
So he's going to come in once he gets cured, he doesn't need to go through all those things again and
therefore that goal can be removed.
But if you want a goal that keeps getting triggered over and over again, then you can create one that
you're not removing after it has been satisfied.
So for example, the nurse is going to have a goal of resting so the nurse can go off and have a rest
period during the work shift.
Now that will keep coming up over and over again.
So that's a goal we don't actually want to remove from the system after it's been satisfied.
It's just going to be sort of like an idle goal until one of its conditions gets satisfied.
Okay, so let's now create this so public sub goal and we would pass through a string for our key value
int I for its actual value and the bool are for remove.
Then in here.
Let's just set s goals equals a new dictionary.
For our string and our int.
And schools don't add the one we're passing through.
So se and I.
And then we're also going to do remove is going to equal whatever are is when it's passed through.
Now the agent itself is going to have a list of actions and a list of goals and those sorts of things.
So let's at the top, first of all, declare a public list of G actions, and the G action will be the
actions that we've given our agent to achieve.
So here we have action, and that's going to equal a new list of G actions or action singular.
Don't put an S in there.
And then we also need a lot of goals.
So it's going to be a public dictionary of dictionary.
So basically it's a dictionary of sub goals which are basically another dictionary int for our value
goals equals new dictionary and then we want sub goal and int.
And then we need a planner, so we'll call it G planner.
Plan out.
We haven't actually created the planner yet, but this is going to be our class that goes off and does
the planning.
Given the goals.
What it's going to return is a Q of the action.
So we're going to use Q in here.
So it'll be a queue of g actions.
O g action.
Let's call that our action queue.
And then a public g action for the current action so we can keep track of what the agent is doing at
any particular time.
And then also the same thing for the goal.
So sub goal and that will be the current goal and we will record that now in the start we have to create
our array of actions.
We're going to make this so that for our agent you can create versions of the G action class up here
and just drop them on to the agent in the inspector, which means that we need to pick them up when
the agent starts working and they're all going to go into an array.
So g action and let's call this x equals this dot get component g action.
And not only do we want one action, but we'll be able to put a lot of actions on there.
So it's actually get components.
So all the actions that are sitting on the agent will get picked up and put into that act.
Then what we're going to do is for each G action, a in act, we're going to put that into our actions
list so actions don't add.
I.
Kind of similar thing that we did with our actions where we were creating these public arrays that would
come up in the inspector, and then we were populating our dictionaries with those down in the awake.
But in the agent we're doing that inside of the start method here.
All right.
So now that we've got our start, we've picked up our actions, we still actually do need to declare
our G planner.
Now, I notice that our actions here, I probably should just put a little s on the end up there to
make sure that we've got our list named the same thing down into our start.
Okay.
And then what we're going to do to run the action so the agent will run through the plan that it's given
up here, and that will happen down here in a late update.
So let's make our update a light update.
And for now, we're going to leave it empty because we need to work on this planner.
So the planner is going to get the goals that are needing to be satisfied, a list of the actions that
we have available to us as well as the world states.
And from there it's going to build a tree of all of the actions.
So you're getting essentially a graph and that graph we then search through the graph from one end to
the other where we come up with a plan that's going to satisfy the given goal.
The planet is quite complex code, so I'm going to leave that until the next video so that we can dedicate
the whole entire thing to the structure of the planner and how it puts together the actions that will
satisfy the goals.