1
00:00:01,000 --> 00:00:02,020
OK, everybody.

2
00:00:02,030 --> 00:00:06,130
It is finally time for our first project, so let's get into it.

3
00:00:07,270 --> 00:00:09,540
So we are making a Tic TAC toe game.

4
00:00:09,550 --> 00:00:11,090
If you dont know what Tic TAC Toe is.

5
00:00:11,110 --> 00:00:12,040
You can Google it.

6
00:00:12,370 --> 00:00:17,140
Or of course, you can't click on this because the video, but you can go to this link and read the

7
00:00:17,140 --> 00:00:18,280
Wikipedia post about it.

8
00:00:19,340 --> 00:00:22,070
But I'll give you a general overview of what it is.

9
00:00:22,580 --> 00:00:28,430
It is a three by three grid, so we're talking three three rows like this and three columns like this,

10
00:00:28,430 --> 00:00:31,730
and it has two players, so one player is in charge of drawing.

11
00:00:31,730 --> 00:00:34,600
X is on the grid and another player is in charge of going 0s.

12
00:00:35,030 --> 00:00:39,230
The players take turns choosing X's and O's spots to draw them.

13
00:00:39,500 --> 00:00:45,570
And the first player to connect three of those X's or O's in a row column of diagonal wins.

14
00:00:45,590 --> 00:00:46,010
So.

15
00:00:47,480 --> 00:00:53,750
Let's say player one is XS and Player two is 0s here, player one has one because they have a column

16
00:00:53,750 --> 00:00:54,890
that has three XS.

17
00:00:55,190 --> 00:00:58,040
This would also be a valid winning column.

18
00:00:58,430 --> 00:01:00,200
This would also be a valid winning column.

19
00:01:00,200 --> 00:01:01,490
So these three columns.

20
00:01:01,900 --> 00:01:05,690
Here's a diagonal where player one whose XS wins.

21
00:01:06,140 --> 00:01:08,930
This is also a valid diagonal that they could win with.

22
00:01:10,040 --> 00:01:15,530
Here is an example of a valid row when from player to is O's, right?

23
00:01:16,010 --> 00:01:19,400
So this rule would be valid too in this row would be valid too.

24
00:01:20,930 --> 00:01:21,290
All right.

25
00:01:21,290 --> 00:01:27,260
So some things that you will need to use, you will need to use either a 2D array or an array of strings.

26
00:01:27,650 --> 00:01:33,410
So there is a way to do this with just a one dimensional array, but that is not the way that we are

27
00:01:33,410 --> 00:01:34,550
going to implement it.

28
00:01:35,210 --> 00:01:38,150
We you should be using a 2D array ordinary of strings.

29
00:01:39,090 --> 00:01:45,960
This can be a dynamic 2D array or a static 2D array, so that is, you know, a non dynamic 2D array.

30
00:01:46,920 --> 00:01:50,640
You should definitely use a while loop and possibly for loops.

31
00:01:50,730 --> 00:01:55,140
You should also definitely have conditional statements like if else, if and else.

32
00:01:55,560 --> 00:02:03,910
You also should definitely have user input and some output, some things that you should use, but you

33
00:02:03,990 --> 00:02:05,310
don't have to use.

34
00:02:05,520 --> 00:02:10,710
I highly recommend using functions because we learn how to use functions, and they will make the program

35
00:02:10,710 --> 00:02:12,390
much nicer and more professional.

36
00:02:12,690 --> 00:02:13,950
You should really use functions.

37
00:02:14,460 --> 00:02:20,190
I will explain a little bit about what these functions might have or what they might be about on the

38
00:02:20,190 --> 00:02:20,910
next slide.

39
00:02:22,140 --> 00:02:27,120
Also, I am app, you should use the set W function that we learned about so you can have nice clean

40
00:02:27,120 --> 00:02:27,540
output.

41
00:02:27,540 --> 00:02:34,320
It's not necessary 100 percent, but I think you really should use it because it's good practice some

42
00:02:34,320 --> 00:02:35,410
things to help you get started.

43
00:02:35,430 --> 00:02:39,510
We haven't really talked about passing a raise to function, so I'd like to point out some stuff here.

44
00:02:39,510 --> 00:02:42,000
I have an example function called void my func.

