コミットを比較

...

3 コミット

作成者 SHA1 メッセージ 日付
ninya9k 194825db5a Merge remote-tracking branch 'origin/cleaner' into cleaner 2023-11-15 08:07:35 +00:00
ninya9k 771b1e9ba8 readable socket niceties 2023-11-15 08:05:54 +00:00
ninya9k 573ae23c48 send board over socket 2023-11-15 08:04:45 +00:00
1個のファイルの変更20行の追加11行の削除

31
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)
{
@ -265,22 +271,22 @@ 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);
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) {
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) {
@ -294,9 +300,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, " ");
}
@ -533,7 +539,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);
@ -615,9 +621,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: ");
@ -637,6 +640,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);
}