1
00:00:06,530 --> 00:00:09,773
Hi, welcome to this second
video of how do we write a wave

2
00:00:09,773 --> 00:00:11,766
function collapse algorithm?

3
00:00:11,766 --> 00:00:15,374
And we're going to start with
setting up our environment.

4
00:00:15,374 --> 00:00:18,094
We will actually write two classes.

5
00:00:18,094 --> 00:00:22,552
One class would be for the environment,

6
00:00:22,552 --> 00:00:26,354
which it's going to be our grid, and

7
00:00:26,354 --> 00:00:31,217
that's going to be
basically a list of tiles.

8
00:00:31,217 --> 00:00:32,828
And not to be confused with the tileset.

9
00:00:32,828 --> 00:00:38,784
The second class we're going to actually
create will be the tiles, right?

10
00:00:38,784 --> 00:00:44,730
We need to make sure that each cell in the
grid has four instances of the different

11
00:00:44,730 --> 00:00:49,968
tiles, basically all the different
tiles that it could actually be,

12
00:00:49,968 --> 00:00:53,991
right, so
representations of the tileset, right?

13
00:00:53,991 --> 00:00:59,432
So let's get started by writing
these classes in processing,

14
00:00:59,432 --> 00:01:04,270
we have here the boilerplate
code that we usually use.

15
00:01:04,270 --> 00:01:06,382
These are setup and draw.

16
00:01:06,382 --> 00:01:09,474
Let's just create a new tab,
we're going to call this environment.

17
00:01:13,106 --> 00:01:20,250
And we're going to also create
a second tab called tiles.

18
00:01:20,250 --> 00:01:23,408
We're going to use this one for
the grid, and

19
00:01:23,408 --> 00:01:26,666
we're going to use this one for
the tileset.

20
00:01:26,666 --> 00:01:31,533
Let's actually start with the tiles
because they're a little bit easier,

21
00:01:31,533 --> 00:01:35,394
for good measure I like
always imported in random.

22
00:01:35,394 --> 00:01:38,314
I'm not sure if we're going to
be using that, but still.

23
00:01:38,314 --> 00:01:44,179
So we're going to use the class Tile,

24
00:01:44,179 --> 00:01:48,676
and define the constructor

25
00:01:48,676 --> 00:01:54,357
without any data for now, right?

26
00:01:54,357 --> 00:01:59,330
So self.name = None.

27
00:01:59,330 --> 00:02:02,816
Just to have something, we're going to
be adding a lot of information to

28
00:02:02,816 --> 00:02:04,479
the style as we go along, right?

29
00:02:04,479 --> 00:02:06,979
But I do want to have something.

30
00:02:06,979 --> 00:02:10,889
Let's define a display function so

31
00:02:10,889 --> 00:02:16,111
that we can actually see
the tile in the screen.

32
00:02:20,886 --> 00:02:23,098
In order to kind of look
at this tile in the screen,

33
00:02:23,098 --> 00:02:26,582
we're going to need a location, an x and
a y, which is going to be the location.

34
00:02:26,582 --> 00:02:28,998
And we're going to need
the cell_size of the tile.

35
00:02:28,998 --> 00:02:35,071
And we're going to use
a variable called entropy.

36
00:02:35,071 --> 00:02:39,342
So the entropy is how many possibilities
this tile can actually be in.

37
00:02:39,342 --> 00:02:46,127
We're going to be calling that entropy
because if it has very many possibilities,

38
00:02:46,127 --> 00:02:52,314
or reducing its entropy would mean
reducing its possibilities, right,

39
00:02:52,314 --> 00:02:58,823
it's going to have a more clear kind of
definition of what that tile is, right?

40
00:02:58,823 --> 00:03:03,528
So let's start by giving it
a stroke of white and 80.

41
00:03:03,528 --> 00:03:07,901
This is just some values that
I tested before in terms of

42
00:03:07,901 --> 00:03:10,906
visualizing the styles correctly.

43
00:03:10,906 --> 00:03:12,082
So let's do a pushMatrix.

