It’s readable with the name free_space, without worrying too much about how it actually makes that determination, right? So I broke the test out into another function so as not to clutter the code. It doesn’t matter which player is moving only unoccupied squares are available. Your test allowed a player to skip a turn by playing on a square he already had. void player (const char Mark, char* board) Since “player 1” and “player 2” are not very descriptive anyway, I’ll use the X and O for the prompt, too. The functions are identical except for one data item!! Don’t Do That! Factor out the thing that changed and make it a parameter. Player1 and player2 have the same parameter issue. The body is very repetitive! Use a loop and don’t repeat code en masse. You should have made it const char* since the function does not modify the data. Then this can be a member function that doesn’t need a parameter. Generally, don’t pass a pointer to a sequence like this, whether length is passed separately or implicitly known. You realize that this is actually (char* board) because arrays are not passed to functions. If(board = 'X' || board = 'X' || board = 'X')Ĭhar board = ((board = board) & (board = board)))Ĭout << "\nGAME OVER!! Player 1 won!\n" Ĭout << "\nGAME OVER!! Player 2 won!\n" If( ((board = board) & (board = board)) || How can I can make it better ? I will be making a new version that plays tic-tac-toe against a computer later. My code can play the tic-tac-toe game with two human players.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |