C++ TIC TAC TOE game for beginners ⭕

  Рет қаралды 37,203

Bro Code

Bro Code

Күн бұрын

Пікірлер: 70
@BroCodez
@BroCodez 2 жыл бұрын
#include #include void drawBoard(char *spaces); void playerMove(char *spaces, char player); void computerMove(char *spaces, char computer); bool checkWinner(char *spaces, char player, char computer); bool checkTie(char *spaces); int main() { char spaces[9] = {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}; char player = 'X'; char computer = 'O'; bool running = true; drawBoard(spaces); while(running){ playerMove(spaces, player); drawBoard(spaces); if(checkWinner(spaces, player, computer)){ running = false; break; } else if(checkTie(spaces)){ running = false; break; } computerMove(spaces, computer); drawBoard(spaces); if(checkWinner(spaces, player, computer)){ running = false; break; } else if(checkTie(spaces)){ running = false; break; } } std::cout
@k7nai
@k7nai 2 жыл бұрын
Hey 😳
@CầnbiếtKo-k5i
@CầnbiếtKo-k5i Жыл бұрын
bạn cần thêm dòng thư viện này nữa:#include
@ayushrai1705
@ayushrai1705 Жыл бұрын
what happens if the random function in computer moves picks a already filled space?
@shinayang-um7mk
@shinayang-um7mk 9 ай бұрын
1:51
@SalKulti
@SalKulti 5 ай бұрын
Why was !number used instead of just the norma, number 0?
@andarling9742
@andarling9742 Жыл бұрын
u could check winner by creating an an array of playermoves and check if there are 3 numbers that when num1 - num2 = num2 - num3 && num1-num2
@narayanswamyghanta315
@narayanswamyghanta315 Жыл бұрын
Looking at this game code, I understood that i lack in algorthimic thinking.
@zeelfarshmek111
@zeelfarshmek111 Ай бұрын
same :/ i read and re reread the code and i understand what does what but ask me to remake the code from scratch and il draw a blank :(
@minkhantsaw0428
@minkhantsaw0428 2 күн бұрын
Use 2d array instead.
@siddharthjain6629
@siddharthjain6629 Ай бұрын
You are amazing Bro !!!! My concepts regarding the programming languages are getting good day by day. Thank you for sharing such amazing content
@DawoodRizwan-k7f
@DawoodRizwan-k7f 4 ай бұрын
so good bro...
@guillermofrancella08
@guillermofrancella08 7 ай бұрын
Bro is back with the Code. Love you man.
@conornorris8014
@conornorris8014 Ай бұрын
And why no for loop for grid creation?
@RaviYadav-wm7tp
@RaviYadav-wm7tp 3 ай бұрын
30 mins in half way there, yet to create the winning criteria this was really helpful
@ra2dsla7
@ra2dsla7 2 жыл бұрын
could u please explain the condition in details (!number > 0 || !number < 8)?
@shintiao1732
@shintiao1732 2 жыл бұрын
@koji is not the same, you try input the same number in player and you will know that.
@ali_gd_0161
@ali_gd_0161 Жыл бұрын
Think of it as ( !(number >0) || !(number < 8) The ! Operator changes the boolean value of the condition in front of it. E.g if it's true it becomes false
@nicko4140
@nicko4140 Жыл бұрын
@@ali_gd_0161 im confused how it loops after you select a non empty space. is the !number>0 || !number
@hupmitom5509
@hupmitom5509 Жыл бұрын
number = 1 the logic is the same. I think it is easier to understand.
@BroDevsRBLX
@BroDevsRBLX Жыл бұрын
It just means as long as the number is 8 the loop will execute@@Kak-koi
@FrederikWollert
@FrederikWollert 8 ай бұрын
Good Video Bro.
@havocblast
@havocblast 6 ай бұрын
I ended up taking this idea an started working on a terminal submarine hunting game where you are trying to sink a submarine that is hiding/moving around under the water. I do need to figure out how to make drawing the board faster since I am using colors to print a grid of blue spaces in the terminal for the water. Board is currently 40 by 80. Thanks for bringing me down that rabbit hole lol
@conornorris8014
@conornorris8014 Ай бұрын
I'm learning Cpp can someone explain why the functions are written inside the main function and not above for modulation? My tutor did the same thing but it doesn't make sense to me.
@firestickman4605
@firestickman4605 3 ай бұрын
thank you so much!
@shintiao1732
@shintiao1732 2 жыл бұрын
if we never use the "char computer" in cheakWinner function ,why need to import this parameter?
@anvrag
@anvrag Жыл бұрын
for fun..
@kshitijsrivastava8312
@kshitijsrivastava8312 Жыл бұрын
For me its showing an exception report after performing the code, telling its a bug.
@ShadowLogic3253
@ShadowLogic3253 5 ай бұрын
you said originally you would have used switch statements but I thought they could only be used with ints
@baconheadhair6938
@baconheadhair6938 2 ай бұрын
They can be used with singlr digit things like ints and chars but not for things like strings
@HunaBopa
@HunaBopa Жыл бұрын
Bro, I have a question for you. Look, we did implement the minimax algorithm in Python and create an AI Tic Tac Toe player that is invincible. However, in C++ it's a daunting task for me. Can you help me implement the minimax algorithm in C++?
@baconheadhair6938
@baconheadhair6938 2 ай бұрын
i am the one who is invincible
@VuQuangVinhA-zr6vv
@VuQuangVinhA-zr6vv 15 күн бұрын
Have you coded it yet?
@novaldwiputra5816
@novaldwiputra5816 Ай бұрын
bro, how to fix this problem? If I fill in X in the same place, but the computer still chooses the place randomly :(
@phamduy6013
@phamduy6013 Ай бұрын
I thought when you pass array to a function you have to include the size, why can you not pass the size in this example and it's still work?
@phamduy6013
@phamduy6013 Ай бұрын
I'm a beginner, just explain to me
@Sam-gv9tv
@Sam-gv9tv Ай бұрын
because you are passing in the pointer in this case
@phamduy6013
@phamduy6013 Ай бұрын
@@Sam-gv9tv thanks, but can you give me a clearer explanation?
@yesyes628
@yesyes628 8 күн бұрын
i think its because we already know the board will be size 9 so we dont need to calculate it
@Sam-gv9tv
@Sam-gv9tv 8 күн бұрын
@@phamduy6013 when you pass an array inside a function normally, which means pass by value you HAVE TO include the size. When we are talking about pointers, since pointers and arrays are somehow interconnected, when u pass a pointer it always points to the first element of the array. In fact if you derefrence the pointer u will see it points to the first element, try adding +1, +2 to the derefrenced pointer and u will see it will point to the next members. So +1 means it will point to the second member etc. so this is usefull to know how you loop through an array using pointers, u derefrnece it and add “i” which increments so for example: cout
@gamsterilyass2952
@gamsterilyass2952 6 ай бұрын
Assembly ?
@zeelfarshmek111
@zeelfarshmek111 Ай бұрын
i had a strange error happen...i tied on the last move with my last move being on the 6th block and it came out with "its a tie" but i double checked the code and its not possible. Tried to replicate it but it did not happen again. Otherwise i understood this code perfectly after checking out what does what ...strangely tho even tho i know all this i doubt i could replicate it from scratch : / so strange that i can understand but doubt i can remake it without help.
@quartzisgames1496
@quartzisgames1496 21 күн бұрын
I'm guessing you mean you won on the last turn. It's because checkTie() doesn't check if there is a winner. Basically, no matter how the grid is filled, if it's filled it considers it's a tie. What you could do if that bothers you is using checkTie() inside of checkWinner(), so you can first determine if there's a winner, and then if there is no winner check for a tie. It should work :)
@jessechen2132
@jessechen2132 Жыл бұрын
When a user enters a letter rather than a number, the program crashes. Do you know how to solve it?
@anvrag
@anvrag Жыл бұрын
std::cin.clear(); fflush(stdin); use this two lines of powerful code which will help u to prevent crashes (use it below the input)
@FlorrioEggGaming
@FlorrioEggGaming Жыл бұрын
@@anvrag truly powerful code
@Toothless_Rides
@Toothless_Rides 10 ай бұрын
@@anvrag how? when I coded this in, it became an infinite loop...
@NovaStargazer23
@NovaStargazer23 3 ай бұрын
​@@Toothless_Rides Fflush(stdin) not work for linux Use while(cin.get() != ' ') { continue; }
@baconheadhair6938
@baconheadhair6938 2 ай бұрын
@@Toothless_Ridesyou could also make it accept a char value insteas and then just use isdigit() to make sure its a number and stoi() to convert it to an int
@triculex2854
@triculex2854 4 ай бұрын
while(!num>0 || !num
@diosinvicto
@diosinvicto 3 ай бұрын
I hate a double negation😂😂.... But this one's better while(number < 0 || number > 8)
@baconheadhair6938
@baconheadhair6938 2 ай бұрын
@@diosinvictoThat isnt a double negation, its just two negations. A double negation is negating a negation. Your code also isn’t „better“. It quite literally does the exact same thing
@charlo-d2
@charlo-d2 3 ай бұрын
Cannot be done in CodeBlocks?
@lalkad8561
@lalkad8561 Жыл бұрын
#include #include void drawBoard(char *spaces); void playerMove(char *spaces, char player); void computerMove(char *spaces, char computer); bool checkWinner(char *spaces, char player, char computer); bool checkTie(char *spaces); int main(){ char spaces[9] = {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}; char player = 'X'; char computer = 'O'; bool running = true; drawBoard(spaces); while(running){ playerMove(spaces, player); drawBoard(spaces); if(checkWinner(spaces, player, computer)){ running = false; break; } else if(checkTie(spaces)){ running = false; break; } computerMove(spaces, computer); drawBoard(spaces); if(checkWinner(spaces, player, computer)){ running = false; break; } else if(checkTie(spaces)){ running = false; break; } } std::cout
@Toothless_Rides
@Toothless_Rides 10 ай бұрын
why??? This was pointless😂
C++ dynamic memory explained for beginners 🧠
5:49
Bro Code
Рет қаралды 19 М.
C Tic Tac Toe game ⭕
20:08
Bro Code
Рет қаралды 178 М.
C++ ROCK PAPER SCISSORS game for beginners 👊
13:07
Bro Code
Рет қаралды 14 М.
you will never ask about pointers again after watching this video
8:03
Making a Game in Python with No Experience
5:57
Goodgis
Рет қаралды 1,8 МЛН
Learning C++ by making a Game... in 1 Week?!
10:14
Floky
Рет қаралды 628 М.
Tic Tac Toe Game in C++
20:20
Kenny Yip Coding
Рет қаралды 14 М.
10 Math Concepts for Programmers
9:32
Fireship
Рет қаралды 2 МЛН
The Dome Paradox: A Loophole in Newton's Laws
22:59
Up and Atom
Рет қаралды 1,1 МЛН
C++ QUIZ GAME for beginners 💯
11:46
Bro Code
Рет қаралды 10 М.
🪄Вечная спичка #diy #выживание #поход
1:00
Короче, ВИ
Рет қаралды 2,8 МЛН
НЕ ДАМ ЕЁ В ОБИДУ😡 #shorts
0:24
Паша Осадчий
Рет қаралды 1,6 МЛН