WEBVTT

00:02.630 --> 00:03.170
All right.

00:03.170 --> 00:07.370
I hope you're ready for some coding because there's quite a bit to get through.

00:07.370 --> 00:12.500
And in fact, we probably won't even get to a point in this particular lecture where we can run anything.

00:12.500 --> 00:18.560
But what we're going to do is start with the very basics and create some really basic classes that we

00:18.560 --> 00:19.970
can build onto.

00:20.000 --> 00:26.780
And that's going to be the world states, the agents and also the actions.

00:26.780 --> 00:29.630
So let's go ahead and create those files.

00:29.630 --> 00:33.890
So down in your project, let's create a C-sharp file.

00:33.890 --> 00:36.020
I'm going to call it G agent.

00:38.790 --> 00:45.720
Then we're going to create another one and we're going to call that one g action.

00:47.350 --> 00:49.450
And another one.

00:52.070 --> 00:55.400
Which we'll call G World.

00:55.940 --> 00:57.740
And one more.

00:59.950 --> 01:04.300
And we will call that world states.

01:05.600 --> 01:05.790
Okay.

01:05.960 --> 01:09.380
So let's open up world states and we'll edit that one first.

01:09.410 --> 01:17.750
At the very top, I'm going to include just above the actual class itself a another little tiny class

01:17.750 --> 01:23.630
and we're going to make it serialize able so that we can see it inside of the inspector.

01:23.630 --> 01:31.940
So if system serialize visible and then we're going to have a public class world state.

01:32.900 --> 01:46.040
And in that state what we're going to do is create a public string key and a public int value.

01:46.070 --> 01:52.850
Now we're doing it so that you can actually edit these items in the inspector, because once we start

01:52.850 --> 01:57.890
building the system, you'll want to drag and drop a lot of things around as much as possible.

01:57.920 --> 02:05.240
Now the reason that we're creating a world state with a key value and a value is that we're going to

02:05.240 --> 02:07.130
create a dictionary with these.

02:07.280 --> 02:11.240
And the key itself is actually the world state.

02:11.330 --> 02:18.650
And then I've also added in this value and the value is some kind of integer that you want associate

02:18.650 --> 02:19.340
with the key.

02:19.370 --> 02:23.210
Should you want to associate with the key down the track?

02:23.240 --> 02:28.610
For the most part, we're not actually going to use that, but we're using a dictionary.

02:28.610 --> 02:32.240
So we do need to have these two values in there.

02:32.240 --> 02:38.690
But let's say that down the track you wanted to have a world state was like free cubicles.

02:38.690 --> 02:44.930
And then you could have in here that there were five free cubicles or something and then you could test

02:44.930 --> 02:47.090
it when you extend this system.

02:47.270 --> 02:47.630
All right.

02:47.630 --> 02:53.750
So that is our little class with the world state, and we will use it inside of other classes.

02:53.840 --> 02:57.080
So let's go ahead and now do our world state here.

02:57.080 --> 02:59.600
Now, first of all, it's not going to be a mono behavior.

02:59.600 --> 03:04.190
So you can get rid of that and all of the other code that's inside of here.

03:04.190 --> 03:09.140
First of all, we're going to create something to hold all of the states of the world.

03:09.140 --> 03:12.140
So public dictionary.

03:14.190 --> 03:16.200
String int.

03:16.840 --> 03:19.420
And this will be called our states.

03:20.260 --> 03:26.800
So let's create our constructor, and that will be a public world states.

03:27.550 --> 03:31.420
And inside of here, we're just set up our dictionary.

03:31.420 --> 03:35.050
So states equals new dictionary.

03:36.860 --> 03:38.780
String int.

03:41.790 --> 03:42.150
All right.

03:42.150 --> 03:44.430
So that's all that we need in there.

03:44.770 --> 03:45.040
Okay.

03:45.060 --> 03:51.060
Now we're going to add a whole bunch of methods to help us use the dictionary.

