1
00:00:05,969 --> 00:00:09,790
Hi, welcome to this third
video of this series.

2
00:00:09,790 --> 00:00:14,769
We are working within the project for
the wave function collapse algorithm and

3
00:00:14,769 --> 00:00:18,430
we are going to start talking
about tile compatibility.

4
00:00:18,430 --> 00:00:20,734
So, what do we mean by tile compatibility?

5
00:00:20,734 --> 00:00:24,541
We going to be using this idea that
tiles can be connected, right?

6
00:00:24,541 --> 00:00:28,440
That's why we're drawing them with this
particular kind of very simple graphic

7
00:00:28,440 --> 00:00:32,182
reference, but you could actually use
any other kind of style of graphic.

8
00:00:32,182 --> 00:00:37,017
But what we want is to represent that
certain tiles connect to one another, and

9
00:00:37,017 --> 00:00:39,686
some other tiles do not connect, right?

10
00:00:39,686 --> 00:00:43,522
So, we're going to be using color
here to present graphically

11
00:00:43,522 --> 00:00:46,270
a sense of compatibility between tiles.

12
00:00:46,270 --> 00:00:47,997
What you can see on the right,

13
00:00:47,997 --> 00:00:52,699
it's all the possible tiles that we might
have where all the connections, top,

14
00:00:52,699 --> 00:00:55,926
bottom, left and
right would be the white or black.

15
00:00:55,926 --> 00:01:00,752
And if we can go through the natural
conclusion of all the possible states of

16
00:01:00,752 --> 00:01:04,146
the tile,
we'd end up with 16 possible tiles.

17
00:01:04,146 --> 00:01:09,216
So if we have a tile like the one that you
can see in the middle and we would like to

18
00:01:09,216 --> 00:01:14,368
connect its right connection to some
tiles, we would evaluate the tileset and

19
00:01:14,368 --> 00:01:20,202
we would determine that it's, in fact,
there's four possible valid connections.

20
00:01:20,202 --> 00:01:25,962
Any tile that it's left side is white,
would in fact connect correctly.

21
00:01:25,962 --> 00:01:29,082
There's other tiles that its
left side will be black, so

22
00:01:29,082 --> 00:01:31,232
therefore we exclude those tiles.

23
00:01:31,232 --> 00:01:33,136
So that changes the possibility space.

24
00:01:33,136 --> 00:01:35,103
This tile towards its right,

25
00:01:35,103 --> 00:01:39,848
its adjacent neighbor to the right
can be only eight possible states.

26
00:01:39,848 --> 00:01:42,624
That's based on this
rule of compatibility.

27
00:01:42,624 --> 00:01:46,663
Let's evaluate that same tile,
in its lower connection, right?

28
00:01:46,663 --> 00:01:51,512
The lower connection in this case will
also be eight possible connections,

29
00:01:51,512 --> 00:01:54,184
but it would be eight different tiles.

30
00:01:54,184 --> 00:01:57,869
So if we're looking at
the adjacency on the bottom,

31
00:01:57,869 --> 00:02:03,888
every tile which it's top has this white
connectivity will in fact be compatible.

32
00:02:03,888 --> 00:02:08,676
So how will we write code for our tiles to
represent formally and within code that

33
00:02:08,676 --> 00:02:14,122
something that we could actually use quite
easily, this information of compatibility?

34
00:02:14,122 --> 00:02:17,608
What we're going to be doing,
it's a dictionary, right?

35
00:02:17,608 --> 00:02:21,806
So we're going to be doing a dictionary
that has pre-written adjacency.

36
00:02:21,806 --> 00:02:24,654
So top, bottom, left, and right.

37
00:02:24,654 --> 00:02:28,614
And we're going to be determining
that those could be in some possible

38
00:02:28,614 --> 00:02:29,662
states, right.

39
00:02:29,662 --> 00:02:33,454
We're going to be using
words here like a and b.

40
00:02:33,454 --> 00:02:38,620
If you wanted to have a tile that has more
possible maybe colors or kind of logics

41
00:02:38,620 --> 00:02:43,990
of connectivity, you could say A, B, C,
D, but we're going to keep it simple.

42
00:02:43,990 --> 00:02:49,266
So a square tile has four possible
connections, top, bottom, left and right.

43
00:02:49,266 --> 00:02:53,392
And we're going to be
switching between A and