45
00:02:42,000 --> 00:02:46,220
You do not have to have a void function in your program.

46
00:02:46,230 --> 00:02:47,760
I'm just using it as an example.

47
00:02:47,760 --> 00:02:49,650
You can use whatever type of function you want.

48
00:02:50,010 --> 00:02:53,370
The point is to focus on this between the parentheses in each one of these.

49
00:02:53,970 --> 00:02:57,600
This right here is an array of characters as a parameter.

50
00:02:58,620 --> 00:03:00,600
This is whether it's dynamic or not.

51
00:03:00,600 --> 00:03:02,280
You can still use this syntax.

52
00:03:02,400 --> 00:03:02,760
OK.

53
00:03:04,080 --> 00:03:06,910
This is a 2D array of characters as a parameter.

54
00:03:06,930 --> 00:03:13,170
So this is a non dynamic, so it would be like a stack one non dynamically allocated, not a heap.

55
00:03:13,170 --> 00:03:18,390
One is just a static array 2D array of chars, right?

56
00:03:18,420 --> 00:03:19,680
This is a way that you can pass that.

57
00:03:19,680 --> 00:03:22,050
Here's the second dimension that I'm putting here.

58
00:03:22,050 --> 00:03:24,420
So you put the second dimension as three.

59
00:03:24,900 --> 00:03:25,770
You can use this.

60
00:03:25,770 --> 00:03:31,140
There's some other ways that you can pass these arrays, but I'm just mentioning a few ways.

61
00:03:32,470 --> 00:03:37,300
This is an array of strings rather than chars, and you notice I'm using a Stevie Colon colon here because

62
00:03:37,300 --> 00:03:42,430
this would be the case that you didn't use the standard namespace if you are using namespace STD.

63
00:03:42,550 --> 00:03:46,230
You do not need this, of course, but it's the same thing as this right here.

64
00:03:46,240 --> 00:03:47,560
It just has a string, right?

65
00:03:47,570 --> 00:03:51,400
So it's an array of strings as a parameter in case you want to do your program that way.

66
00:03:51,430 --> 00:03:53,470
This is how you could pass it to a function.

67
00:03:54,820 --> 00:04:01,030
And then we have the dynamic 2D array that we talked about already, so we did an array of pointers

68
00:04:01,030 --> 00:04:06,130
that point to other arrays, if that's a parameter in one of your functions, you can do it like this.

69
00:04:06,140 --> 00:04:07,470
It's Cha star star.

70
00:04:07,480 --> 00:04:11,860
So it's kind of a double pointer thing and you notice there's no square brackets here.

71
00:04:12,950 --> 00:04:18,800
These are not, and I repeat, not all of the ways that you can pass a raise, but one of the really

72
00:04:18,800 --> 00:04:24,200
important things to know about this is that all of these are not being passed by value.

73
00:04:24,740 --> 00:04:26,870
They are all able to be modified.

74
00:04:26,870 --> 00:04:33,140
So when you modify an array and here it's not modifying a copy, it's modifying the original array and

75
00:04:33,140 --> 00:04:34,580
all of these examples, OK?

76
00:04:35,150 --> 00:04:40,970
I'm not necessarily claiming that this is called this is called passing by reference because technically

77
00:04:40,970 --> 00:04:47,570
there are other ways that you can have pass the arrays, and it might be more realistic in a more realistic

78
00:04:47,570 --> 00:04:51,350
example of passing by reference, but they can all be modified.

79
00:04:51,350 --> 00:04:53,660
They are not passing a copy by value.

80
00:04:53,660 --> 00:04:54,010
OK?

81
00:04:55,220 --> 00:05:02,510
Some other things that might help you a dual loop or a value is useful for input for the row and column.

82
00:05:03,080 --> 00:05:09,350
So when they're choosing the spot to put their X URL, using conditional statements is huge and pivotal.

83
00:05:09,350 --> 00:05:12,440
As well as that Boolean with that to check whether someone's won yet.

84
00:05:12,450 --> 00:05:15,800
So we're talking about scanning the rows, columns and diagonals.

85
00:05:16,400 --> 00:05:19,100
That is something that might be useful in a function, OK?

86
00:05:19,520 --> 00:05:25,940
So you might want some function that checks the game board, which is your array or 2D array or whatever

