OK, everybody.
It is finally time for our first project, so let's get into it.
So we are making a Tic TAC toe game.
If you dont know what Tic TAC Toe is.
You can Google it.
Or of course, you can't click on this because the video, but you can go to this link and read the
Wikipedia post about it.
But I'll give you a general overview of what it is.
It is a three by three grid, so we're talking three three rows like this and three columns like this,
and it has two players, so one player is in charge of drawing.
X is on the grid and another player is in charge of going 0s.
The players take turns choosing X's and O's spots to draw them.
And the first player to connect three of those X's or O's in a row column of diagonal wins.
So.
Let's say player one is XS and Player two is 0s here, player one has one because they have a column
that has three XS.
This would also be a valid winning column.
So these three columns.
Here's a diagonal where player one whose XS wins.
This is also a valid diagonal that they could win with.
Here is an example of a valid row when from player to is O's, right?
So this rule would be valid too in this row would be valid too.
All right.
So some things that you will need to use, you will need to use either a 2D array or an array of strings.
So there is a way to do this with just a one dimensional array, but that is not the way that we are
going to implement it.
We you should be using a 2D array ordinary of strings.
This can be a dynamic 2D array or a static 2D array, so that is, you know, a non dynamic 2D array.
You should definitely use a while loop and possibly for loops.
You should also definitely have conditional statements like if else, if and else.
You also should definitely have user input and some output, some things that you should use, but you
don't have to use.
I highly recommend using functions because we learn how to use functions, and they will make the program
much nicer and more professional.
You should really use functions.
I will explain a little bit about what these functions might have or what they might be about on the
next slide.
Also, I am app, you should use the set W function that we learned about so you can have nice clean
output.
It's not necessary 100 percent, but I think you really should use it because it's good practice some
things to help you get started.
We haven't really talked about passing a raise to function, so I'd like to point out some stuff here.
I have an example function called void my func.
You do not have to have a void function in your program.
I'm just using it as an example.
You can use whatever type of function you want.
The point is to focus on this between the parentheses in each one of these.
This right here is an array of characters as a parameter.
This is whether it's dynamic or not.
You can still use this syntax.
OK.
This is a 2D array of characters as a parameter.
So this is a non dynamic, so it would be like a stack one non dynamically allocated, not a heap.
One is just a static array 2D array of chars, right?
This is a way that you can pass that.
Here's the second dimension that I'm putting here.
So you put the second dimension as three.
You can use this.
There's some other ways that you can pass these arrays, but I'm just mentioning a few ways.
This is an array of strings rather than chars, and you notice I'm using a Stevie Colon colon here because
this would be the case that you didn't use the standard namespace if you are using namespace STD.
You do not need this, of course, but it's the same thing as this right here.
It just has a string, right?
So it's an array of strings as a parameter in case you want to do your program that way.
This is how you could pass it to a function.
And then we have the dynamic 2D array that we talked about already, so we did an array of pointers
that point to other arrays, if that's a parameter in one of your functions, you can do it like this.
It's Cha star star.
So it's kind of a double pointer thing and you notice there's no square brackets here.
These are not, and I repeat, not all of the ways that you can pass a raise, but one of the really
important things to know about this is that all of these are not being passed by value.
They are all able to be modified.
So when you modify an array and here it's not modifying a copy, it's modifying the original array and
all of these examples, OK?
I'm not necessarily claiming that this is called this is called passing by reference because technically
there are other ways that you can have pass the arrays, and it might be more realistic in a more realistic
example of passing by reference, but they can all be modified.
They are not passing a copy by value.
OK?
Some other things that might help you a dual loop or a value is useful for input for the row and column.
So when they're choosing the spot to put their X URL, using conditional statements is huge and pivotal.
As well as that Boolean with that to check whether someone's won yet.
So we're talking about scanning the rows, columns and diagonals.
That is something that might be useful in a function, OK?
So you might want some function that checks the game board, which is your array or 2D array or whatever
you using for the game board.
You want to check all the rows, columns and diagonals to see if anyone has one yet, and you're only
going to need to do that repeatedly, right?
Also, make sure to check whether a spot is already taken.
So if someone if there's already an X at row two, column two, for example, and then the player tries
to put another X or URL at row two column two, you should say that spot is not available or that's
invalid.
And then you should ask them to try again and keep asking for them to try again until they enter something
that is a valid spot.
You also should not let them like enter something on like row eight or something because there is no
row eight, it's a three by three grid.
OK, so let's go ahead and look at how the gameplay should look.
I'm not going to show you my code, but I will show you how the final game should look in the console.
So let's head over here, so I'm going to go ahead and run it.
I've already compiled it.
We have a nice welcome message here, so put a welcome message however you like this says welcome to
the game of Tic TAC Toe.
I also offer the option to quit, and what I say is you can enter zero four row if you want to quit.
That might seem interesting, because isn't this like rose zero?
Isn't that a valid row?
Well, yes, in your array, it starts at index zero, but I want the player to see the first row as
row one.
So I will just modify the user's input to make it be row zero if they enter row one.
If you get when you get what I'm saying, so it's.
Really rose zero in code, but the user should think of it as row one row, two or three.
Column one, column two, column three and that's how they should type the numbers for the input row
and column.
All right.
So I say you can enter a zero if you want to quit.
So if I enter a zero, it immediately stops the program.
All right, so I'm going to run it again.
Let's go ahead and look at some valid wins.
All right.
I start out saying it's X's turn, so my game just says that the first person to go is Player X.
You do not have to put Player X, you could put player one or whatever, but you're going to need to
put X's and O's on the board.
Next thing is to show the current game board.
Each time someone plays a move, you need to re display the game board and show what spots are available
and where the X's and O's are.
Here I have hyphens to show the empty spots.
You do not have to use hyphens, but I thought it would be a nice way to show the empty spots.
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
the current game board now has an X on row one column one.
So what if I go ahead and enter something that's invalid?
Let's check that out, like I enter row seven and column seven.
That's an invalid choice, so it asks the user to to choose again.
Even if I enter a valid row but are not valid column, it still asks me or invalid row, but valid column
still ask me.
And if I press zero, it would quit still.
So let me continue on, though, and make a valid win.
So let's put one one and then I'll put one three.
I'll put to one and then I'll put it three, three, four, oh, and then I'll put three one four x
and you notice it says X when?
Because there's three XS in a column right here.
What I also put is that the game was won after five turns one two three four five.
So you should also display how many turns it took to win the game.
And I mean, like, combine terms between both players.
Let's go ahead and check another valid one.
All right.
So what if I want to do a diagonal and have O's win this time?
So I say one one, four x, but then I say one three four oh three three, four x.
I say two to four.
Oh, and then maybe one to four x and then a final move.
Here, I'm going to put an O and have this one.
So I say three and one.
And now you see, there's diagonal O's.
It says 0s when and it says Game one after six turns, we have one two three four five six turns that
were played, and that's why the game was won after six terms.
So I'm going to clear and run again, and I want to show you also what happens when there is a tie.
So you also need to be able to tell if nobody won right, which you can consider like a draw or a stalemate.
You can call it whatever you want, but you need to say when that happens.
So I'm going to go ahead and make that happen to show you what you should display in that case.
So if I do like something like this.
And maybe a three to one is, oh, but then let's say to three is X, and then everyone to me is, Oh.
And then I could say like.
Three one is X and three to oh, and then one two is X.
You notice that no one got three in a row here.
And it says that the game ended in a draw.
You can put whatever you like here.
You could say that it's like a stalemate or something like that, but you need to print some message
when the game, when all the spaces spaces have been played and yet nobody won.
So a little hint they're all in the spaces have been played.
Specifically, all nine spaces have been taken up.
Yet there are no winning like columns, diagonals or rows.
All right, so that's another little hint there.
So that's pretty much it for this game.
What I want to say, another thing I want to say is I'm going to post a solution, my solution to it.
There are many solutions that you could do that I tried to make a simple one that wasn't too complex,
so you'd be able to look at it and understand.
However, I'm not a person sure I'm going to make a video walkthrough of it because most of the projects
will just have me posting a solution code.
In fact, we may not even have like descriptive videos for the projects, some of the projects.
I just give you a text description description because that's very important for you to be able to read
a document and then understand how to do a project off of a document.
So we'll have that as well.
The main point I want to get across, though, is please, please do not go look at the solution right
off the bat.
In fact, do not look at the solution until you have completely exhausted every single thing you could
do on your own.
OK?
Because it's huge is pivotal for you to do that, because if you do not, you're not going to get nearly
as much out of this course and you're not going to be able to learn nearly as well.
If you look at solutions, OK?
And that's just not my solution.
Do not go online and just search up Tic TAC toe game or something like that and then just see how someone
else did it and copy paste.
Even just looking at it and seeing how they solved it too early on is really not helping you at all.
You should really focus on it, even if it's really hard.
It's meant to be hard.
It might be a struggle.
It might take you a very long time to be able to figure this out.
But the point is to not give up if you need to look up syntax things on Stack Overflow or some other
form, like how do I pass this to a function?
How do I do this conditional thing that I forgot about?
How do I use X thing or whatever in the in C++?
You can totally look up all that or go back to the course that.
Discourse and some of the videos that we've gone over so far, and you could, you know, if you can't
find it there.
Of course, then you can go, look it up elsewhere, but do not look up answers.
That's all I'm saying.
Like, do not look up.
How to do Tic TAC toe game before you have completely exhausted all of your options.
All right, so with that, I will be seeing you in the next video.
I will go ahead and post some solution.
It will most likely be in some type of zip folder or something that I include.
Or maybe I'll have a link to it.
I'm not sure yet, but good luck with the project and I will see you in the next lecture.