44
00:02:53,392 --> 00:02:58,578
B as representing A will be black and
B will be white.

45
00:02:58,578 --> 00:03:02,773
In the graphic representation of the tile,
we're going to also do a representation

46
00:03:02,773 --> 00:03:06,907
that it doesn't require a texture because
later down the line we're going to learn

47
00:03:06,907 --> 00:03:10,733
how to use a texture and draw our own
textures and use those into the system,

48
00:03:10,733 --> 00:03:13,274
which will give us a lot
of creative freedom.

49
00:03:13,274 --> 00:03:15,346
But within our system currently,

50
00:03:15,346 --> 00:03:19,686
we want to draw that compatibility
with maybe these kind of rectangles.

51
00:03:19,686 --> 00:03:23,094
The red will represent B and
the green will represent A.

52
00:03:23,094 --> 00:03:26,511
And as you can see, as each one of these
tiles would be a representation of

53
00:03:26,511 --> 00:03:30,462
different compatibility, we want to have
some graphic representation of them.

54
00:03:30,462 --> 00:03:32,691
So let's jump into the code and

55
00:03:32,691 --> 00:03:37,323
see how we can actually start
using these dictionaries to define

56
00:03:37,323 --> 00:03:42,368
how each tile will have different
compatibility with other tiles.

57
00:03:42,368 --> 00:03:43,267
So here we are.

58
00:03:43,267 --> 00:03:46,824
I'm continuing where we left
off from the last video.

59
00:03:46,824 --> 00:03:51,039
Basically, I'm working
within the set environment.

60
00:03:51,039 --> 00:03:56,364
Right now we have a grid where every cell
can be in four possible states, right?

61
00:03:58,584 --> 00:04:00,904
Let's just go to the tile.

62
00:04:00,904 --> 00:04:03,681
And the first thing we want to do,
if you could see up here,

63
00:04:03,681 --> 00:04:06,224
we had used some kind of
placeholder information.

64
00:04:06,224 --> 00:04:08,544
We're not really using
this information at all.

65
00:04:08,544 --> 00:04:11,394
So let's just change this for edges.

66
00:04:12,774 --> 00:04:15,238
And edges is going to be our dictionary.

67
00:04:15,238 --> 00:04:17,182
Let's just add this to the constructor.

68
00:04:17,182 --> 00:04:18,234
So edges.

69
00:04:20,294 --> 00:04:23,894
And here we could say that
edges equals edges, right?

70
00:04:23,894 --> 00:04:24,984
So edges is going to be,

71
00:04:24,984 --> 00:04:27,834
let's remind ourselves this
is going to be a dictionary.

72
00:04:30,894 --> 00:04:34,168
Dictionary, right,

73
00:04:34,168 --> 00:04:38,647
with the keywords will be top,

74
00:04:38,647 --> 00:04:43,654
bottom, right, left and right.

75
00:04:47,910 --> 00:04:48,546
Something like that.

76
00:04:48,546 --> 00:04:53,274
Just as a reminder, these are going to
be the keywords of our dictionary.

77
00:04:53,274 --> 00:04:55,034
So now, let's save that.

78
00:04:55,034 --> 00:04:59,858
And if we would like to run the script,
we're going to run into an error

79
00:04:59,858 --> 00:05:04,684
because once we initiate our tiles here,
when we create our tiles,

80
00:05:04,684 --> 00:05:09,616
we need to provide an argument,
which is our dictionary, right?

81
00:05:09,616 --> 00:05:14,147
So let's just write a dictionary here.

82
00:05:14,147 --> 00:05:17,992
Because we want each tile to be different,
let's just write it in line, right?

83
00:05:17,992 --> 00:05:24,632
So let's just open a curly braces and
say top, right?

84
00:05:24,632 --> 00:05:30,084
This is going to be,
let's just give it a B for now, right?

85
00:05:30,084 --> 00:05:33,844
So that's going to be the first
entry of the dictionary.

86
00:05:33,844 --> 00:05:35,544
The second one will be bottom.

87
00:05:37,084 --> 00:05:39,384
This is going to be also a B.

88
00:05:41,244 --> 00:05:47,084
Let's go with left.

89
00:05:47,084 --> 00:05:50,464
That will be A.

90
00:05:52,484 --> 00:05:57,402
So yeah, take your time here because it
certainly couldn't be confusing sometimes