87
00:05:25,940 --> 00:05:26,920
you using for the game board.

88
00:05:26,940 --> 00:05:32,330
You want to check all the rows, columns and diagonals to see if anyone has one yet, and you're only

89
00:05:32,350 --> 00:05:33,800
going to need to do that repeatedly, right?

90
00:05:34,490 --> 00:05:36,890
Also, make sure to check whether a spot is already taken.

91
00:05:36,890 --> 00:05:43,940
So if someone if there's already an X at row two, column two, for example, and then the player tries

92
00:05:43,940 --> 00:05:52,820
to put another X or URL at row two column two, you should say that spot is not available or that's

93
00:05:52,820 --> 00:05:53,570
invalid.

94
00:05:53,570 --> 00:05:58,250
And then you should ask them to try again and keep asking for them to try again until they enter something

95
00:05:58,250 --> 00:05:59,300
that is a valid spot.

96
00:05:59,810 --> 00:06:04,280
You also should not let them like enter something on like row eight or something because there is no

97
00:06:04,280 --> 00:06:06,010
row eight, it's a three by three grid.

98
00:06:06,020 --> 00:06:11,030
OK, so let's go ahead and look at how the gameplay should look.

99
00:06:11,030 --> 00:06:15,290
I'm not going to show you my code, but I will show you how the final game should look in the console.

100
00:06:16,400 --> 00:06:20,320
So let's head over here, so I'm going to go ahead and run it.

101
00:06:20,330 --> 00:06:21,440
I've already compiled it.

102
00:06:21,740 --> 00:06:26,510
We have a nice welcome message here, so put a welcome message however you like this says welcome to

103
00:06:26,510 --> 00:06:27,590
the game of Tic TAC Toe.

104
00:06:28,130 --> 00:06:34,760
I also offer the option to quit, and what I say is you can enter zero four row if you want to quit.

105
00:06:35,270 --> 00:06:38,810
That might seem interesting, because isn't this like rose zero?

106
00:06:38,810 --> 00:06:40,160
Isn't that a valid row?

107
00:06:41,220 --> 00:06:47,940
Well, yes, in your array, it starts at index zero, but I want the player to see the first row as

108
00:06:47,940 --> 00:06:48,870
row one.

109
00:06:49,410 --> 00:06:55,950
So I will just modify the user's input to make it be row zero if they enter row one.

110
00:06:56,160 --> 00:06:57,990
If you get when you get what I'm saying, so it's.

111
00:06:59,010 --> 00:07:04,680
Really rose zero in code, but the user should think of it as row one row, two or three.

112
00:07:05,010 --> 00:07:09,660
Column one, column two, column three and that's how they should type the numbers for the input row

113
00:07:09,660 --> 00:07:10,100
and column.

114
00:07:10,110 --> 00:07:10,410
All right.

115
00:07:10,890 --> 00:07:14,160
So I say you can enter a zero if you want to quit.

116
00:07:14,670 --> 00:07:18,250
So if I enter a zero, it immediately stops the program.

117
00:07:18,270 --> 00:07:21,060
All right, so I'm going to run it again.

118
00:07:21,270 --> 00:07:24,330
Let's go ahead and look at some valid wins.

119
00:07:24,360 --> 00:07:24,720
All right.

120
00:07:25,110 --> 00:07:31,250
I start out saying it's X's turn, so my game just says that the first person to go is Player X.

121
00:07:31,260 --> 00:07:35,310
You do not have to put Player X, you could put player one or whatever, but you're going to need to

122
00:07:35,310 --> 00:07:36,810
put X's and O's on the board.

123
00:07:37,470 --> 00:07:39,930
Next thing is to show the current game board.

124
00:07:39,960 --> 00:07:47,130
Each time someone plays a move, you need to re display the game board and show what spots are available

125
00:07:47,130 --> 00:07:48,870
and where the X's and O's are.

126
00:07:49,080 --> 00:07:52,180
Here I have hyphens to show the empty spots.

127
00:07:53,010 --> 00:07:56,850
You do not have to use hyphens, but I thought it would be a nice way to show the empty spots.

128
00:07:57,510 --> 00:08:02,880
I'm going to put row one column one, and now I'm going to see that it says it's O's turn, and it shows