44
00:03:19,794 --> 00:03:21,674
There we go.

45
00:03:21,674 --> 00:03:25,840
And a popMatrix, right?

46
00:03:27,763 --> 00:03:30,683
And between here,

47
00:03:30,683 --> 00:03:36,344
let's translate this tile to x, y.

48
00:03:37,404 --> 00:03:40,564
Let's define the rectMode.

49
00:03:40,564 --> 00:03:45,785
It's going to be CORNER, and

50
00:03:45,785 --> 00:03:51,687
the rectangle will be 0,0,

51
00:03:51,687 --> 00:03:57,135
cell_size, cell_size.

52
00:03:57,135 --> 00:04:00,598
So this is kind of as simple
as a class we could get.

53
00:04:00,598 --> 00:04:06,502
It's actually just a tile that
basically has a position.

54
00:04:06,502 --> 00:04:08,284
It's basically a rectangle,

55
00:04:08,284 --> 00:04:12,129
but we're going to be using it with
a lot more information than this.

56
00:04:12,129 --> 00:04:15,438
So let's just roll with it.

57
00:04:15,438 --> 00:04:17,894
At the moment we have a very simple tile.

58
00:04:17,894 --> 00:04:23,521
What we want this tile eventually to have
is possible different states, right?

59
00:04:23,521 --> 00:04:27,137
The tileset would represent different
compatibilities that it will have with

60
00:04:27,137 --> 00:04:28,430
adjacent tiles around it.

61
00:04:28,430 --> 00:04:31,192
So that information is not
quite relevant just yet,

62
00:04:31,192 --> 00:04:33,494
we're setting up the environment.

63
00:04:33,494 --> 00:04:35,610
So start with that, right?

64
00:04:35,610 --> 00:04:39,398
Now let's just write a grid class.

65
00:04:39,398 --> 00:04:41,910
And I think we've done this several times.

66
00:04:41,910 --> 00:04:46,882
So if you want to skip a little bit ahead,
I don't think

67
00:04:46,882 --> 00:04:51,754
there's going to be any very
important lessons here.

68
00:04:53,694 --> 00:05:01,338
We're going to import the tiles
from the tiles file the class Tile.

69
00:05:01,338 --> 00:05:03,439
I think that that's how we call it, right?

70
00:05:03,439 --> 00:05:06,658
So Tile, yeah, perfect.

71
00:05:06,658 --> 00:05:14,079
So the class Environment,
we are going to define it as,

72
00:05:15,934 --> 00:05:24,502
It's going to have a certain
number of columns and

73
00:05:24,502 --> 00:05:29,008
certain number of rows.

74
00:05:29,008 --> 00:05:34,128
We also want to know how
large the world is in x and

75
00:05:34,128 --> 00:05:39,608
in y, so that we can adapt
to the size of the world.

76
00:05:39,608 --> 00:05:41,816
In this case, the size of the world
will be the size of the window.

77
00:05:47,263 --> 00:05:51,924
But yeah, if you wanted to have a more
specific kind of this algorithm working in

78
00:05:51,924 --> 00:05:56,044
a different size, that's something
that you could specify as well.

79
00:05:58,784 --> 00:06:03,991
Let's just go ahead and,

80
00:06:07,376 --> 00:06:10,475
Making sure that.

81
00:06:18,264 --> 00:06:19,294
Let's do that for y.

82
00:06:24,484 --> 00:06:28,048
Right?
And here we're going to add a new variable

83
00:06:28,048 --> 00:06:34,444
that is going to be self.cells, and
it's going to be an empty list, right?

84
00:06:34,444 --> 00:06:39,124
So we're going to have all the cells of

85
00:06:39,124 --> 00:06:43,813
this grid as an empty list, right?

86
00:06:43,813 --> 00:06:51,944
I also want to have a variable
that defines the tileset, right?

87
00:06:51,944 --> 00:06:55,992
So we do have a tile.

88
00:06:55,992 --> 00:06:57,808
But we're going to define the tileset.

89
00:06:57,808 --> 00:07:04,004
So self.tiles equals, and
here it's going to be a list.

