C++ TIC TAC TOE game for beginners ⭕

Поділитися
Вставка

КОМЕНТАРІ • 32

  • @BroCodez
    @BroCodez  2 роки тому +25

    #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 😳

    • @user-wz9fo1eg1q
      @user-wz9fo1eg1q Рік тому

      bạn cần thêm dòng thư viện này nữa:#include

    • @ayushrai1705
      @ayushrai1705 11 місяців тому

      what happens if the random function in computer moves picks a already filled space?

    • @shinayang-um7mk
      @shinayang-um7mk 2 місяці тому +1

      1:51

  • @andarling9742
    @andarling9742 Рік тому +1

    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

  • @guillermofrancella08
    @guillermofrancella08 Місяць тому

    Bro is back with the Code. Love you man.

  • @havocblast8737
    @havocblast8737 56 хвилин тому

    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

  • @FrederikWollert
    @FrederikWollert 2 місяці тому

    Good Video Bro.

  • @narayanswamyghanta315
    @narayanswamyghanta315 8 місяців тому +3

    Looking at this game code, I understood that i lack in algorthimic thinking.

  • @user-xk7de1jw8g
    @user-xk7de1jw8g 8 місяців тому

    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++?

  • @kshitijsrivastava8312
    @kshitijsrivastava8312 10 місяців тому

    For me its showing an exception report after performing the code,
    telling its a bug.

  • @ra2dsla7
    @ra2dsla7 Рік тому +9

    could u please explain the condition in details (!number > 0 || !number < 8)?

    • @shintiao1732
      @shintiao1732 Рік тому

      @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 11 місяців тому

      number = 1 the logic is the same. I think it is easier to understand.

    • @PKisBetter
      @PKisBetter 7 місяців тому +1

      It just means as long as the number is 8 the loop will execute@@Kak-koi

  • @shintiao1732
    @shintiao1732 Рік тому +1

    if we never use the "char computer" in cheakWinner function ,why need to import this parameter?

  • @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 11 місяців тому

      @@anvrag truly powerful code

    • @Haptic_Drift
      @Haptic_Drift 4 місяці тому

      @@anvrag how? when I coded this in, it became an infinite loop...

  • @gamsterilyass2952
    @gamsterilyass2952 13 днів тому

    Assembly ?

  • @lalkad8561
    @lalkad8561 Рік тому +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

    • @Haptic_Drift
      @Haptic_Drift 4 місяці тому

      why??? This was pointless😂