WEBVTT

00:03.190 --> 00:03.640
Okay.

00:03.640 --> 00:11.230
So in this video, we've got the inventory set up and we're going to start using it to get the nurse

00:11.230 --> 00:16.540
and the patients to go to the cubicle that have just been assigned.

00:17.410 --> 00:21.540
So create yourself a new C-sharp file and open that up.

00:21.550 --> 00:23.890
Call it, get treated.

00:23.890 --> 00:31.810
And this class here is actually based on the original get patient's code before we modified it.

00:31.900 --> 00:37.080
And you'll see why I've used this in a moment, because it's actually got a few things that are similar

00:37.080 --> 00:39.010
to the target.

00:39.010 --> 00:41.380
We need to get a cubicle.

00:41.380 --> 00:45.340
We don't want to get the cubicle from remove patient or anywhere else.

00:45.340 --> 00:47.530
We're going to get it out of our inventory.

00:47.530 --> 00:58.480
So in here we're going to put inventory, dot, find object with tag and give it our cubicle.

00:59.850 --> 01:00.720
Like that.

01:00.870 --> 01:07.770
And then if we don't have it, of course we're going to return false or otherwise null.

01:07.800 --> 01:12.360
Now what are going to be the post perform in this situation?

01:12.360 --> 01:14.640
What things do we need to set up?

01:14.910 --> 01:19.230
Well, the first thing is that we could actually add a state to the world.

01:19.350 --> 01:28.260
So world thought, instance, dot, get world and dot modify state.

01:28.260 --> 01:31.410
And we're going to add a new state in there called Treated.

01:31.890 --> 01:36.420
And basically, it's just going to count the number of patients who get treated.

01:36.420 --> 01:40.320
It's not going to be used for anything, but you'll be able to see the count going up.

01:40.350 --> 01:46.710
Maybe if you were turning this into a full blown medical simulation, you would be keeping track of

01:46.710 --> 01:50.220
how many patients were actually treated in this particular state.

01:50.220 --> 01:54.090
And therefore you could trigger some of the event, you know, like you get extra budget or you get

01:54.090 --> 01:55.830
an award or whatever.

01:55.830 --> 02:01.080
So it's just another thing that you can keep track of and you can put all sorts of things into that

02:01.080 --> 02:02.640
world, state with values.

02:03.030 --> 02:12.000
Now, once we've been treated well, we have to remove the cubicle so it will go inventory, dot remove

02:12.000 --> 02:19.500
item and we will remove the target from the agents own inventory.

02:19.530 --> 02:20.190
Okay, great.

02:20.190 --> 02:21.690
So save that.

02:21.690 --> 02:33.180
Now we're going to go back into Unity and get the patient drag and drop that new get treated on to the

02:33.180 --> 02:33.750
patient.

02:33.750 --> 02:37.590
So it's one of the tasks now we will call it get treated.

02:40.400 --> 02:46.010
The target we don't need to set up and the preconditions for this.

02:46.370 --> 02:53.840
So if we don't put any preconditions on this, it's something that can be done pretty much straight

02:53.840 --> 02:58.760
away and it can't really be done until you're in the waiting area.

02:58.850 --> 03:06.110
So there need to be some kind of situation that gets triggered to say that we are actually in the waiting

03:06.110 --> 03:06.680
area.

03:07.280 --> 03:16.130
Unfortunately, we can't be looking at the world state for a precondition to being in the waiting area

03:16.130 --> 03:22.190
because every agent that comes in is going to add to the world state.

03:22.550 --> 03:29.420
So there will be some cases when your agent needs to keep a set of its own states.

03:29.420 --> 03:35.100
And that's where the beliefs that I talked about in previous lectures come into play.

03:35.120 --> 03:38.390
So let's go back into our folder.

03:38.420 --> 03:43.160
We'll go into our agent and we'll add in some beliefs.

03:43.340 --> 03:44.950
So let's have a look here.

03:44.960 --> 03:51.200
We've already added in this beliefs structure, but we haven't actually started to use it.

03:51.530 --> 03:55.580
So in order to use it, we need to put some values in there.

03:55.610 --> 04:01.550
Now the action itself is going to want access to the beliefs.

04:01.550 --> 04:04.160
So let's go back into the action.

04:04.160 --> 04:15.860
And just like we put the inventory in there, we're going to add in a public world states beliefs and

04:15.860 --> 04:27.710
then down in the awake we will put beliefs equals this dot get component for the g agent dot beliefs.

04:28.520 --> 04:28.760
All right.

04:28.760 --> 04:30.480
So you can save that script.

04:30.500 --> 04:33.360
Now, let's go into our go to waiting room.

04:33.380 --> 04:40.100
This is where we want to inject a state into the patient's own belief system.