90
00:07:04,004 --> 00:07:09,724
And I'm going to close
this list somewhere here.

91
00:07:11,024 --> 00:07:15,040
And here's where I'm
going to initiate my tile.

92
00:07:15,040 --> 00:07:16,272
So like that, right?

93
00:07:16,272 --> 00:07:21,705
So this is going to be
our first possibility.

94
00:07:21,705 --> 00:07:25,264
This is going to be our
second possibility, right?

95
00:07:25,264 --> 00:07:27,547
And right now all of them are the same,
right?

96
00:07:27,547 --> 00:07:31,208
But bear with me later we're going to
start adding arguments to this tile so

97
00:07:31,208 --> 00:07:33,912
that each one of them has
different connectivity.

98
00:07:33,912 --> 00:07:37,328
But let's imagine that we want to
have a tileset of four tiles, right?

99
00:07:37,328 --> 00:07:41,938
So this variable tiles, or
you could call it possible tiles,

100
00:07:41,938 --> 00:07:47,539
will represent what are the possible
tiles that each cell can actually be?

101
00:07:47,539 --> 00:07:50,852
So we're going to do four options, right?

102
00:07:50,852 --> 00:07:55,127
So this list contains four copies of this,
or

103
00:07:55,127 --> 00:07:59,264
instances of this class tile, right?

104
00:07:59,264 --> 00:08:01,697
So that's going to be our
A bit little space for this.

105
00:08:01,697 --> 00:08:03,389
Let's just create a bit of space here.

106
00:08:05,449 --> 00:08:07,945
So that's great, we have that going on.

107
00:08:07,945 --> 00:08:10,713
That's the main data that we will need for
the environment.

108
00:08:10,713 --> 00:08:14,910
Let's just, now what we want to
do here is create a function that

109
00:08:14,910 --> 00:08:19,031
will initiate the cells so
that we can initiate all the cells and

110
00:08:19,031 --> 00:08:23,809
it would actually create instances for
each one of those.

111
00:08:23,809 --> 00:08:26,582
So let's call that function def

112
00:08:26,582 --> 00:08:34,131
init_cells, Right?

113
00:08:34,131 --> 00:08:38,976
And init each cells, as we've seen before,

114
00:08:38,976 --> 00:08:45,999
it's going to be a nested for
loop, for i in range(self.cols).

115
00:08:48,859 --> 00:08:52,890
We're going to create a row,

116
00:08:52,890 --> 00:08:57,795
it's going to be an empty list, and

117
00:08:57,795 --> 00:09:02,539
for j in range(self.rows).

118
00:09:05,679 --> 00:09:12,619
So now we will append, so
let's pick the row and append to that row.

119
00:09:14,799 --> 00:09:16,367
What do we want to append to that row?

120
00:09:16,367 --> 00:09:23,679
We want to append a copy of our tiles,
right, so self.tiles.

121
00:09:24,939 --> 00:09:28,119
And here's a trick, not a trick, but

122
00:09:28,119 --> 00:09:32,594
in a way a technique that if
we would just assign that,

123
00:09:32,594 --> 00:09:38,987
basically we would be referencing,
right, this variable here, right?

124
00:09:38,987 --> 00:09:42,770
But what we want is to,
because we want to do this in a loop and

125
00:09:42,770 --> 00:09:47,789
we want to do it like create a copy of
that variable to each one of our cells.

126
00:09:47,789 --> 00:09:50,589
We're going to use this slice notation.

127
00:09:50,589 --> 00:09:55,935
So this is a notation that allows
us to slice a list and say, well,

128
00:09:55,935 --> 00:10:01,029
I want the elements from,
maybe in element 0 to element 3.

129
00:10:01,029 --> 00:10:05,885
Or we could actually select
elements within the list.

130
00:10:05,885 --> 00:10:10,472
But if we just use this column symbol,
it would actually give us the whole list,

131
00:10:10,472 --> 00:10:12,679
basically all four elements.

132
00:10:12,679 --> 00:10:20,079
But it will give us a copy of this list
as opposed to a reference to it, right?

