tictactoe

Tic Tac Toe on the terminal using ANSI Escape Codes
Index Commits Files Refs README LICENSE
commit 77c7c30cf95c38f360abba313b0fc50a1332e989
parent 03cc736119b9635199351baa506e4f01fe60fe3c
Author: mjkloeckner <martin.cachari@gmail.com>
Date:   Sat, 27 Apr 2024 21:39:35 -0300

remove `player_won` variable

since now we count `player_t` from `1` we don't need to store the value
of the player who won the match in a variable, we can do bitwise
operator on the current player to flip the player (we need to flip the
player bacause when we do the check for `WIN` status the user is already
the next to move)

Diffstat:
Mtictactoe.cpp | 5+----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/tictactoe.cpp b/tictactoe.cpp
@@ -62,7 +62,6 @@ void game_clear_board(void) {
 }
 
 void game_player_status_msg(void) {
-    unsigned int player_won;
     key_string.assign("\033[0J");
 
     switch(game_status) {
@@ -72,10 +71,8 @@ void game_player_status_msg(void) {
         player_status += "\033[0J";
         break;
     case WIN:
-        player_won = ((current_player == PLAYER_1) ? PLAYER_2 : PLAYER_1);
-        current_player_string << player_won+1;
-        player_status += current_player_string.str();
         player_status.assign("Player ");
+        player_status += (std::ostringstream() << (current_player^3)).str();
         player_status += " Wins";
         key_string.assign("Press `r` to restart\033[0J");
         game_status = HALT;