04:40.490 --> 04:49.910
So in here, we'll put beliefs, dot, modify state, and we'll put at hospital.

04:50.690 --> 04:51.710
In their.

04:52.980 --> 05:00.270
So now we can use at hospital as a precondition for that get treatment.

05:00.420 --> 05:09.210
So back in unity on the patient, we will now put a precondition one in there and under the first element

05:09.210 --> 05:12.270
there will put at hospital.

05:13.480 --> 05:18.520
Do make sure that you are spelling these correctly so that they do match.

05:19.060 --> 05:21.440
Now, what's going to be our after effect?

05:21.460 --> 05:24.340
Well, we need to add one at least.

05:24.340 --> 05:29.170
And the after effect, remember, is going to match whatever our goal is.

05:29.170 --> 05:36.190
So for here we're going to put is treated like that.

05:36.190 --> 05:44.770
So this is pretty much a stand alone action all by itself where it's waiting for our hospital to be

05:44.770 --> 05:45.460
triggered.

05:45.460 --> 05:50.020
And then we have this is treated goal.

05:50.140 --> 05:52.030
And you know what that means?

05:52.030 --> 05:59.710
It means we actually have to go back into the patient code to make sure that is treated is in fact one

05:59.710 --> 06:00.880
of its goals.

06:00.880 --> 06:04.540
So let's go in here while we're in here.

06:04.540 --> 06:11.200
I just want to point out this start method and the way I declared it in the now I know in previous videos

06:11.200 --> 06:18.040
I have it as protected override, void, start and that's what you should have in here as well.

06:18.040 --> 06:24.710
You want to have it for all of the classes that derive from the agent class.

06:24.710 --> 06:27.580
So that's going to be the nurse and anything else that you create.

06:27.580 --> 06:27.910
Okay.

06:27.910 --> 06:30.160
So we're going to create another sub.

06:30.260 --> 06:38.920
I'm just going to copy this one and put it under here and we'll put it as two and we will add to and

06:38.920 --> 06:48.190
our treatment is going to be is treated and we will put this at a five because it's more important than

06:48.190 --> 06:53.860
the is waiting even though we can't obviously get to is treated without that happening first.

06:54.430 --> 06:54.670
Okay.

06:54.700 --> 06:58.210
So save that press play and let's have a look at this.

06:58.210 --> 07:05.890
So I've sped up my agents movement and I've also decreased the amount of duration for their actions

07:05.890 --> 07:08.590
so that there's not so much waiting around.

07:08.680 --> 07:08.950
Okay.

07:08.950 --> 07:16.990
So the nurse comes in, gives the cubicle assignment to the patient and nothing happens.

07:17.290 --> 07:18.880
So what's going wrong?

07:19.180 --> 07:28.960
Well, what is going wrong is the at hospital, which is the trigger for our get treated.

07:29.230 --> 07:34.270
So we've got this ad hospital, but where are we injecting it?

07:34.270 --> 07:37.330
Well, you might say, well, we are we are actually injecting it.

07:37.330 --> 07:41.260
We're doing it in the waiting area.

07:41.260 --> 07:42.460
So go to waiting.

07:42.460 --> 07:43.630
We have a look in here.

07:43.780 --> 07:44.620
There it is.

07:44.620 --> 07:47.530
There it's going into the belief system.

07:47.830 --> 07:51.820
But what isn't using the belief system at the moment?

07:53.310 --> 07:55.050
Well, it's the planner.

07:55.170 --> 07:57.420
The plan is not using the belief system.

07:57.420 --> 08:01.800
The planner is only considering the world states.

08:01.830 --> 08:08.160
Now, if you remember right back when we started working on the agent, if we go to the agent here and

08:08.160 --> 08:14.100
we find where the planner is actually created and fires off, which is somewhere down in where are we

08:14.100 --> 08:15.570
late update.

08:16.930 --> 08:17.350
Let's go.

08:17.350 --> 08:18.840
Down, down, down.

08:18.850 --> 08:22.100
The plana is here.

08:22.120 --> 08:24.460
So planner equals new planner.

08:24.550 --> 08:25.570
And then we go.

08:25.570 --> 08:26.050
Planner.

08:26.290 --> 08:28.390
Plan actions.

08:28.510 --> 08:30.040
Our goals.

08:30.950 --> 08:34.040
Now this is where we're sending through our beliefs.

08:34.040 --> 08:36.710
So make sure you put beliefs in here.

08:37.520 --> 08:43.340
Now, this is all well and good, but the actual planner on the other end doesn't have the capability

08:43.340 --> 08:45.440
just yet to do anything with them.

08:45.440 --> 08:47.250
So just save that.

