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++?
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
#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
Hey 😳
bạn cần thêm dòng thư viện này nữa:#include
what happens if the random function in computer moves picks a already filled space?
1:51
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
Bro is back with the Code. Love you man.
Good Video Bro.
Looking at this game code, I understood that i lack in algorthimic thinking.
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++?
For me its showing an exception report after performing the code,
telling its a bug.
could u please explain the condition in details (!number > 0 || !number < 8)?
@koji is not the same, you try input the same number in player and you will know that.
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
@@ali_gd_0161 im confused how it loops after you select a non empty space. is the !number>0 || !number
number = 1 the logic is the same. I think it is easier to understand.
It just means as long as the number is 8 the loop will execute@@Kak-koi
if we never use the "char computer" in cheakWinner function ,why need to import this parameter?
for fun..
When a user enters a letter rather than a number, the program crashes. Do you know how to solve it?
std::cin.clear();
fflush(stdin);
use this two lines of powerful code which will help u to prevent crashes (use it below the input)
@@anvrag truly powerful code
@@anvrag how? when I coded this in, it became an infinite loop...
Assembly ?
#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
why??? This was pointless😂