diff --git a/TODO.txt b/TODO.txt index f4912cc..7eb1bef 100644 --- a/TODO.txt +++ b/TODO.txt @@ -6,6 +6,4 @@ - messaggio speciale per abbandono -- se le ipcs non si sono chiuse bene non funzia - -- fa errore quando un giocatore abbandona \ No newline at end of file +- se le ipcs non si sono chiuse bene non funzia \ No newline at end of file diff --git a/src/F4Server.c b/src/F4Server.c index 857cc02..283d062 100644 --- a/src/F4Server.c +++ b/src/F4Server.c @@ -62,10 +62,13 @@ int main(int argc, char *argv[]){ int turns_left = _INPUT_S.rows * _INPUT_S.collums; int turn = 0; - tile_t result; + tile_t result = -1; move_t move; do { + //FIXME: tmp + printf("result: %d\n", result); + // apro semaforo al player di turno semOp(_SEMID, turn, 1); @@ -86,13 +89,12 @@ int main(int argc, char *argv[]){ // next turn turn ^= 1; - } while (--turns_left && !(result = checkWin(move.move))); + } while (--turns_left && (result = checkWin(move.move)) == -1); printf("result: %d\n", result); - if (!result) { + if (result == -1) { printf(PSERVER "Game ended in a draw\n"); - } else { printf(PSERVER "%s won\n", name[result]); } @@ -102,7 +104,7 @@ int main(int argc, char *argv[]){ sndGame_end(&game_end); printf("%d %d\n", _PIDS[0], _PIDS[1]); - + kill(_PIDS[0], SIGUSR1); kill(_PIDS[1], SIGUSR1); diff --git a/src/custom_sig.c b/src/custom_sig.c index e08190c..93a842b 100644 --- a/src/custom_sig.c +++ b/src/custom_sig.c @@ -47,8 +47,6 @@ void sigHandlerServer(int sig) { kill(_PIDS[0], SIGUSR1); //FIXME: fare una funzione per queste robe perche anche gia scritta a fine F4Server kill(_PIDS[1], SIGUSR1); - - printf("adesso vi chiudo\n"); raise(SIGTERM); } @@ -159,9 +157,11 @@ void sigHandlerClient(int sig) { printBoard(); if (winner.winner == ID) { printf("YOU WON!!!\n"); - } else { + } else if (winner.winner == -1) { printf("YOU LOST!!!\n"); } + + raise(SIGTERM); } } diff --git a/src/forza4.c b/src/forza4.c index c144c2c..8152748 100644 --- a/src/forza4.c +++ b/src/forza4.c @@ -53,7 +53,7 @@ int checkLine(int pos, int delta) { } // checks _BOARD for a win -// returns player tile_t on win, otherwise 0 +// returns player id on win, otherwise -1 int checkWin(int pos) { int result = checkLine(pos, ORIZONTAL); if (result) { @@ -75,7 +75,7 @@ int checkWin(int pos) { return _BOARD[pos] - 1; } - return 0; + return -1; } int checkWinAll(){ @@ -114,10 +114,10 @@ void printTile(tile_t t) { printf(" "); break; case PLAYER1: - printf("\033[91m%c\033[39m", _TOKEN1); + printf("\033[94m%c\033[39m", _TOKEN1); break; case PLAYER2: - printf("\033[94m%c\033[39m", _TOKEN2); + printf("\033[91m%c\033[39m", _TOKEN2); break; } } @@ -150,7 +150,7 @@ int checkMove(int collums) { void insertMove(int pos, int turn) { printf("playing %d in %d\n", (turn == 0) ? PLAYER1 : PLAYER2, pos); - _BOARD[pos] = (turn == 0) ? PLAYER2 : PLAYER1; + _BOARD[pos] = (turn == 0) ? PLAYER1 : PLAYER2; } int isValid(int pos) {