91
00:05:57,402 --> 00:05:59,834
to write these dictionaries correctly.

92
00:06:02,494 --> 00:06:04,430
And that would be a two, right?

93
00:06:04,430 --> 00:06:07,454
And at this point we can
close the dictionary, right?

94
00:06:07,454 --> 00:06:09,038
So let's see what we have.

95
00:06:09,038 --> 00:06:13,372
We have top B, bottom B,
left A, right A, right, and

96
00:06:13,372 --> 00:06:16,314
that's the end of that dictionary.

97
00:06:17,614 --> 00:06:21,932
We could copy paste it For

98
00:06:21,932 --> 00:06:25,422
each one of our tiles so

99
00:06:25,422 --> 00:06:32,202
that we could actually change it, right?

100
00:06:32,202 --> 00:06:37,369
And as you can see here, we could say,
well, the next tile would

101
00:06:37,369 --> 00:06:42,174
have a compatibility of A,
here this is going to be an AA, BA.

102
00:06:45,434 --> 00:06:50,226
All of them will have the same keywords,
right, AA BA.

103
00:06:50,226 --> 00:06:57,614
And this one will have AA BB.

104
00:07:00,034 --> 00:07:05,394
And as you can see,
we're actually using only not

105
00:07:05,394 --> 00:07:11,014
all the 16 possible
combinations between these.

106
00:07:12,614 --> 00:07:15,234
So AB, AB.

107
00:07:17,054 --> 00:07:17,982
There we go.

108
00:07:17,982 --> 00:07:20,672
So, we could write all
the possible combinations and

109
00:07:20,672 --> 00:07:22,926
we're going to be doing
that in a bit of time.

110
00:07:22,926 --> 00:07:27,639
But for now we want to just be able to
check that we have a way of representing

111
00:07:27,639 --> 00:07:29,474
the compatibility system.

112
00:07:31,094 --> 00:07:35,597
So right now, because the way
we're displaying the information,

113
00:07:35,597 --> 00:07:40,774
there's four possible states, we are not
in fact drawing the actual tile.

114
00:07:40,774 --> 00:07:45,476
So let's just comment out three of them.

115
00:07:45,476 --> 00:07:50,388
So let's imagine that now all tiles
have only a singular option, right?

116
00:07:50,388 --> 00:07:54,473
Therefore, we're going to be triggering
this part of the equation, right?

117
00:07:54,473 --> 00:07:56,844
So let's see what we get here.

118
00:07:56,844 --> 00:07:58,348
So it's working.

119
00:07:58,348 --> 00:07:59,988
It's actually not creating the text.

120
00:07:59,988 --> 00:08:03,764
So it's actually switching the function
that we're using to draw it, right?

121
00:08:03,764 --> 00:08:08,193
So instead of drawing
the entropy which has the text,

122
00:08:08,193 --> 00:08:11,944
we actually go in this function display.

123
00:08:11,944 --> 00:08:13,096
Okay, great.

124
00:08:13,096 --> 00:08:16,496
So, let's just add to that function.

125
00:08:16,496 --> 00:08:19,051
Let's add to the function display here,

126
00:08:19,051 --> 00:08:23,582
some information that would allow us
to see that compatibility, right?

127
00:08:23,582 --> 00:08:29,037
So we're going to do those
little rectangles, green or

128
00:08:29,037 --> 00:08:35,340
red for each cell based on its
compatibility logic, right?

129
00:08:35,340 --> 00:08:40,424
So what I would like to do first of all
is write a very small function down here.

130
00:08:42,444 --> 00:08:45,584
Let's call that a color by edge.

131
00:08:48,564 --> 00:08:50,540
And it's going to be a self.

132
00:08:50,540 --> 00:08:53,802
And I'm going to use
a variable called which,

133
00:08:53,802 --> 00:08:58,060
you're going to see in a minute
how we're going to use that.

134
00:08:58,060 --> 00:09:02,231
So we're going to say which edge
if I give you the top, right,

135
00:09:02,231 --> 00:09:04,310
which edge am I evaluating?

136
00:09:04,310 --> 00:09:07,062
If I give you a top, then give me a color.

137
00:09:07,062 --> 00:09:11,270
Let's say green or red,
depending if that matches A or B, right?

138
00:09:11,270 --> 00:09:16,198
So let's say if self.edge, which,

139
00:09:16,198 --> 00:09:21,280
right, because we're going to be asking