129
00:08:02,880 --> 00:08:07,410
the current game board now has an X on row one column one.

130
00:08:08,740 --> 00:08:13,150
So what if I go ahead and enter something that's invalid?

131
00:08:13,300 --> 00:08:16,900
Let's check that out, like I enter row seven and column seven.

132
00:08:17,350 --> 00:08:20,860
That's an invalid choice, so it asks the user to to choose again.

133
00:08:20,890 --> 00:08:28,450
Even if I enter a valid row but are not valid column, it still asks me or invalid row, but valid column

134
00:08:28,450 --> 00:08:29,350
still ask me.

135
00:08:29,350 --> 00:08:32,500
And if I press zero, it would quit still.

136
00:08:33,730 --> 00:08:37,190
So let me continue on, though, and make a valid win.

137
00:08:37,300 --> 00:08:41,770
So let's put one one and then I'll put one three.

138
00:08:43,230 --> 00:08:50,220
I'll put to one and then I'll put it three, three, four, oh, and then I'll put three one four x

139
00:08:50,220 --> 00:08:53,160
and you notice it says X when?

140
00:08:53,160 --> 00:08:56,220
Because there's three XS in a column right here.

141
00:08:56,790 --> 00:09:02,690
What I also put is that the game was won after five turns one two three four five.

142
00:09:02,700 --> 00:09:07,230
So you should also display how many turns it took to win the game.

143
00:09:07,230 --> 00:09:09,840
And I mean, like, combine terms between both players.

144
00:09:11,130 --> 00:09:12,930
Let's go ahead and check another valid one.

145
00:09:12,960 --> 00:09:13,290
All right.

146
00:09:13,650 --> 00:09:16,770
So what if I want to do a diagonal and have O's win this time?

147
00:09:16,780 --> 00:09:23,580
So I say one one, four x, but then I say one three four oh three three, four x.

148
00:09:24,120 --> 00:09:25,590
I say two to four.

149
00:09:25,590 --> 00:09:29,940
Oh, and then maybe one to four x and then a final move.

150
00:09:29,940 --> 00:09:32,100
Here, I'm going to put an O and have this one.

151
00:09:32,100 --> 00:09:35,670
So I say three and one.

152
00:09:36,450 --> 00:09:38,270
And now you see, there's diagonal O's.

153
00:09:38,280 --> 00:09:44,490
It says 0s when and it says Game one after six turns, we have one two three four five six turns that

154
00:09:44,490 --> 00:09:47,370
were played, and that's why the game was won after six terms.

155
00:09:48,660 --> 00:09:54,850
So I'm going to clear and run again, and I want to show you also what happens when there is a tie.

156
00:09:54,870 --> 00:10:02,130
So you also need to be able to tell if nobody won right, which you can consider like a draw or a stalemate.

157
00:10:02,140 --> 00:10:05,400
You can call it whatever you want, but you need to say when that happens.

158
00:10:05,760 --> 00:10:09,330
So I'm going to go ahead and make that happen to show you what you should display in that case.

159
00:10:09,330 --> 00:10:12,180
So if I do like something like this.

160
00:10:15,410 --> 00:10:27,800
And maybe a three to one is, oh, but then let's say to three is X, and then everyone to me is, Oh.

161
00:10:28,860 --> 00:10:31,320
And then I could say like.

162
00:10:34,320 --> 00:10:44,640
Three one is X and three to oh, and then one two is X.

163
00:10:45,180 --> 00:10:49,080
You notice that no one got three in a row here.

164
00:10:49,560 --> 00:10:52,050
And it says that the game ended in a draw.

165
00:10:52,080 --> 00:10:53,310
You can put whatever you like here.

166
00:10:53,310 --> 00:10:57,810
You could say that it's like a stalemate or something like that, but you need to print some message

167
00:10:58,230 --> 00:11:04,650
when the game, when all the spaces spaces have been played and yet nobody won.

168
00:11:04,710 --> 00:11:07,680
So a little hint they're all in the spaces have been played.

169
00:11:07,680 --> 00:11:11,190
Specifically, all nine spaces have been taken up.

170
00:11:11,520 --> 00:11:16,620
Yet there are no winning like columns, diagonals or rows.

