C++ TIC TAC TOE game for beginners ⭕

Поделиться
HTML-код
  • Опубликовано: 18 май 2024
  • A C++ game of tic tac toe for beginners project tutorial example explained
    #TIC #TAC #TOE
  • НаукаНаука

Комментарии • 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.

  • @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?

    • @anvrag
      @anvrag Год назад

      for fun..

  • @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😂