03:51.060 --> 03:56.130
So to add things to the dictionary and to modify the dictionary and also set the states that are in

03:56.130 --> 03:57.100
the dictionary.

03:57.120 --> 04:01.290
First of all, let's ask if the dictionary has a particular state in it.

04:01.290 --> 04:07.770
So public bool has state and we will pass through the key.

04:10.890 --> 04:14.070
And then we will return states.

04:14.550 --> 04:17.220
Dot contains key.

04:18.610 --> 04:19.570
Okay.

04:26.470 --> 04:27.340
Nice and simple.

04:27.340 --> 04:32.290
There, you'll start to see why we're using dictionaries for this, because they're just so easy to

04:32.290 --> 04:37.810
manipulate and add stuff to and to look for things without having to write an awful lot of code.

04:38.050 --> 04:38.410
All right.

04:38.410 --> 04:40.990
The next one will be to add a state to our dictionary.

04:40.990 --> 04:48.460
If it's not there, so avoid add state string key int value.

04:49.570 --> 04:56.620
And then this is simply a states dot add and then a key and a value.

04:56.650 --> 04:58.330
Nice and simple.

04:59.270 --> 05:02.660
Next we're going to add in a modifier state.

05:02.660 --> 05:11.310
So public void modifier state string key int value.

05:13.130 --> 05:18.260
And in this case I'm going to put.

05:21.610 --> 05:25.960
If states dot contains key.

05:27.880 --> 05:32.030
Then obviously we've already added that state to our dictionary.

05:32.050 --> 05:40.330
Now, if it's in there, what I want to do is actually increase its value by whatever we pass through

05:40.360 --> 05:45.990
here, which means you could also take away by sending through like a minus one from here.

05:46.000 --> 05:57.400
So let me put in here if states contains key states at that particular key plus equals value.

05:59.600 --> 06:10.670
If the state at that key is less than or equal to zero, I'm actually going to get rid of it.

06:11.510 --> 06:15.800
Now, that's because of the way I'm using this particular dictionary.

06:15.800 --> 06:22.010
If you're not going to use that and you actually do want negative values in there, then that is entirely

06:22.010 --> 06:25.240
up to you how you deal with this.

06:25.250 --> 06:34.040
So what we're going to do for this as an example, is if we have a state like free cubicles and there's

06:34.040 --> 06:42.170
five free cubicles, and then you send through another free cubicle one, then it will update the number

06:42.170 --> 06:44.510
of cubicles to six that are available.

06:44.540 --> 06:51.050
If a cubicle is not free anymore, so you could send through a value of free cubicle minus one.

06:51.050 --> 06:56.270
It will actually take away the number of cubicles that are available for use.

06:56.610 --> 06:59.870
Okay, so once we've done that, we're just going to go else.

07:02.240 --> 07:04.520
States add.

07:07.110 --> 07:09.510
Key value.

07:09.510 --> 07:14.760
So if it doesn't exist and we're adding our first cubicle side cubicle one, it's going to add that

07:14.760 --> 07:17.020
in there rather than incrementing it.

07:17.040 --> 07:21.360
Now, we haven't written remove states and we'll get to that right now.

07:21.360 --> 07:31.620
So public void, remove state string key.

07:34.370 --> 07:42.710
And then in here if states dot contains key key.

07:44.620 --> 07:46.690
Then we will state stop.

07:47.410 --> 07:49.630
Remove the key.

07:50.620 --> 07:51.310
Easy.

07:53.580 --> 07:55.590
Especially if you spell it correctly.

07:55.770 --> 07:56.280
All right.

07:56.280 --> 07:59.970
So that's the modifying and the remove.

08:00.000 --> 08:04.860
Now, let's have an actual set state if we need to not modify it.

08:04.860 --> 08:08.640
As far as adding a value to it, we just want to set what its value is.

08:08.760 --> 08:12.780
Public void set state.

08:12.870 --> 08:20.610
Again, we want the string key and the int value.

