lazy but works

このコミットが含まれているのは:
ninya9k 2023-11-12 15:42:24 +00:00
コミット 1b427181a2
1個のファイルの変更14行の追加4行の削除

18
uttt.c
ファイルの表示

@ -186,7 +186,17 @@ bool getpos(const struct ut_state *state, int *x, int *y) {
}
bool getpos_net(const struct ut_state *state, int conn, int *x, int *y) {
//recv(conn, )
char buf[4];
int n = recv(conn, &buf, 4, 0); // lazy way but idc
printf("bytes received: %d\n", n);
printf("buf=%s\n", buf);
*x = buf[0] - 0x30;
*y = buf[2] - 0x30;
printf("x=%d y=%d\n", *x, *y);
if (buf[1] != ',' || buf[3] != '\n' || *x >= 9 || *y >= 9 || *x < 0 || *y < 0) {
printf("protocol not followed perfectly by partner - exiting\n");
exit(1);
}
}
void finish(int sig)
@ -230,12 +240,12 @@ void ut_host_game(struct ut_state *state, int conn, char host_player) {
if (state->player == host_player) {
bool ok = getpos(state, &x, &y);
if (!ok) {continue;}
int err = ut_move(state, state, x, y);
if (err) {continue;}
} else {
printf("Waiting for game parter ...");
printf("Waiting for game parter ...\n");
getpos_net(state, conn, &x, &y);
}
int err = ut_move(state, state, x, y);
if (err) {continue;}
char w = ut_winner((char *)state->boards, 0, 3);
if(w)
{