140
00:09:21,280 --> 00:09:25,754
the dictionary, are you the top?

141
00:09:26,814 --> 00:09:29,074
If the top is an A.

142
00:09:29,074 --> 00:09:33,535
If we check our an A,

143
00:09:33,535 --> 00:09:39,574
then return the color red.

144
00:09:41,154 --> 00:09:46,258
This is a very first kind of
way of starting to check if

145
00:09:46,258 --> 00:09:52,174
the information of this adjacency or
this compatibility and

146
00:09:52,174 --> 00:09:56,264
we can use some color to visualize it.

147
00:09:56,264 --> 00:10:01,391
If we're going to say here
if the same equation, but

148
00:10:01,391 --> 00:10:06,164
if it's in fact B,
give me a different color.

149
00:10:07,944 --> 00:10:14,296
So let's return that,
in this case let's move that to green.

150
00:10:14,296 --> 00:10:16,478
Rg, red, green, right?

151
00:10:16,478 --> 00:10:23,744
And finally, let's just do for
good measure and else return back, right?

152
00:10:26,982 --> 00:10:28,372
Turn the colors zero, right?

153
00:10:28,372 --> 00:10:33,264
So we have a way of quickly switching
the colors based on the dictionary, right?

154
00:10:34,444 --> 00:10:36,060
So now we have that function.

155
00:10:36,060 --> 00:10:40,338
Let's just alter our display
function using this new

156
00:10:40,338 --> 00:10:43,644
function that we have available.

157
00:10:43,644 --> 00:10:49,960
So, let's imagine that we've
already done the rectangle,

158
00:10:49,960 --> 00:10:54,339
which is going to
represent the background.

159
00:10:54,339 --> 00:11:01,028
Here what we're going to be doing
is transition to a no stroke,

160
00:11:01,028 --> 00:11:05,618
and switch also to rect, mode, center,

161
00:11:05,618 --> 00:11:10,602
because it's going to be
easier to locate these

162
00:11:10,602 --> 00:11:16,488
rectangles that we're going to
draw by their center.

163
00:11:16,488 --> 00:11:20,449
So we're going to say that the field,
the color of this rectangle,

164
00:11:20,449 --> 00:11:23,190
it's going to be using our function,
right?

165
00:11:23,190 --> 00:11:28,806
Self.color by edge, right?

166
00:11:28,806 --> 00:11:36,699
And we're going to evaluate the top edge.

167
00:11:36,699 --> 00:11:38,558
That's going to be the color, right?

168
00:11:38,558 --> 00:11:41,358
So we're going to be doing that for
each one of these edges,

169
00:11:41,358 --> 00:11:42,874
and let's do a rectangle here.

170
00:11:44,134 --> 00:11:48,004
And this actually,
when I wrote it the first time,

171
00:11:48,004 --> 00:11:51,604
it took me a little bit of
time to figure out, but

172
00:11:51,604 --> 00:11:58,074
what we want to do is a small rectangle
that it's positioned within the cell.

173
00:11:58,074 --> 00:12:04,157
In this case,
we're thinking on the top most corner.

174
00:12:04,157 --> 00:12:06,730
So, bear with me here.

175
00:12:06,730 --> 00:12:12,346
The equation that I came up with

176
00:12:12,346 --> 00:12:18,394
is cell size divided by two here,

177
00:12:18,394 --> 00:12:24,658
that's the x zero plus cell size,

178
00:12:24,658 --> 00:12:31,138
divided by ten and comma cell size,

179
00:12:31,138 --> 00:12:35,474
divided by five twice.

180
00:12:36,734 --> 00:12:40,116
Let's look at what we have
with only a single one.

181
00:12:43,874 --> 00:12:46,754
I think that could work.

182
00:12:46,754 --> 00:12:48,614
Let's see why we're getting an error here.

183
00:12:50,274 --> 00:12:51,530
Okay, so that's working.

184
00:12:51,530 --> 00:12:52,730
So what are we having here?

185
00:12:52,730 --> 00:12:53,882
Let's see this in detail.

186
00:12:53,882 --> 00:13:00,282
What we're creating is a little
rectangle on the top edge, right?

187
00:13:00,282 --> 00:13:05,616
And we are saying, make it green or
red based on this function here,

188
00:13:05,616 --> 00:13:09,894
if it's B, it's going to be green, right?