171
00:11:16,650 --> 00:11:18,210
All right, so that's another little hint there.

172
00:11:18,210 --> 00:11:21,210
So that's pretty much it for this game.

173
00:11:22,290 --> 00:11:30,760
What I want to say, another thing I want to say is I'm going to post a solution, my solution to it.

174
00:11:30,780 --> 00:11:37,230
There are many solutions that you could do that I tried to make a simple one that wasn't too complex,

175
00:11:38,910 --> 00:11:40,890
so you'd be able to look at it and understand.

176
00:11:41,280 --> 00:11:46,740
However, I'm not a person sure I'm going to make a video walkthrough of it because most of the projects

177
00:11:46,740 --> 00:11:49,140
will just have me posting a solution code.

178
00:11:50,340 --> 00:11:54,660
In fact, we may not even have like descriptive videos for the projects, some of the projects.

179
00:11:54,660 --> 00:11:59,220
I just give you a text description description because that's very important for you to be able to read

180
00:11:59,220 --> 00:12:03,030
a document and then understand how to do a project off of a document.

181
00:12:03,040 --> 00:12:04,950
So we'll have that as well.

182
00:12:05,220 --> 00:12:13,050
The main point I want to get across, though, is please, please do not go look at the solution right

183
00:12:13,050 --> 00:12:13,590
off the bat.

184
00:12:13,620 --> 00:12:19,920
In fact, do not look at the solution until you have completely exhausted every single thing you could

185
00:12:19,920 --> 00:12:20,970
do on your own.

186
00:12:21,510 --> 00:12:22,010
OK?

187
00:12:22,440 --> 00:12:27,690
Because it's huge is pivotal for you to do that, because if you do not, you're not going to get nearly

188
00:12:27,690 --> 00:12:32,620
as much out of this course and you're not going to be able to learn nearly as well.

189
00:12:32,640 --> 00:12:34,380
If you look at solutions, OK?

190
00:12:34,710 --> 00:12:36,210
And that's just not my solution.

191
00:12:36,690 --> 00:12:43,950
Do not go online and just search up Tic TAC toe game or something like that and then just see how someone

192
00:12:43,950 --> 00:12:45,360
else did it and copy paste.

193
00:12:46,260 --> 00:12:51,930
Even just looking at it and seeing how they solved it too early on is really not helping you at all.

194
00:12:51,970 --> 00:12:55,590
You should really focus on it, even if it's really hard.

195
00:12:56,160 --> 00:12:57,210
It's meant to be hard.

196
00:12:57,840 --> 00:12:59,010
It might be a struggle.

197
00:12:59,010 --> 00:13:01,800
It might take you a very long time to be able to figure this out.

198
00:13:01,800 --> 00:13:09,060
But the point is to not give up if you need to look up syntax things on Stack Overflow or some other

199
00:13:09,060 --> 00:13:11,420
form, like how do I pass this to a function?

200
00:13:11,460 --> 00:13:15,120
How do I do this conditional thing that I forgot about?

201
00:13:15,130 --> 00:13:20,080
How do I use X thing or whatever in the in C++?

202
00:13:20,100 --> 00:13:23,730
You can totally look up all that or go back to the course that.

203
00:13:24,720 --> 00:13:30,390
Discourse and some of the videos that we've gone over so far, and you could, you know, if you can't

204
00:13:30,390 --> 00:13:31,260
find it there.

205
00:13:31,290 --> 00:13:34,990
Of course, then you can go, look it up elsewhere, but do not look up answers.

206
00:13:35,010 --> 00:13:35,790
That's all I'm saying.

207
00:13:35,790 --> 00:13:36,510
Like, do not look up.

208
00:13:36,510 --> 00:13:40,860
How to do Tic TAC toe game before you have completely exhausted all of your options.

209
00:13:42,570 --> 00:13:46,650
All right, so with that, I will be seeing you in the next video.

210
00:13:47,250 --> 00:13:49,710
I will go ahead and post some solution.

211
00:13:50,040 --> 00:13:55,080
It will most likely be in some type of zip folder or something that I include.

212
00:13:55,080 --> 00:13:56,330
Or maybe I'll have a link to it.

213
00:13:56,340 --> 00:14:01,590
I'm not sure yet, but good luck with the project and I will see you in the next lecture.
