rifunziona pt 30000

This commit is contained in:
Lorenzo Bianchi 2023-06-01 14:39:04 +02:00
parent cab69abfea
commit c051085e4a
4 changed files with 16 additions and 16 deletions

View File

@ -6,6 +6,4 @@
- messaggio speciale per abbandono
- se le ipcs non si sono chiuse bene non funzia
- fa errore quando un giocatore abbandona
- se le ipcs non si sono chiuse bene non funzia

View File

@ -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);

View File

@ -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);
}
}

View File

@ -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) {