From 573ae23c48ffbbc7b0a9d9c7381444ff52468108 Mon Sep 17 00:00:00 2001 From: ninya9k <> Date: Wed, 15 Nov 2023 08:04:45 +0000 Subject: [PATCH 1/3] send board over socket --- uttt.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/uttt.c b/uttt.c index f4d6574..dcfab38 100644 --- a/uttt.c +++ b/uttt.c @@ -264,7 +264,7 @@ void ut_sockdraw(const struct ut_state *state, int fd) } } -/*void ut_show(const struct ut_state *state, int fd, bool as_comment) { +void ut_show(const struct ut_state *state, int fd) { #define tiles state->tiles ut_dprintf(fd, "%sTurn: %c\n%sPlay board: %d\n", as_comment ? "| " : "", (int)state->player, as_comment ? "| " : "", state->playBoard); int play_board_row = -1; @@ -273,13 +273,13 @@ void ut_sockdraw(const struct ut_state *state, int fd) play_board_row = state->playBoard / 3; play_board_col = state->playBoard % 3; } - ut_dprintf(fd, "%s 012 345 678\n", as_comment ? "| " : ""); + ut_dprintf(fd, " 012 345 678\n"); for(int y = 0; y < 9; y++) { if (y == 3 || y == 6) { - ut_dprintf(fd, "%s ---+---+---\n", as_comment ? "| " : ""); + ut_dprintf(fd, " ---+---+---\n"); } - ut_dprintf(fd, "%s%d ", as_comment ? "| " : "", y); + ut_dprintf(fd, "%d ", y); for(int x = 0; x < 9; x++) { if (x == 3 || x == 6) { @@ -293,9 +293,9 @@ void ut_sockdraw(const struct ut_state *state, int fd) ut_writefill(fd, "\n", 1); } if (play_board_col == -1) { - ut_dprintf(fd, "%s ^^^ ^^^ ^^^", as_comment ? "| " : ""); + ut_dprintf(fd, " ^^^ ^^^ ^^^"); } else { - ut_dprintf(fd, "%s ", as_comment ? "| " : ""); + ut_dprintf(fd, " "); for (int i = 0; i < play_board_col; i++) { ut_dprintf(fd, " "); } @@ -531,7 +531,7 @@ int ut_network_game(struct ut_state *state, int sock, char player, bool readable while (true) { //ut_show(state, 1, false); //ut_show_boards(state); - //ut_show(state, sock, true); + ut_show(state, sock); if (state->player == player) { if (readable) {ut_dprintf(sock, "Waiting for game partner ...\n");} bool ok = ut_cursgetpos(state, &x, &y); From 771b1e9ba802f27b70344d4ba84bdd08a7b87c0c Mon Sep 17 00:00:00 2001 From: ninya9k <> Date: Wed, 15 Nov 2023 08:05:54 +0000 Subject: [PATCH 2/3] readable socket niceties --- uttt.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/uttt.c b/uttt.c index dcfab38..4f85c9a 100644 --- a/uttt.c +++ b/uttt.c @@ -41,6 +41,12 @@ const char arg_local[] = "--local"; const char arg_host[] = "--host"; const char arg_join[] = "--join"; +const char PLAY_BOARDS[][14] = { + "top left", "top middle", "top right", + "middle left", "middle", "middle right", + "bottom left", "bottom middle", "bottom right", + "all boards", +}; char ut_turn(char player) { @@ -266,7 +272,7 @@ void ut_sockdraw(const struct ut_state *state, int fd) void ut_show(const struct ut_state *state, int fd) { #define tiles state->tiles - ut_dprintf(fd, "%sTurn: %c\n%sPlay board: %d\n", as_comment ? "| " : "", (int)state->player, as_comment ? "| " : "", state->playBoard); + ut_dprintf(fd, "Turn: %c\nPlay board: %s\n", (int)state->player, PLAY_BOARDS[(state->playBoard + 10) % 10]); int play_board_row = -1; int play_board_col = -1; if (state->playBoard != -1) { @@ -613,9 +619,6 @@ int ut_host_game(struct ut_state *state) { char player; if ((player = ut_random_player()) < 0) {return 1;} - // tell partner X or O - ut_dprintf(conn, "%c\n", ut_turn(player)); - // check to determine readable char byte; ut_dprintf(conn, "| Press enter to start: "); @@ -635,6 +638,12 @@ int ut_host_game(struct ut_state *state) { } } + // tell partner X or O + ut_dprintf(conn, "%c\n", ut_turn(player)); + if (readable) { + ut_dprintf(conn, "You play as: %c\n\n", ut_turn(player)); + } + return ut_network_game(state, conn, player, readable); } From a98459b46e5dd6be264152c76c6af1df5745a2ff Mon Sep 17 00:00:00 2001 From: ninya9k <> Date: Wed, 15 Nov 2023 08:09:16 +0000 Subject: [PATCH 3/3] lol --- uttt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uttt.c b/uttt.c index 7b761a5..c5d3bb8 100644 --- a/uttt.c +++ b/uttt.c @@ -310,7 +310,7 @@ void ut_show(const struct ut_state *state, int fd) { } ut_writefill(fd, "\n", 1); #undef tiles -}*/ +} /*void ut_show_boards(const struct ut_state *state) { for (int j = 0; j < 3; j++) {