//This is a tic tac toe game written in C designed for beginners //(This doesn't contain the use of pointers or other more advanced C topics) #include #include #include #include char board[3][3]; const char PLAYER = 'X'; const char COMPUTER = 'O'; void resetBoard(); void printBoard(); int checkFreeSpaces(); void playerMove(); void computerMove(); char checkWinner(); void printWinner(char); int main() { char winner = ' '; char response = ' '; do { winner = ' '; response = ' '; resetBoard(); while(winner == ' ' && checkFreeSpaces() != 0) { printBoard(); playerMove(); winner = checkWinner(); if(winner != ' ' || checkFreeSpaces() == 0) { break; } computerMove(); winner = checkWinner(); if(winner != ' ' || checkFreeSpaces() == 0) { break; } } printBoard(); printWinner(winner); printf(" Would you like to play again? (Y/N): "); scanf("%c"); scanf("%c", &response); response = toupper(response); } while (response == 'Y'); printf("Thanks for playing!"); return 0; } void resetBoard() { for(int i = 0; i < 3; i++) { for(int j = 0; j < 3; j++) { board[i][j] = ' '; } } } void printBoard() { printf(" %c | %c | %c ", board[0][0], board[0][1], board[0][2]); printf(" ---|---|--- "); printf(" %c | %c | %c ", board[1][0], board[1][1], board[1][2]); printf(" ---|---|--- "); printf(" %c | %c | %c ", board[2][0], board[2][1], board[2][2]); printf(" "); } int checkFreeSpaces() { int freeSpaces = 9; for(int i = 0; i < 3; i++) { for(int j = 0; j < 3; j++) { if(board[i][j] != ' ') { freeSpaces--; } } } return freeSpaces; } void playerMove() { int x; int y; do { printf("Enter row #(1-3): "); scanf("%d", &x); x--; printf("Enter column #(1-3): "); scanf("%d", &y); y--; if(board[x][y] != ' ') { printf("Invalid move! "); } else { board[x][y] = PLAYER; break; } } while (board[x][y] != ' ');
} void computerMove() { //creates a seed based on current time srand(time(0)); int x; int y; if(checkFreeSpaces() > 0) { do { x = rand() % 3; y = rand() % 3; } while (board[x][y] != ' ');
Watching this tutorial in 2024 and absolutely enjoying learning C from you. Followed your course from the first video till the last and now i feel very confident in C language. This guy never disappoints🙌. Respect man❤❤ Keep making such insightful and useful videos
I'm just beginning to learn and followed this example. It's great, thank you. So far I've added the ability to choose whether to be X or O, who goes first, and made it alternate who goes first after each game. I'm going to work on the AI now.
Thank you for providing this information for free man, appreciate it! I am about to go into my second year as a CS major and did not know where to go after learning Java so these tutorials have been great for learning the basic syntax of another language
Thank you, awesome breakdown....One small improvement: if you add && board[i][0] != ' ' to the check rows if statement in the checkeWinner() function (and of course && board[0][j] != ' ' for columns etc) it will ensure that it doesn't prematurely return from that function if it sees that for instance the top row is still all ' ' even if you win in the bottom row. It doesn't come up that often, but it's irritating when it does, I made a 2 player version of this so I was able to force this corner case and it drove me crazy until I finally figured out how to solve it with he simple fix above.
Thank you for this. I easily altered it to make it a two player game, add an option for player names and a nice little menu. In the words of Homer SImpson "GAAHHHHGGHHH! More, please!"
Hey bro..first of all thanks a lot for all the free courses... I would like to know something, How can i prevent the player from winning? And How the computer can block the player winning move? like, if player move 2 X horizontally or vertically, how the computer can prevent player from winning? you response would be very helpful... I'm eagerly waiting for your response.
Yo Bro Code, u gotta hit us up with some videos on pointers. I appreciate all the hard work u put in here cuz it really translates to a learning experience for me and many others here.
Cant seem to get that Y /N part to work my lines are the same but it will just go straight from "Wanna play again? (Y/n): " to "Thank you for playing!!'
Correct me if I'm wrong. The checkFreespaces() function within the computerMove() function is unnecessary since the main function already contains a while loop checking for that. The printWinner(' '); statement in the computerMove() function is also pointless since the winner=checkWinner() is already doing the job in main function.
printf(" %c | %c | %c ", board[i][0], board[i][1], board[i][2]); printf("---|---|--- "); } I tried like this, but it creates 1 additional horizontal line X | X | O ---|---|--- O | X | O ---|---|--- O | X | X ---|---|---
this is for 5x5 The answer of ur question is in point 6). 1).so first of all we need to change char board and make it 5 to 5 2d matrix.(board[5][5]). 2).Change the resetBorad function. The condition will be for(int i = 0;i < 5; i++) { for(int j = 0; j < 5; j++) { board[i][j] = ' '; } } 3). Now it's time for printing our board, instead of writing the same thing 5 time, we can use nested loop like this. for(int i = 0; i < 5; i++ ) {
printf(" %c | %c | %c | %c | %c ", board[i][0], board[i][1], board[i][2], board[i][3], board[i][4]); if(i < 4) printf("---|---|---|---|--- "); } The output will be .\ | | | | ---------- first row ---|---|---|---|--- | | | | ---------- second row ---|---|---|---|--- | | | | ---------- third row ---|---|---|---|--- | | | | ---------- fourth row ---|---|---|---|--- | | | | ---------- fifth row 4). Now we need to change checkFreeSpaces() function. In the 3x3 we wrote 9 coz we have 9 free spaces, now we have 25 free spaces. int checkFreeSpaces() { int freeSpaces = 25; for(int i = 0;i < 5; i++) { for(int j = 0; j < 5; j++) { if(board[i][j] != ' ') { freeSpaces--; } } } return freeSpaces; } 5).In playerMove function we can just change printf function to printf("Enter row #(1-5): "); printf("Enter colum #(1-5): "); 6). Now let's change the checkWinner() function. In 5x5 matrix we have this struction. That is why when we r giving for example 5 rows and 5 columns with scanf function, it is decrementing with -1 wich is giving us [4][4]. [ 0][ 0 ] , [ 0 ][ 1 ], [ 0 ][ 2 ], [ 0 ][ 3 ] , [ 0 ][ 4 ] [ 1][ 0 ] , [ 1 ][ 1 ], [ 1 ][ 2 ], [ 1 ][ 3 ] , [ 1 ][ 4 ] [ 2][ 0 ] , [ 2 ][ 1 ], [ 2 ][ 2 ], [ 2 ][ 3 ] , [ 2 ][ 4 ] [ 3][ 0 ] , [ 3 ][ 1 ], [ 3 ][ 2 ], [ 3 ][ 3 ] , [ 3 ][ 4 ] [ 4][ 0 ] , [ 4 ][ 1 ], [ 4 ][ 2 ], [ 4 ][ 3 ] , [ 4 ][ 4 ] char checkWinner() { //check rows for(int i = 0 ; i < 5; i++) { if(board[i][0]== board[i][1] && board[i][0] == board[i][2] && board[i][0] == board[i][3] && board[i][0] == board[i][4]) { return board[i][0]; } } //check columns for(int i = 0 ; i < 5; i++) { if(board[0][i] == board[1][i] && board[0][i] == board[2][i] && board[0][i] == board[3][i] && board[0][i] == board[4][i]) { return board[0][i]; } } //check diagonals
if(board[0][0]== board[1][1] && board[0][0] == board[2][2] && board[0][0] == board[3][3] && board[0][0] == board[4][4]) { return board[0][0]; } if(board[0][4]== board[1][3] && board[0][4] == board[2][2] && board[0][4] == board[3][1] && board[0][4] == board[4][0]) { return board[0][4]; } return ' '; } 7).Change computerMove() function We r leaving seed the same(with time) , so that every time we will have different random numbers. Then we r generating random number with rand() function. We wrote x = rand() % 3 ; because we wanted to generate from 0 to 2. But now we need to generate from 0 to 4. So we write x = rand() % 5 ; It will now generate 0-4. if we want to increase the range we can add (+number), for example x = (rand() % 5) + 2; Now it will generate from 2 to 6. void computerMove() { srand(time(0)); int x; int y; if(checkFreeSpaces() > 0) { do { x = rand() % 5; y = rand() % 5; }while(board[x][y] != ' '); board[x][y] = COMPUTER; } else { printWinner(' '); } 8) and the final one... Enjoy and have fun with codes :)))))
I have reached the end. Thank you for the time you've given some random fellow human beings. It's more important than you know and made a big difference for this random human being. If I survive through my next few months fast track I will not forget to let you know.
Hello guys, when I type Y or N, I get an error saying: The term 'n' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + n + ~ + CategoryInfo : ObjectNotFound: (n:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException Can someone help?
@@emelieobumse4345 this video aint one of those videos where you understand everything in one sitting, its one of those videos where you follow along as a tutorial and figure things out on ur own
Of course U can. U just need to write any condition inside while loop like while(1>0) , so that it will loop infinite times. This if condition here means that it will break the loop only if board[x][y] == ' '; Otherwise it will loop because 1 is always more that 0. else { board[x][y] = PLAYER; break; } while(1>0) { printf("Enter row #(1-5): "); scanf("%d",&x); x--; printf("Enter colum #(1-5): "); scanf("%d",&y); y--; if(board[x][y] != ' ') { printf("Invalid move! "); } else { board[x][y] = PLAYER; break; } }
Im halfway through. Very nice tutorial that is helping me with my project. I had one thought though, since we (humans) are accoustumed to x moving in a in horizontal line and y moving in a vertical line, the createBoard function would should better be thus in my opinion: void printBoard(){ printf("c% | c% | c% |",board[0][0],board[1][0],board[2][0]); printf(" ...|...|... "); printf("c% | c% | c% |",board[0][1],board[1][1],board[2][1]); printf(" ...|...|... "); printf("c% | c% | c% |",board[0][2],board[1][2],board[2][2]); printf(" ...|...|... "); printf(" "); }; What do you think ? All argumentators welcome ;)
i would like to argue that we humans are more accustomed to matrices and the createBoard function in the video is more easy to understand and visualize than your version Moreover your version would print the transpose of the matrix rather than the original matrix .
@@siddhantamallick6837 the difference is irrelevant. @SuperSamsosa's code assumes column major order for the matrix (each column is stored contiguously in memory), the code in the video assumes row major order (each row is stored contiguously in memory). both of them are functionally equivalent with each other (though column major matrices are more cache-friendly when performing matrix multiplications of row vectors, and they better describe mathematical principles like basis matrices) as long as the remaining code is consistent with the ordering: most importantly, the code that assigns the player's moves to the board shouldn't be accessing the column major matrix with row major ordering.
Made mine somehow it was 356 lines 🤣☠️, I did make mine a class and my computer knows when you are about to win and stops you so it always ends in a draw or you make a mistake and the computer wins
So about the #include for stdio.h stdlib.h ctype.h andtime.h, i keep getting the red squiggly lines on the bottom saying they cant open source file, do you know how to fix that?
//This is a tic tac toe game written in C designed for beginners
//(This doesn't contain the use of pointers or other more advanced C topics)
#include
#include
#include
#include
char board[3][3];
const char PLAYER = 'X';
const char COMPUTER = 'O';
void resetBoard();
void printBoard();
int checkFreeSpaces();
void playerMove();
void computerMove();
char checkWinner();
void printWinner(char);
int main()
{
char winner = ' ';
char response = ' ';
do
{
winner = ' ';
response = ' ';
resetBoard();
while(winner == ' ' && checkFreeSpaces() != 0)
{
printBoard();
playerMove();
winner = checkWinner();
if(winner != ' ' || checkFreeSpaces() == 0)
{
break;
}
computerMove();
winner = checkWinner();
if(winner != ' ' || checkFreeSpaces() == 0)
{
break;
}
}
printBoard();
printWinner(winner);
printf("
Would you like to play again? (Y/N): ");
scanf("%c");
scanf("%c", &response);
response = toupper(response);
} while (response == 'Y');
printf("Thanks for playing!");
return 0;
}
void resetBoard()
{
for(int i = 0; i < 3; i++)
{
for(int j = 0; j < 3; j++)
{
board[i][j] = ' ';
}
}
}
void printBoard()
{
printf(" %c | %c | %c ", board[0][0], board[0][1], board[0][2]);
printf("
---|---|---
");
printf(" %c | %c | %c ", board[1][0], board[1][1], board[1][2]);
printf("
---|---|---
");
printf(" %c | %c | %c ", board[2][0], board[2][1], board[2][2]);
printf("
");
}
int checkFreeSpaces()
{
int freeSpaces = 9;
for(int i = 0; i < 3; i++)
{
for(int j = 0; j < 3; j++)
{
if(board[i][j] != ' ')
{
freeSpaces--;
}
}
}
return freeSpaces;
}
void playerMove()
{
int x;
int y;
do
{
printf("Enter row #(1-3): ");
scanf("%d", &x);
x--;
printf("Enter column #(1-3): ");
scanf("%d", &y);
y--;
if(board[x][y] != ' ')
{
printf("Invalid move!
");
}
else
{
board[x][y] = PLAYER;
break;
}
} while (board[x][y] != ' ');
}
void computerMove()
{
//creates a seed based on current time
srand(time(0));
int x;
int y;
if(checkFreeSpaces() > 0)
{
do
{
x = rand() % 3;
y = rand() % 3;
} while (board[x][y] != ' ');
board[x][y] = COMPUTER;
}
else
{
printWinner(' ');
}
}
char checkWinner()
{
//check rows
for(int i = 0; i < 3; i++)
{
if(board[i][0] == board[i][1] && board[i][0] == board[i][2])
{
return board[i][0];
}
}
//check columns
for(int i = 0; i < 3; i++)
{
if(board[0][i] == board[1][i] && board[0][i] == board[2][i])
{
return board[0][i];
}
}
//check diagonals
if(board[0][0] == board[1][1] && board[0][0] == board[2][2])
{
return board[0][0];
}
if(board[0][2] == board[1][1] && board[0][2] == board[2][0])
{
return board[0][2];
}
return ' ';
}
void printWinner(char winner)
{
if(winner == PLAYER)
{
printf("YOU WIN!");
}
else if(winner == COMPUTER)
{
printf("YOU LOSE!");
}
else{
printf("IT'S A TIE!");
}
}
damn.. this much code just for a simple game....
A lot happens inside the game while you enjoy the scene of the game.
thank you
Great work
@@chriijack101 same problem I can't replay
this is the most elaborating way of programming that invokes all the materials that you study in c programming. Thank you
Watching this tutorial in 2024 and absolutely enjoying learning C from you. Followed your course from the first video till the last and now i feel very confident in C language.
This guy never disappoints🙌.
Respect man❤❤
Keep making such insightful and useful videos
same same
From a student who's learning programming and runs out of time, thank you a lot Bro Code
Sit back relax and enjoy the show
I'm just beginning to learn and followed this example. It's great, thank you. So far I've added the ability to choose whether to be X or O, who goes first, and made it alternate who goes first after each game. I'm going to work on the AI now.
how are you doing?
Thank you for providing this information for free man, appreciate it! I am about to go into my second year as a CS major and did not know where to go after learning Java so these tutorials have been great for learning the basic syntax of another language
Евала братле. С туй си взех курсовата работа. Продължавай така, че още 7 семестъра ще трябва!
Thanks bro, nice approach for this problem
This video definitely deserves more views
Yo! Very good informative video . Btw advance congrats for 200k . U deserve more
I watched the full as so that you can earn gud money 😂😀
Same here 😅
@@hritiktheopgamer4122 wow 1 year old comment
@@smartxavier89067 muffs
@@smartxavier8906so how much r u earning now
@@smartxavier8906 same
I love you bro keep it up I am learning a lot thanks to you!!
I finished the course ❤ thanks bro
thank you! it's really helpfu to me, do more such type of mini projects🤩
hi bro I have ended this tutorial right now , and I want to start c++ tutorial . I want to say thank u for teaching fast and very good . best regards
there's no error in my code but still when i enter where i want to place my x it doesn't show me where i have placed it, the board stays empty.
Thank you, awesome breakdown....One small improvement: if you add && board[i][0] != ' ' to the check rows if statement in the checkeWinner() function (and of course && board[0][j] != ' ' for columns etc) it will ensure that it doesn't prematurely return from that function if it sees that for instance the top row is still all ' ' even if you win in the bottom row. It doesn't come up that often, but it's irritating when it does, I made a 2 player version of this so I was able to force this corner case and it drove me crazy until I finally figured out how to solve it with he simple fix above.
exactly !!
can you explain a bit more my stupid brain can't comprehend this.😅
Nice bro❤
is there any site showing all variables and operators in c, example of their usage?
Great work ...!!!!
Thank you for this. I easily altered it to make it a two player game, add an option for player names and a nice little menu. In the words of Homer SImpson "GAAHHHHGGHHH! More, please!"
hi ,a quick question: can we use else if statement when making checkwinner() condition for diagonal elements
Will add this, Flappy Brid and Snake Game in my CV after 3 years 😂.
Hey bro..first of all thanks a lot for all the free courses... I would like to know something, How can i prevent the player from winning? And How the computer can block the player winning move?
like, if player move 2 X horizontally or vertically, how the computer can prevent player from winning? you response would be very helpful... I'm eagerly waiting for your response.
"Sit back relax and enjoy the show" :) and i also finished the course, Thanks bruh
Thx bro, i’ve learn so much from you
its taking input even when we give column no as 4, which should give invalid? why is that?
Thx a lot mate
Completed Bro! Thanks for this video.
Yo Bro Code, u gotta hit us up with some videos on pointers. I appreciate all the hard work u put in here cuz it really translates to a learning experience for me and many others here.
Cant seem to get that Y /N part to work my lines are the same but it will just go straight from "Wanna play again? (Y/n): " to "Thank you for playing!!'
Correct me if I'm wrong. The checkFreespaces() function within the computerMove() function is unnecessary since the main function already contains a while loop checking for that. The printWinner(' '); statement in the computerMove() function is also pointless since the winner=checkWinner() is already doing the job in main function.
yes !!
now we just need a video on this but with the language C# :)
My first game reloaded thank you❣️ love from 🇳🇵
in line 52, why dis you is scanf("%c"), but without &response ??
To clear buffer /new line character
Completed the whole series and now I'm ready to ace my midterms
Ended the full course here 😁✊ lets gaaa
Thanks ! I modified the code to set pawn and a toss will be performed to decide who will go first
Thank You So Much Brother ❤️❤️❤️❤️❤️🔥🔥🔥🔥😍😍😍😶😘😘😘😘😘.
So great bro !
wrote my own rn it’s at nearly 400 lines imma do some optimisation and cleaning and it’s gonna drop to 350 easily
im sad to be a the end of this course :(
THANK YOU SO MUCH!
is this playlist include all of c?
yes
thank you so much!!
can you create board with nested loops instead of copy paste 3 times? appreciate the video!
I think u can only loop first two rows, the last one is different
for(int i = 0; i < 3; i++ )
{
printf(" %c | %c | %c
", board[i][0], board[i][1], board[i][2]);
printf("---|---|---
");
}
I tried like this, but it creates 1 additional horizontal line
X | X | O
---|---|---
O | X | O
---|---|---
O | X | X
---|---|---
IT's working right with additional if(i
Why no "for" loop in printBoard???
Thanks man, awesome
How would you check for winner if it was a 5x5 or 6x6 instead of 3x3 grid?
I think with same way, U just need to add more rows and columns
this is for 5x5
The answer of ur question is in point 6).
1).so first of all we need to change char board and make it 5 to 5 2d matrix.(board[5][5]).
2).Change the resetBorad function. The condition will be for(int i = 0;i < 5; i++)
{
for(int j = 0; j < 5; j++)
{
board[i][j] = ' ';
}
}
3). Now it's time for printing our board, instead of writing the same thing 5 time, we can use nested loop like this.
for(int i = 0; i < 5; i++ )
{
printf(" %c | %c | %c | %c | %c
", board[i][0], board[i][1], board[i][2], board[i][3], board[i][4]);
if(i < 4)
printf("---|---|---|---|---
");
}
The output will be .\
| | | | ---------- first row
---|---|---|---|---
| | | | ---------- second row
---|---|---|---|---
| | | | ---------- third row
---|---|---|---|---
| | | | ---------- fourth row
---|---|---|---|---
| | | | ---------- fifth row
4). Now we need to change checkFreeSpaces() function. In the 3x3 we wrote 9 coz we have 9 free spaces, now we have 25 free spaces.
int checkFreeSpaces()
{
int freeSpaces = 25;
for(int i = 0;i < 5; i++)
{
for(int j = 0; j < 5; j++)
{
if(board[i][j] != ' ')
{
freeSpaces--;
}
}
}
return freeSpaces;
}
5).In playerMove function we can just change printf function to printf("Enter row #(1-5): ");
printf("Enter colum #(1-5): ");
6). Now let's change the checkWinner() function.
In 5x5 matrix we have this struction. That is why when we r giving for example 5 rows and 5 columns with scanf function, it is decrementing with -1 wich is giving us [4][4].
[ 0][ 0 ] , [ 0 ][ 1 ], [ 0 ][ 2 ], [ 0 ][ 3 ] , [ 0 ][ 4 ]
[ 1][ 0 ] , [ 1 ][ 1 ], [ 1 ][ 2 ], [ 1 ][ 3 ] , [ 1 ][ 4 ]
[ 2][ 0 ] , [ 2 ][ 1 ], [ 2 ][ 2 ], [ 2 ][ 3 ] , [ 2 ][ 4 ]
[ 3][ 0 ] , [ 3 ][ 1 ], [ 3 ][ 2 ], [ 3 ][ 3 ] , [ 3 ][ 4 ]
[ 4][ 0 ] , [ 4 ][ 1 ], [ 4 ][ 2 ], [ 4 ][ 3 ] , [ 4 ][ 4 ]
char checkWinner()
{
//check rows
for(int i = 0 ; i < 5; i++)
{
if(board[i][0]== board[i][1] && board[i][0] == board[i][2] && board[i][0] == board[i][3] && board[i][0] == board[i][4])
{
return board[i][0];
}
}
//check columns
for(int i = 0 ; i < 5; i++)
{
if(board[0][i] == board[1][i] && board[0][i] == board[2][i] && board[0][i] == board[3][i] && board[0][i] == board[4][i])
{
return board[0][i];
}
}
//check diagonals
if(board[0][0]== board[1][1] && board[0][0] == board[2][2] && board[0][0] == board[3][3] && board[0][0] == board[4][4])
{
return board[0][0];
}
if(board[0][4]== board[1][3] && board[0][4] == board[2][2] && board[0][4] == board[3][1] && board[0][4] == board[4][0])
{
return board[0][4];
}
return ' ';
}
7).Change computerMove() function
We r leaving seed the same(with time) , so that every time we will have different random numbers.
Then we r generating random number with rand() function. We wrote
x = rand() % 3 ; because we wanted to generate from 0 to 2.
But now we need to generate from 0 to 4.
So we write x = rand() % 5 ;
It will now generate 0-4.
if we want to increase the range we can add (+number), for example
x = (rand() % 5) + 2;
Now it will generate from 2 to 6.
void computerMove()
{
srand(time(0));
int x;
int y;
if(checkFreeSpaces() > 0)
{
do
{
x = rand() % 5;
y = rand() % 5;
}while(board[x][y] != ' ');
board[x][y] = COMPUTER;
}
else
{
printWinner(' ');
}
8) and the final one... Enjoy and have fun with codes :)))))
thank u so much!!!!!!
I have reached the end. Thank you for the time you've given some random fellow human beings. It's more important than you know and made a big difference for this random human being. If I survive through my next few months fast track I will not forget to let you know.
did you survive bro?
Hello guys, when I type Y or N, I get an error saying:
The term 'n' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is
correct and try again.
At line:1 char:1
+ n
+ ~
+ CategoryInfo : ObjectNotFound: (n:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Can someone help?
Me too
I don't understand how I managed to follow one for one with the video, understand it, and yet the program fails to run lmao
would it be a problem if after watching this, i cant do it on my own without watching the video? :(
thats like asking if you cant take the term exam after attending a single lecture
@@unrealgalaxy9669 there are so many processes lol that’s why
@@emelieobumse4345 this video aint one of those videos where you understand everything in one sitting, its one of those videos where you follow along as a tutorial and figure things out on ur own
How can I make user input the number for the grid(nxn), e.g: 5x5 or 6x6
best guy on the internet
TY very helpful
For determining the win condition, how would you go about doing it through a Switch statement?
dont
could you do this for c# program?
use the same approch, yu have now the logic and you only need the syntax. go for it and try it yourself
Thank you
I have a question. Can you use while-loop instead d0-while-loop in function playerMove?
Of course U can. U just need to write any condition inside while loop like while(1>0) , so that it will loop infinite times.
This if condition here means that it
will break the loop only if board[x][y] == ' ';
Otherwise it will loop because 1 is always more that 0.
else
{
board[x][y] = PLAYER;
break;
}
while(1>0)
{
printf("Enter row #(1-5): ");
scanf("%d",&x);
x--;
printf("Enter colum #(1-5): ");
scanf("%d",&y);
y--;
if(board[x][y] != ' ')
{
printf("Invalid move!
");
}
else
{
board[x][y] = PLAYER;
break;
}
}
This Code is so Useful
Hey there, I'm getting the 'It's a tie" message at the start of running the code. Does anyone know why that may be?
did u copy the code that he commented? or use chatgpt
you are a beautiful human
That's some heavy stuff for beginner
i finished the course lesgggoooooooo
thanks
I guess you are preparing a c full tutorial
cool
I will came back again, its kinda to hard for me 😢😂
13:51
Cool.
in c++ how would it be : printf("
Would you like to play again? (Y/N): ");
scanf("%c");
scanf("%c", &response);
U can use standard method Cout & Cin. I think there wouldn't be any problem.
coutresponse;
how to make bot for level expert?
Can anyone make a algorithm flowchart for this code??
Im halfway through. Very nice tutorial that is helping me with my project.
I had one thought though, since we (humans) are accoustumed to x moving in a in horizontal line and y moving in a vertical line, the createBoard function would should better be thus in my opinion:
void printBoard(){
printf("c% | c% | c% |",board[0][0],board[1][0],board[2][0]);
printf("
...|...|...
");
printf("c% | c% | c% |",board[0][1],board[1][1],board[2][1]);
printf("
...|...|...
");
printf("c% | c% | c% |",board[0][2],board[1][2],board[2][2]);
printf("
...|...|...
");
printf("
");
};
What do you think ? All argumentators welcome ;)
This is so confusing… I don’t think that’s how matrices work
i would like to argue that we humans are more accustomed to matrices and the createBoard function in the video is more easy to understand and visualize than your version
Moreover your version would print the transpose of the matrix rather than the original matrix .
@@siddhantamallick6837 the difference is irrelevant. @SuperSamsosa's code assumes column major order for the matrix (each column is stored contiguously in memory), the code in the video assumes row major order (each row is stored contiguously in memory). both of them are functionally equivalent with each other (though column major matrices are more cache-friendly when performing matrix multiplications of row vectors, and they better describe mathematical principles like basis matrices) as long as the remaining code is consistent with the ordering: most importantly, the code that assigns the player's moves to the board shouldn't be accessing the column major matrix with row major ordering.
is it possible to make a 9x9 grid , meaning, making a ultimate tic tac toe until this sunday and give the code? I need it fast
just expand the grid from this tutorial maybe? and do minor adjustments yourself
@@banglawarlock3947 ok shut up
Which engine u used?
Unreal Engine 5
Made mine somehow it was 356 lines 🤣☠️, I did make mine a class and my computer knows when you are about to win and stops you so it always ends in a draw or you make a mistake and the computer wins
i finished the course
class
we love you
How do people know such things, good Lord.
The code justs get stuck at running for me, Can anyone help?
Whats the error?
I need to add return but i see he didn't so idk
Dzieki za pomoc
printf("Thanks a lot buddy");
Finally done :D
uuu this is the last episode
And then, what next...?
okay
Comments 😅
comment.
"comment"
Like();
Comment
So about the #include for stdio.h stdlib.h ctype.h andtime.h, i keep getting the red squiggly lines on the bottom saying they cant open source file, do you know how to fix that?
same, i cant use any library in VS code
How contact you
I want to add difficulties. I don’t know how to do that. 🥲
good tuto though!