189
00:13:09,894 --> 00:13:12,110
So let's just go into the environment and
see, okay?

190
00:13:12,110 --> 00:13:13,614
In fact, top, it's B.

191
00:13:13,614 --> 00:13:17,814
So if you want it to be red,
we could put an A there, right?

192
00:13:17,814 --> 00:13:18,854
Let's see.

193
00:13:18,854 --> 00:13:25,670
So the same rectangle on the top
is showing us that B or A, right?

194
00:13:25,670 --> 00:13:28,262
So we like B, fine, right?

195
00:13:28,262 --> 00:13:32,566
So, it's a graphic representation
of the compatibility, right?

196
00:13:32,566 --> 00:13:37,367
So, this one, we need to do
four little rectangles based on

197
00:13:37,367 --> 00:13:41,244
the diagram that we saw on the slides,
right?

198
00:13:41,244 --> 00:13:42,744
So we can copy that.

199
00:13:44,964 --> 00:13:47,436
That's three and one more, right?

200
00:13:47,436 --> 00:13:53,246
So one would be for the bottom,
another one would be for

201
00:13:53,246 --> 00:13:58,184
the left, another one would be for
the right.

202
00:13:59,724 --> 00:14:07,048
The only difference would be,
some of these locations will change.

203
00:14:07,048 --> 00:14:14,564
So if we go to the bottom, the y
coordinate would be, in fact, cell size.

204
00:14:18,464 --> 00:14:19,040
Let's see.

205
00:14:19,040 --> 00:14:26,484
It would be cell size minus cell
size divided by ten, right?

206
00:14:26,484 --> 00:14:28,468
And everything else remains the same.

207
00:14:28,468 --> 00:14:31,772
Let's just check one by one, and
I'm going to comment these ones out.

208
00:14:31,772 --> 00:14:36,996
Let's check if that second one,
the bottom one works.

209
00:14:36,996 --> 00:14:42,124
We have two, the top and
bottom working correctly.

210
00:14:42,124 --> 00:14:45,164
Let's just do the two missing ones.

211
00:14:45,164 --> 00:14:49,684
So let's evaluate this one.

212
00:14:49,684 --> 00:14:53,959
So we're going to do cell size divided by,

213
00:14:53,959 --> 00:14:57,614
in this case, 10 in x and 2 in y.

214
00:14:59,314 --> 00:15:01,134
That should give us the left side.

215
00:15:04,314 --> 00:15:05,954
Okay, that's good.

216
00:15:05,954 --> 00:15:09,338
And then the right side,

217
00:15:09,338 --> 00:15:14,493
we're going to do as we did in the y here,

218
00:15:14,493 --> 00:15:20,135
cell size minus cell size divided by ten,

219
00:15:20,135 --> 00:15:28,374
and then cell size divided by
two in this direction, right?

220
00:15:30,274 --> 00:15:34,395
Okay, so basically we have
all the possible sides or

221
00:15:34,395 --> 00:15:40,170
the edges represented with this kind
of little rectangle to identify.

222
00:15:40,170 --> 00:15:43,701
If you find a better
visualization of compatibility,

223
00:15:43,701 --> 00:15:45,986
by all means, you can draw that.

224
00:15:45,986 --> 00:15:48,294
But this is kind of
a simple representation.

225
00:15:49,304 --> 00:15:50,982
Two colors for A and B, and

226
00:15:50,982 --> 00:15:55,368
a simple rectangle that would be
on each side of the cell, right?

227
00:15:55,368 --> 00:15:59,400
If the cell has more than
one single option, right, so

228
00:15:59,400 --> 00:16:04,792
it hasn't been collapsed yet,
we will represent its numbers, right?

229
00:16:04,792 --> 00:16:08,040
So we have two functions,
one that represents its entropy, and

230
00:16:08,040 --> 00:16:10,792
another one that represents
its collapsed state.

231
00:16:10,792 --> 00:16:16,314
So with this, we're wrapping
up this compatibility video.

232
00:16:16,314 --> 00:16:20,268
The representation of the collapsed state
is something that we're going to be moving

233
00:16:20,268 --> 00:16:22,890
towards as we learn about
how do we collapse a cell?

234
00:16:22,890 --> 00:16:25,498
And we're going to have
a visualization for that.

235
00:16:25,498 --> 00:16:26,474
So I'll see you in the next video.