WEBVTT

00:06.470 --> 00:10.820
In this lecture, we're going to start building the agent class.

00:10.820 --> 00:14.820
So open up your basic agent class that you've already created.

00:14.840 --> 00:17.810
At the top, we need to add in the link library.

00:17.810 --> 00:22.940
We'll be using that a little later for sorting our goals based on their priority.

00:22.940 --> 00:26.240
So it'll be system dot link.

00:27.890 --> 00:28.520
Okay.

00:28.520 --> 00:34.820
We also need to add a little helper class at the top, which will define our goals.

00:34.850 --> 00:42.260
Now, usually in these systems you can create just a single goal that the agent has, and the agent

00:42.260 --> 00:44.930
can go off and satisfy that goal and then come back.

00:44.930 --> 00:51.680
But in this case, we're going to create a whole bunch of goals that have sub goals and that will make

00:51.680 --> 00:57.110
the system a little bit more flexible if you want the agent doing really complex tasks.

00:57.230 --> 01:02.300
So we'll create a public class for sub goal.

01:03.630 --> 01:11.400
And it's going to be quite short, but it's going to have a dictionary, of course, so public dictionary

01:11.400 --> 01:17.400
and it'll be the same structure that we've been using all along because we need to keep it very consistent

01:17.580 --> 01:20.940
and let's call it as goals in here.

01:21.210 --> 01:27.150
And then we're going to also have a public bool remove.

01:27.540 --> 01:33.840
The reason being is that some agents you want to be able to give them a goal when they've satisfied

01:33.840 --> 01:40.370
that goal, then the goal gets removed from their list of intentions that they want to do.

01:40.380 --> 01:44.520
So, for example, in the case of the patient, the patient might need to be treated.

01:44.520 --> 01:49.590
So he's going to come in once he gets cured, he doesn't need to go through all those things again and

01:49.590 --> 01:51.540
therefore that goal can be removed.

01:51.540 --> 01:57.420
But if you want a goal that keeps getting triggered over and over again, then you can create one that

01:57.420 --> 02:00.740
you're not removing after it has been satisfied.

02:00.750 --> 02:09.090
So for example, the nurse is going to have a goal of resting so the nurse can go off and have a rest

02:09.090 --> 02:12.120
period during the work shift.

02:12.150 --> 02:14.730
Now that will keep coming up over and over again.

02:14.730 --> 02:19.260
So that's a goal we don't actually want to remove from the system after it's been satisfied.

02:19.260 --> 02:25.590
It's just going to be sort of like an idle goal until one of its conditions gets satisfied.

02:25.900 --> 02:34.470
Okay, so let's now create this so public sub goal and we would pass through a string for our key value

02:34.470 --> 02:41.040
int I for its actual value and the bool are for remove.

02:42.590 --> 02:43.370
Then in here.

02:43.370 --> 02:47.780
Let's just set s goals equals a new dictionary.

02:49.330 --> 02:52.630
For our string and our int.

02:54.220 --> 02:59.230
And schools don't add the one we're passing through.

02:59.230 --> 03:01.720
So se and I.

03:02.740 --> 03:09.790
And then we're also going to do remove is going to equal whatever are is when it's passed through.

03:10.720 --> 03:17.890
Now the agent itself is going to have a list of actions and a list of goals and those sorts of things.

03:17.890 --> 03:27.790
So let's at the top, first of all, declare a public list of G actions, and the G action will be the

03:27.790 --> 03:30.870
actions that we've given our agent to achieve.

03:30.880 --> 03:40.420
So here we have action, and that's going to equal a new list of G actions or action singular.

03:40.450 --> 03:41.680
Don't put an S in there.

03:42.070 --> 03:46.090
And then we also need a lot of goals.

03:46.090 --> 03:52.870
So it's going to be a public dictionary of dictionary.

03:52.870 --> 04:01.960
So basically it's a dictionary of sub goals which are basically another dictionary int for our value