08:23.240 --> 08:29.480
And in here we're going to if states dot contains key again.

08:34.040 --> 08:35.900
Then we can go states.

08:37.020 --> 08:39.990
Key equals value.

08:41.280 --> 08:45.090
Else we can add that state in so state.

08:46.330 --> 08:51.940
Stop add key with the value.

08:55.220 --> 08:55.610
All right.

08:55.610 --> 08:59.170
So that's all of the sort of management methods that we need.

08:59.180 --> 09:05.000
Finally, I'm going to create one that we can return all of the states or return the actual dictionary.

09:05.000 --> 09:09.500
So public dictionary string.

09:11.470 --> 09:12.340
Ain't.

09:13.720 --> 09:14.950
Get states.

09:18.340 --> 09:20.200
Return states.

09:20.200 --> 09:24.850
So this will actually be used by the planner when it needs to get hold of all the states of the world

09:24.850 --> 09:27.790
and all of the states of the belief.

09:27.940 --> 09:28.510
All right.

09:28.510 --> 09:32.760
So I've just noticed I've got one little problem up here with that space in there.

09:32.770 --> 09:34.000
So let me get rid of that.

09:34.060 --> 09:42.910
And the rest of the code is good to go so we can save that now that we've written our world states class.

09:43.930 --> 09:44.350
All right.

09:44.350 --> 09:50.470
So just quickly back into unity so I can open up our G world class.

09:50.470 --> 09:55.150
And that is also not going to be a mono behavior.

09:55.150 --> 10:00.340
But what we're going to do with it is create a sealed class.

10:00.340 --> 10:07.450
And this will help us a little later when we start using cues in that to queue things up so that we

10:07.450 --> 10:16.180
don't get any sort of conflicts in trying to access particular parts of this class, which really should

10:16.180 --> 10:19.120
only be accessed one thing at a time.

10:19.360 --> 10:19.540
Okay.

10:19.570 --> 10:33.370
So first of all, we're going to create a private static read only g world instance, which equals a

10:33.370 --> 10:34.990
new G world.

10:36.520 --> 10:42.220
Now, I didn't mention this, but we're also going to make this into a singleton so that we can access

10:42.220 --> 10:43.510
it pretty much everywhere.

10:43.510 --> 10:50.410
And we only ever want one version of the game world environment states because there's only one game

10:50.410 --> 10:50.830
world.

10:50.830 --> 10:54.280
So we don't want to have copies of it with different values in it.

10:55.030 --> 11:02.170
So private static world, states, world.

11:02.170 --> 11:05.560
That's our dictionary holding all of their states.

11:05.800 --> 11:10.960
Okay, so let's get rid of those starts and updates because we don't actually need them.

11:10.960 --> 11:13.330
Then we will have our constructor.

11:13.330 --> 11:25.240
So Static G world and in here we're going to create World Equals New World States, which is just a

11:25.240 --> 11:26.260
new dictionary.

11:29.570 --> 11:32.270
And that's all we need in there.

11:33.350 --> 11:41.930
Okay, then let's create a private G world and set everything up so that we can actually grab this with

11:41.930 --> 11:44.810
a singleton public.

11:47.200 --> 11:48.250
Static.

11:49.270 --> 11:52.930
G world instance.

11:55.180 --> 12:00.520
And this will be a gift return instance.

12:07.590 --> 12:08.050
Okay.

12:08.070 --> 12:17.220
And then one last thing we'll put in here is a public world status for get world so that we can actually

12:17.220 --> 12:22.020
return the status of the world.

12:23.040 --> 12:25.620
Return world.

12:28.810 --> 12:29.350
Okay.

12:29.350 --> 12:32.130
So that's all we need currently in world.

12:32.200 --> 12:39.610
We'll come back and create a few more methods and other dictionaries in here as we need them as we start

12:39.610 --> 12:41.500
building the simulation.

12:42.160 --> 12:47.110
Okay, so that's our basic world and our world states.
