Tic-Tac-Toe

Tic-Tac-Toe

·

2 min read

Day 1: 25 October 2023

What I did:

  • planned out the project

  • started the project after laying down the structure

  • completed loops for gameplay

Problems faced + solution:

  • program terminated right away after the first input despite being in a loop.

    • still not sure of what happened, but the problem was fixed after downloading the file from VS live server.
  • turns were messed up, with player 1 appearing in turn 4 (skipping player 2's turn)

  • when the above problem was fixed, realised that 'O's and 'X's were opposite (Player 1 was supposed to be O but became X and vice versa)

    • realised that this was due to the bad placement of turn++(was before the change in grids and checking of win condition took place).

    • Fixed after moving turn++ to the end of the code (right before the start of the new turn)

//ORIGINAL (PROBLEMATIC CODE)
//turns
if(turn % 2 != 0){
    std::cout << "Player 1's turn.";
    std::cout << "You are O\n\n";
    turn++;
}
else {
    std::cout << "Player 2's turn.";
    std::cout << "You are X\n\n";
    turn++;
}
  • Loops ended and "player __ wins!" is displayed prematurely even when win conditions were not fulfilled.

    • This was due to the if/else statements.

    • Original: if ((player2[i] == '1','2','3') |...)

    • Edited1: if ((player2[i] == '1' && '2' && '3') | ... )

    • Edited2:if ((player2[i] == '1' && player2[i] == '2' && player2[i] == '3') | ... )

Things to work on:

  • Figure out why win condition + cout "player __ wins!" is not working anymore, even after fulfilling win conditions.

  • How to reject duplicate input, currently duplicate = overwrite pre-existing X/O

  • Making the code easier to read using functions and templates...