#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include int main(int argc, char *argv[]){ printf("Il mio pid per killarmi: %d\n", getpid()); //FIXME: TMP setupServer(argc, argv); // aperta semaforo per connessione dei due client printf(PSERVER "Waiting for players...\n"); semOp(_SEMID, CLIENT0, 1); semOp(_SEMID, CLIENT1, 1); player_ds player; char name[2][MAX_NAME]; // aspetto PRIMO client //FIXME: codice duplicato semOp(_SEMID, SERVER, -1); // ricevo nome primo client rcvPlayer(&player); strcpy(name[player.id], player.name_player); _PIDS[player.id] = player.pid; printf(PSERVER "Player %s connected\n", name[player.id]); // aspetto SECONDO client semOp(_SEMID, SERVER, -1); // ricevo nome secondo client rcvPlayer(&player); strcpy(name[player.id], player.name_player); _PIDS[player.id] = player.pid; printf(PSERVER "Player %s connected\n", name[player.id]); // avvisto inizio partita semOp(_SEMID, CLIENT0, 1); semOp(_SEMID, CLIENT1, 1); // PARTITA printf(PSERVER "Starting game\n"); int turns_left = _INPUT_S.rows * _INPUT_S.collums; int turn = 0; tile_t result; move_t move; do { // apro semaforo al player di turno semOp(_SEMID, turn, 1); printf(PSERVER "%s's turn\n", name[turn]); // aspetto che mi mandi una mossa rcvMove(&move); insertMove(move.move, turn); // info printf("move: %d\n", move.move); printf("turns left: %d\n", turns_left - 1); // dico al player che la mossa รจ stata effettuata per fargli stampare il campo semOp(_SEMID, turn, 1); // next turn turn ^= 1; } while (--turns_left && !(result = checkWin(move.move))); if (!result) { printf(PSERVER "Game ended in a draw\n"); } else { printf(PSERVER "Game ended\n"); } game_end_t game_end = {.mtype = GAME_END, .winner = result}; sndGame_end(&game_end); sndGame_end(&game_end); kill(_PIDS[0], SIGUSR1); kill(_PIDS[1], SIGUSR1); //TODO: end of game return 0; }