133
00:10:20,079 --> 00:10:22,792
Because we don't want all
cells to have a reference,

134
00:10:22,792 --> 00:10:25,699
we want to have individual
copies of the tile set, right?

135
00:10:27,319 --> 00:10:32,607
That's perfect, and now we can actually

136
00:10:32,607 --> 00:10:38,359
do a self.cells.append(row), right?

137
00:10:40,219 --> 00:10:44,963
So in this way we are actually
initiating all the cells.

138
00:10:44,963 --> 00:10:47,939
Each one of the cells
will have four copies.

139
00:10:47,939 --> 00:10:52,790
Now this function,
we could actually call it,

140
00:10:52,790 --> 00:10:59,599
in the beginning here,
we could say self.init_cells, right?

141
00:11:01,139 --> 00:11:02,559
So that's great.

142
00:11:02,559 --> 00:11:07,671
We at this point we should
have the cells initiated.

143
00:11:07,671 --> 00:11:09,739
We wouldn't be able to
see anything just yet.

144
00:11:10,839 --> 00:11:14,023
For that, we're going to do
a function as we always do.

145
00:11:14,023 --> 00:11:16,679
We do a function run.

146
00:11:16,679 --> 00:11:21,129
It's going to be like what we want
to be running every frame, right?

147
00:11:21,129 --> 00:11:23,031
So let's do a function run.

148
00:11:23,031 --> 00:11:27,990
And that function run will only have
an instance of one function for now,

149
00:11:27,990 --> 00:11:30,915
which is going to be displaying the grid.

150
00:11:30,915 --> 00:11:37,179
So let's create that function
called self.display_grid,

151
00:11:37,179 --> 00:11:40,179
which we haven't built yet.

152
00:11:40,179 --> 00:11:45,679
So let's just make that function,
so def display_grid().

153
00:11:52,619 --> 00:11:54,515
And what is a display_grid?

154
00:11:54,515 --> 00:12:01,903
Similarly to the construction of the grid,
we have to do a nested loop, right?

155
00:12:01,903 --> 00:12:06,767
So we know that we want to do for loop.

156
00:12:06,767 --> 00:12:08,791
We can copy that from here.

157
00:12:08,791 --> 00:12:13,552
We're going to do a loop, for

158
00:12:13,552 --> 00:12:18,107
x in range of columns, and

159
00:12:18,107 --> 00:12:22,049
for y in rows, right?

160
00:12:25,069 --> 00:12:27,733
The other thing we want to
do is calculate the size.

161
00:12:27,733 --> 00:12:31,689
So let's just do a variable here,
tile size.

162
00:12:32,869 --> 00:12:35,720
It's going to be a float,

163
00:12:35,720 --> 00:12:41,569
which is the division
between self.world_x.

164
00:12:43,029 --> 00:12:49,149
Let's divide that by self.cols, right?

165
00:12:49,149 --> 00:12:51,787
So that's going to give
us the size of the tile.

166
00:12:51,787 --> 00:12:54,609
And if you think within these two loops,

167
00:12:54,609 --> 00:12:58,679
what we want to be doing is
calling this function display.

168
00:12:59,739 --> 00:13:07,899
What I would like to do is eventually
separate the visualization of this tile.

169
00:13:07,899 --> 00:13:11,694
If it has multiple options,
if it has, let's say four options,

170
00:13:11,694 --> 00:13:14,915
I would like to see a cell
that shows me a number four.

171
00:13:14,915 --> 00:13:17,470
But if it's in fact collapsed,

172
00:13:17,470 --> 00:13:24,359
we would like to see that cell having
the representation of its actual tile.

173
00:13:24,359 --> 00:13:27,319
So I would like to expand
this a little bit.

174
00:13:27,319 --> 00:13:32,178
Let's just write that down and
saying if your possibility space,

175
00:13:32,178 --> 00:13:35,199
right, how do we check for that?

176
00:13:35,199 --> 00:13:39,962
We would need to check if the cells x and
y,