08:47.270 --> 08:54.560
We're going to go back into the actual planner code here.

08:54.680 --> 09:02.150
And at the very top, what we need to do is create an overloaded constructor for our node that will

09:02.150 --> 09:09.140
take in the beliefs as well as the state of the world which is coming through into here.

09:09.140 --> 09:16.520
So let's just grab a copy of that, put it underneath, and then after our all states, we're going

09:16.520 --> 09:18.530
to put in another dictionary.

09:18.920 --> 09:20.420
Let me just copy that.

09:20.510 --> 09:25.550
Put it in there and let's call this belief states.

09:27.140 --> 09:29.910
So that we have the world and the belief states.

09:29.930 --> 09:33.890
Now, this is putting the world states into there.

09:33.920 --> 09:39.810
What we need to do after that is also add in the belief states.

09:39.830 --> 09:41.600
So for each.

09:42.470 --> 09:45.710
Key value pair, which will be a string.

09:46.820 --> 09:47.540
It.

09:49.150 --> 09:54.160
Be in b leaf states if.

09:55.290 --> 10:01.560
Not this dot state dot contains key.

10:03.070 --> 10:04.360
B key.

10:05.360 --> 10:07.280
Then we're going to go ahead and add it.

10:07.280 --> 10:15.590
So this dot state add B dot key and B dot value.

10:16.010 --> 10:20.870
So now you can be assured that you have both things being fed through.

10:21.170 --> 10:27.530
So that means also just another little change is that when we create our very first node that we send

10:27.530 --> 10:31.820
through the world states and the belief state.

10:31.820 --> 10:35.510
So let's go down into our planner where that very first node gets created.

10:35.510 --> 10:42.800
So here is where the first node is getting created and it's getting sent our world states that we're

10:42.800 --> 10:45.080
grabbing here from our singleton.

10:45.170 --> 10:51.890
We've just made an overloaded method that we can send through the states that come from the agent.

10:51.920 --> 10:58.490
Now, when we initially set up our queue creation or our plan creation up here, we allowed for another

10:58.490 --> 11:01.670
set of states to come through, but we were setting that to null.

11:01.670 --> 11:07.640
So these states here are actually the belief states, so let's call them belief states.

11:07.640 --> 11:12.080
And then down here we want to add them in as a parameter.

11:12.080 --> 11:15.410
So I believe states and.

11:16.290 --> 11:18.030
It's going to be dot.

11:19.010 --> 11:24.800
Get states in order to actually return them in the right format for the node.

11:25.040 --> 11:32.210
Now that takes those parameters where we create the other nodes, which is down.

11:32.990 --> 11:35.720
In build graph where it creates more nodes.

11:35.720 --> 11:47.780
You don't need to change this because the world states that are coming through into here are the concatenation

11:47.780 --> 11:49.370
of both sets of states.

11:49.370 --> 11:55.550
And so any other child leaves that get created for our graph are always going to have the concatenation

11:55.550 --> 12:01.880
of those two initial states, the world state and the set of beliefs inside of them.

12:02.180 --> 12:02.630
Right.

12:02.630 --> 12:02.920
Okay.

12:02.930 --> 12:04.370
So let's save that.

12:04.370 --> 12:12.980
And now that we're actually getting our at hospital from somewhere, let's go back into here, press

12:12.980 --> 12:18.150
play and let's take a look at what happens.

12:18.150 --> 12:20.840
So they're going to spawn as before.

12:20.870 --> 12:31.040
Then here they come up to the reception desk and then after they've registered, they'll start making

12:31.040 --> 12:32.630
their way into the writing room.

12:32.630 --> 12:35.780
And that's going to trigger the nurse who'll go across.

12:35.780 --> 12:45.890
So if he comes to their the nurse, once she and him get in the same space as a goal location, he's

12:45.890 --> 12:53.450
going to shuffle off over to the cubicle whilst avoiding the other guys that are coming in.

12:54.740 --> 12:57.890
All right, so that's working really well.

12:59.930 --> 13:07.820
So what I'm going to do now is actually leave it as a challenge for you to try and create a new action

13:07.820 --> 13:15.380
for the nurse that is going to get the nurse to go over to the same cubicle as the patient.

13:15.380 --> 13:24.410
So it's going to involve creating a new action and basically just setting up the correct preconditions

13:24.410 --> 13:27.980
and after effects and put that onto the nurse.

13:27.980 --> 13:37.310
Now, one little clue that I will give you is that we've just created our get treated for our patient.

13:37.310 --> 13:44.150
And the code that you need for your nurse is very similar for her action.

13:44.150 --> 13:46.370
So go ahead and give that a go.

13:46.370 --> 13:51.470
And when we come back in the next video, I'll show you one way to do that.