04:01.990 --> 04:08.440
goals equals new dictionary and then we want sub goal and int.

04:12.640 --> 04:16.960
And then we need a planner, so we'll call it G planner.

04:18.340 --> 04:18.900
Plan out.

04:18.910 --> 04:24.010
We haven't actually created the planner yet, but this is going to be our class that goes off and does

04:24.010 --> 04:24.730
the planning.

04:24.760 --> 04:26.410
Given the goals.

04:26.410 --> 04:29.800
What it's going to return is a Q of the action.

04:29.800 --> 04:31.780
So we're going to use Q in here.

04:33.510 --> 04:36.180
So it'll be a queue of g actions.

04:36.480 --> 04:37.770
O g action.

04:37.860 --> 04:41.190
Let's call that our action queue.

04:43.010 --> 04:52.250
And then a public g action for the current action so we can keep track of what the agent is doing at

04:52.250 --> 04:53.750
any particular time.

04:53.750 --> 04:57.500
And then also the same thing for the goal.

04:57.500 --> 05:07.640
So sub goal and that will be the current goal and we will record that now in the start we have to create

05:07.640 --> 05:10.250
our array of actions.

05:10.700 --> 05:21.620
We're going to make this so that for our agent you can create versions of the G action class up here

05:21.620 --> 05:29.180
and just drop them on to the agent in the inspector, which means that we need to pick them up when

05:29.180 --> 05:32.360
the agent starts working and they're all going to go into an array.

05:32.360 --> 05:44.480
So g action and let's call this x equals this dot get component g action.

05:46.610 --> 05:52.640
And not only do we want one action, but we'll be able to put a lot of actions on there.

05:52.640 --> 05:54.380
So it's actually get components.

05:54.380 --> 06:00.350
So all the actions that are sitting on the agent will get picked up and put into that act.

06:00.380 --> 06:11.660
Then what we're going to do is for each G action, a in act, we're going to put that into our actions

06:11.660 --> 06:14.120
list so actions don't add.

06:15.340 --> 06:15.940
I.

06:17.170 --> 06:27.100
Kind of similar thing that we did with our actions where we were creating these public arrays that would

06:27.100 --> 06:33.010
come up in the inspector, and then we were populating our dictionaries with those down in the awake.

06:33.010 --> 06:38.920
But in the agent we're doing that inside of the start method here.

06:39.100 --> 06:39.580
All right.

06:39.580 --> 06:47.320
So now that we've got our start, we've picked up our actions, we still actually do need to declare

06:47.320 --> 06:48.350
our G planner.

06:48.370 --> 06:53.620
Now, I notice that our actions here, I probably should just put a little s on the end up there to

06:53.620 --> 06:58.630
make sure that we've got our list named the same thing down into our start.

06:58.750 --> 06:59.280
Okay.

06:59.290 --> 07:05.290
And then what we're going to do to run the action so the agent will run through the plan that it's given

07:05.290 --> 07:08.280
up here, and that will happen down here in a late update.

07:08.290 --> 07:11.680
So let's make our update a light update.

07:12.130 --> 07:17.770
And for now, we're going to leave it empty because we need to work on this planner.

07:18.310 --> 07:28.330
So the planner is going to get the goals that are needing to be satisfied, a list of the actions that

07:28.330 --> 07:33.910
we have available to us as well as the world states.

07:33.910 --> 07:38.320
And from there it's going to build a tree of all of the actions.

07:38.320 --> 07:45.310
So you're getting essentially a graph and that graph we then search through the graph from one end to

07:45.310 --> 07:51.430
the other where we come up with a plan that's going to satisfy the given goal.

07:52.120 --> 07:59.140
The planet is quite complex code, so I'm going to leave that until the next video so that we can dedicate

07:59.140 --> 08:05.470
the whole entire thing to the structure of the planner and how it puts together the actions that will

08:05.470 --> 08:07.300
satisfy the goals.