177
00:13:39,962 --> 00:13:45,135
right, which is what we're checking within

178
00:13:45,135 --> 00:13:49,909
these tiles, has only one tile, right?

179
00:13:51,009 --> 00:13:54,017
Then in fact is collapsed.

180
00:13:54,017 --> 00:13:56,449
Otherwise it has many possibilities,
right?

181
00:13:56,449 --> 00:13:59,121
So let's just write it right away,
actually.

182
00:13:59,121 --> 00:14:02,719
So we're going to go here and say if,

183
00:14:02,719 --> 00:14:06,822
let's first check, if the length of,

184
00:14:14,300 --> 00:14:19,822
So if the length of these

185
00:14:19,822 --> 00:14:25,069
cells equals 1 here,

186
00:14:25,069 --> 00:14:30,592
we will say that the tile

187
00:14:30,592 --> 00:14:36,393
self.cells[x] [y]

188
00:14:36,393 --> 00:14:41,289
[0], right?

189
00:14:41,289 --> 00:14:42,505
And that is what we're doing here.

190
00:14:42,505 --> 00:14:47,404
We have a list within

191
00:14:47,404 --> 00:14:51,505
lists, right?

192
00:14:51,505 --> 00:14:54,073
x and y,
it's representing the grid position.

193
00:14:54,073 --> 00:14:58,969
But then each one of those
cells has many options, right.

194
00:14:58,969 --> 00:15:03,518
We're seeing, if there's only one left,
if the cell has been collapsed, right?

195
00:15:03,518 --> 00:15:05,709
This is a way of saying if
the cell has been collapsed,

196
00:15:05,709 --> 00:15:09,919
it will only have one option, therefore
we're going to pick its first element.

197
00:15:09,919 --> 00:15:12,359
So let's imagine that you have four tiles.

198
00:15:12,359 --> 00:15:14,151
If you have four, that's more than one.

199
00:15:14,151 --> 00:15:15,127
So that's not going to be the case.

200
00:15:15,127 --> 00:15:17,695
But if you only have one,
let's just pick the first one.

201
00:15:17,695 --> 00:15:21,747
If that's the case, we could tile.display.

202
00:15:24,894 --> 00:15:28,349
And here we're going to use the display
function, I might need a little bit more

203
00:15:28,349 --> 00:15:32,859
extra space just to give the coordinate,
because here the coordinate will be x.

204
00:15:32,859 --> 00:15:37,639
Roughly what we want to say is x,
y, it's not quite right,

205
00:15:37,639 --> 00:15:42,922
the math for the position, but
bear with me here, tile_size.

206
00:15:42,922 --> 00:15:47,722
And the entropy right now,
let's just put a 0, right,

207
00:15:47,722 --> 00:15:51,923
for now,
it doesn't really matter too much, but

208
00:15:51,923 --> 00:15:56,499
this is not going to be
the right coordinate location.

209
00:15:56,499 --> 00:16:00,248
We want to use the tile
size multiplied by the x.

210
00:16:00,248 --> 00:16:02,671
X and y, which is just the count, right?

211
00:16:02,671 --> 00:16:08,880
So this tile is going to be in x times
tile_size, in times tile_size, right?

212
00:16:08,880 --> 00:16:13,047
We've done this before is how do we
kind of position the cell in the right

213
00:16:13,047 --> 00:16:14,238
location, right?

214
00:16:14,238 --> 00:16:20,626
Okay, so
that's one way of visualizing the cell.

215
00:16:20,626 --> 00:16:26,055
Else, meaning that if it has

216
00:16:26,055 --> 00:16:31,938
only one option, else we would

217
00:16:31,938 --> 00:16:37,612
like to use random.choice.

218
00:16:37,612 --> 00:16:42,041
So pick one of the possible tiles.

219
00:16:42,041 --> 00:16:48,141
This is just not really necessary,
but if you wanted,

220
00:16:48,141 --> 00:16:53,189
you could actually
visualize a random tile.

221
00:16:53,189 --> 00:16:55,983
What we actually want to do is have
a different visualization method.

222
00:16:55,983 --> 00:17:03,463
You see how the tile has display method,
right?

223
00:17:03,463 --> 00:17:06,496
Which is this display method.

224
00:17:06,496 --> 00:17:13,853
Let's just write a display method that
allows us to see all the possibilities of.

225
00:17:13,853 --> 00:17:17,985
lf the tile hasn't been collapsed,
we want to see a number four, right?

226
00:17:17,985 --> 00:17:21,249
Let's say that shows this tile
hasn't been collapsed yet,

227
00:17:21,249 --> 00:17:22,985
it has four different options.

228
00:17:22,985 --> 00:17:25,491
So how we would do that?

229
00:17:25,491 --> 00:17:33,327
Let's do define display_entropy.

230
00:17:33,327 --> 00:17:34,700
And we're going to use self.

231
00:17:34,700 --> 00:17:36,910
It's going to be very
similar to the previous one.

232
00:17:36,910 --> 00:17:43,964
So you can actually copy-paste
some of this information.

233
00:17:43,964 --> 00:17:46,620
Because basically,
it's not going to change its location.

234
00:17:46,620 --> 00:17:48,318
It's not going to change anything at all.

235
00:17:48,318 --> 00:17:51,758
Except that instead of
showing an actual tile,

236
00:17:51,758 --> 00:17:54,516
we're going to be showing a bit of text.

237
00:17:54,516 --> 00:17:56,060
Let's just define the font.

238
00:18:09,572 --> 00:18:13,248
So I would select the Consolas font Bold.

239
00:18:17,451 --> 00:18:19,042
The text size is a variable.

240
00:18:19,042 --> 00:18:23,168
So we could say,
let's start with something simple,

241
00:18:23,168 --> 00:18:25,509
something kind of arbitrary.

242
00:18:25,509 --> 00:18:29,997
And then, later down the line, we could
see how we can maybe modify the size if it

243
00:18:29,997 --> 00:18:32,695
has many options, or
small number of options.

244
00:18:32,695 --> 00:18:36,259
So let's say the size of this tile.

245
00:18:36,259 --> 00:18:42,431
Let's say something like 12, right?

246
00:18:42,431 --> 00:18:49,034
And then, the textFont would be f.

247
00:18:49,034 --> 00:18:52,010
And finally,
we can do this kind of push and

248
00:18:52,010 --> 00:18:55,337
pop matrix sequence
which we've done before.

249
00:18:56,747 --> 00:19:00,100
Basically, push translate to x.

250
00:19:00,100 --> 00:19:07,246
Let's just make sure, let's say fill (0).

251
00:19:07,246 --> 00:19:09,415
And we do want to do a rectangle.

252
00:19:09,415 --> 00:19:12,466
Yes, we want to draw
the boundary of that cell.

253
00:19:12,466 --> 00:19:16,791
But let's just also do the text,

254
00:19:16,791 --> 00:19:20,188
which is going to be the str,

255
00:19:20,188 --> 00:19:25,444
the string version of entropy, right?

256
00:19:25,444 --> 00:19:28,190
And entropy is a variable that
we're going to be passing.

257
00:19:28,190 --> 00:19:30,421
Meaning, how many options do we have?

258
00:19:30,421 --> 00:19:35,957
And where is the location of this

259
00:19:35,957 --> 00:19:41,092
would be cell_size 2- 6.

260
00:19:41,092 --> 00:19:46,065
This is kind of something I pre-tested,
but feel free to modify this number.

261
00:19:46,065 --> 00:19:50,465
And see, we're just trying to
kind of displace a little bit

262
00:19:50,465 --> 00:19:54,086
the location of the text
in relation to the cell.

263
00:19:54,086 --> 00:19:57,213
So cell_size/2,

264
00:19:57,213 --> 00:20:01,907
in this case, plus 6, right?

265
00:20:01,907 --> 00:20:04,710
So let's just see if it works.

266
00:20:04,710 --> 00:20:06,868
We've been writing a lot
of code without testing.

267
00:20:06,868 --> 00:20:10,542
So I would at this point,
really would like to make sure.

268
00:20:10,542 --> 00:20:14,161
Let's just do one more fill here,
which is 255,

269
00:20:14,161 --> 00:20:17,547
just to make sure that the text is white,
right?

270
00:20:17,547 --> 00:20:24,558
So the rectangle for
the cell is going to be black background.

271
00:20:24,558 --> 00:20:30,084
But the cell itself, which had a white
text that would show the variable entropy,

272
00:20:30,084 --> 00:20:32,983
which we are defining here as an argument.

273
00:20:34,122 --> 00:20:39,799
So as we said, when we're displaying
the grid, if the cell has been collapsed,

274
00:20:39,799 --> 00:20:45,654
we will show the actual cell, but at this
point, all cells will have four options.

275
00:20:45,654 --> 00:20:50,974
So we would actually, in fact,
use this different display function,

276
00:20:50,974 --> 00:20:53,732
which is called display_entropy.

277
00:20:53,732 --> 00:21:01,595
So a tile.display_entropy.

278
00:21:01,595 --> 00:21:03,122
Is that the way we called?

279
00:21:05,342 --> 00:21:06,642
Yeah, display_entropy.

280
00:21:06,642 --> 00:21:10,933
That's the name of
the barrier of the function.

281
00:21:10,933 --> 00:21:12,313
So display_entropy.

282
00:21:12,313 --> 00:21:17,918
And here, we can actually use the same
attributes of location, right?

283
00:21:17,918 --> 00:21:19,734
Exactly the same arguments.

284
00:21:19,734 --> 00:21:22,144
Let's just give a bit of room here.

285
00:21:22,144 --> 00:21:26,222
The only difference that we
want is that instead of, say,

286
00:21:26,222 --> 00:21:31,648
presenting a number 0, we want to
present the actual entropy size, right?

287
00:21:31,648 --> 00:21:36,721
Which we could say the entropy equals

288
00:21:36,721 --> 00:21:40,975
the length of how many possible

289
00:21:40,975 --> 00:21:45,729
tiles we have available, right?

290
00:21:45,729 --> 00:21:52,142
So if we just look at the cell xy, right?

291
00:21:52,142 --> 00:21:53,644
How many options do we have?

292
00:21:53,644 --> 00:21:55,212
Do we have four?

293
00:21:55,212 --> 00:21:56,442
Do we have one?

294
00:21:56,442 --> 00:21:59,213
Do we have 16, right?

295
00:21:59,213 --> 00:22:00,964
That's the entropy that we're passing,
right?

296
00:22:00,964 --> 00:22:05,210
So let's just use this entropy value here.

297
00:22:05,210 --> 00:22:06,939
And we could do that also for this one.

298
00:22:06,939 --> 00:22:09,110
But this one is not going to
be displaying its entropy.

299
00:22:09,110 --> 00:22:11,727
This is going to be just
displaying the cell.

300
00:22:11,727 --> 00:22:16,089
But at this point, because all cells
will start with four options, should

301
00:22:16,089 --> 00:22:20,815
always default to this visualization,
the visualization of entropy, right?

302
00:22:20,815 --> 00:22:24,417
So we have quite a bit already
written down for our environment,

303
00:22:24,417 --> 00:22:26,562
and this video is getting quite long.

304
00:22:26,562 --> 00:22:31,490
So let's just kind of wrap it
up by calling this function and

305
00:22:31,490 --> 00:22:33,569
see if it all works here.

306
00:22:33,569 --> 00:22:41,594
So let's, from environment import.

307
00:22:41,594 --> 00:22:46,953
We're going to import that class, and
let's create an instance of that class.

308
00:22:46,953 --> 00:22:50,782
Let's just create a, just for

309
00:22:50,782 --> 00:22:56,240
good measure, a global my_environment.

310
00:23:00,961 --> 00:23:05,722
And my_environment would be
an instance of environment.

311
00:23:08,622 --> 00:23:14,246
Let's do a grid of 30 by 15.

312
00:23:14,246 --> 00:23:18,257
And using canvas_width and

313
00:23:18,257 --> 00:23:24,447
canvas_height as the world size, right?

314
00:23:24,447 --> 00:23:30,851
And finally, we can run that environment.

315
00:23:33,257 --> 00:23:35,760
We're going to save here, and make sure.

316
00:23:35,760 --> 00:23:38,492
And we're going to try to run this,
and see if we have errors somewhere.

317
00:23:38,492 --> 00:23:45,260
I'm sure we're going to have a few errors,
so let's just figure it out.

318
00:23:45,260 --> 00:23:47,198
Okay, so we are running into some errors.

319
00:23:47,198 --> 00:23:51,491
Let's just see where those are.

320
00:23:51,491 --> 00:23:53,512
By checking a little bit the code here,

321
00:23:53,512 --> 00:23:56,582
I think I realized we had a bit
of an issue with indentation.

322
00:23:56,582 --> 00:23:58,600
There wasn't really kind
of many syntax errors.

323
00:23:58,600 --> 00:24:04,031
But make sure that all your
indentation here, for some reason,

324
00:24:04,031 --> 00:24:09,881
I didn't see that my indentation was off,
so I just corrected that.

325
00:24:09,881 --> 00:24:13,888
Making sure that all the definition
of functions is actually happening in

326
00:24:13,888 --> 00:24:17,284
relation to one another,
especially in this environment.

327
00:24:17,284 --> 00:24:21,252
Class, I think the other class
is actually working pretty well.

328
00:24:21,252 --> 00:24:24,273
Let's see what we have right now.

329
00:24:24,273 --> 00:24:26,879
So what you could see is this number 4.

330
00:24:26,879 --> 00:24:31,524
A small error, or
something else that we would like

331
00:24:31,524 --> 00:24:35,530
to add here is that this display_entropy.

332
00:24:35,530 --> 00:24:37,773
Let's just do here,
where it says fill (0).

333
00:24:37,773 --> 00:24:42,911
Let's do also a stroke (255,

334
00:24:42,911 --> 00:24:48,058
80) of white edge to this cell.

335
00:24:48,058 --> 00:24:51,212
So we can see now the grid, right?

336
00:24:51,212 --> 00:24:52,634
With a number 4 inside.

337
00:24:52,634 --> 00:24:55,043
If you think that
the number 4 is too small,

338
00:24:55,043 --> 00:24:57,660
you can increase the size
of the text size here.

339
00:24:57,660 --> 00:25:02,893
Maybe 16, something like that.

340
00:25:02,893 --> 00:25:04,642
So that's pretty expressive, right?

341
00:25:04,642 --> 00:25:09,598
And what is basically happening at
this point is that we are not using at

342
00:25:09,598 --> 00:25:14,144
all this first part of the if
statement that is showing the tile.

343
00:25:14,144 --> 00:25:15,150
We're going to get here,

344
00:25:15,150 --> 00:25:18,620
we're going to get to the moment of
collapsing the tile and showing something.

345
00:25:18,620 --> 00:25:22,948
But so far we are just going straight
into the display entropy because each one

346
00:25:22,948 --> 00:25:25,316
of the tiles has four possible options.

347
00:25:25,316 --> 00:25:28,382
Right, we have our nested loop for

348
00:25:28,382 --> 00:25:33,361
X and Y, which determines
where the cells are located.

349
00:25:33,361 --> 00:25:39,106
But then, inside each cell,
we have four possible tiles.

350
00:25:39,106 --> 00:25:41,175
That is what we're calling entropy, right?

351
00:25:41,175 --> 00:25:44,458
So with that in mind,
we have our data structure,

352
00:25:44,458 --> 00:25:48,061
basically the two classes,
the grid and the tile set.

353
00:25:48,061 --> 00:25:51,774
Ready to start kind of using some
information, and we start moving into what

354
00:25:51,774 --> 00:25:55,096
is the collapsing of the cell, and
the propagation, and so forth.

355
00:25:55,096 --> 00:25:59,016
So with that, I leave it here and
I'll see you in the next video.