funziona tuttogit push!

This commit is contained in:
Lorenzo Bianchi 2023-06-17 12:05:56 +02:00
parent 8ff7c1123d
commit 4fe93002e3
6 changed files with 36 additions and 21 deletions

View File

@ -2,6 +2,7 @@
#define CLIENT_H
extern int ID;
extern int clientBot;
extern pid_t SERVER_PID;
void setupClient(int argc, char *argv[]);

View File

@ -9,7 +9,7 @@
#define CLEAR 1
#define TIME_TO_MOVE 15
#define TIME_TO_MOVE 10
// semaphore
union semun {

View File

@ -22,9 +22,9 @@ void checkClientinput(int argc, char *argv[]);
int generateMove();
int main(int argc, char *argv[]){
int clientBot = 0;
printf("Il mio pid per killarmi: %d\n", getpid()); //TMP
printf("%d\n", argc);
setupClient(argc, argv);
// aspetto che il server mi dia il permesso di collegarmi e segnalo collegamento al server
@ -41,19 +41,22 @@ int main(int argc, char *argv[]){
}
if (!strcmp(argv[2], "auto")) {
clientBot = 1;
printf("sono un bot\n");
}
}
strcpy(player.name_player, argv[1]);
sndPlayer(&player);
printf(PCLIENT "Searching for oponent...\n");
if (!clientBot) {
printf(PCLIENT "Searching for oponent...\n");
}
semOp(_SEMID, ID, -1);
printf(PCLIENT "Opponent found\n");
printBoard();
printf(PCLIENT "Waiting for oponent\n");
if (!clientBot) {
printf(PCLIENT "Opponent found\n");
printBoard();
printf(PCLIENT "Waiting for oponent\n");
}
@ -63,10 +66,13 @@ int main(int argc, char *argv[]){
while (1) {
// aspetto il mio turno
semOp(_SEMID, ID, -1);
printBoard();
// input e controllo
printf(PCLIENT "Your Turn: ");
if (!clientBot) {
printBoard();
// input e controllo
printf(PCLIENT "Your Turn: ");
}
int pos;
do {
@ -83,14 +89,24 @@ int main(int argc, char *argv[]){
sndMove(&move);
semOp(_SEMID, ID, -1);
printBoard();
printf(PCLIENT "Waiting for opponent\n");
if (!clientBot) {
printBoard();
printf(PCLIENT "Waiting for opponent\n");
}
}
return 0;
}
int generateMove() {
return 1;
int cont = 0;
int arr[_COLLUMS];
for (int i=0; i<_COLLUMS; i++) {
if (checkMove(i)) {
arr[cont] = i;
cont++;
}
}
return arr[rand()%cont];
}

View File

@ -18,6 +18,7 @@
int ID;
pid_t SERVER_PID;
int clientBot = 0;
void checkClientinput(int argc, char *argv[]);
@ -55,7 +56,6 @@ void checkClientinput(int argc, char *argv[]){
}
if (argv[2]) {
printf("%s\n", argv[2]);
if (strcmp(argv[2], "bot") && strcmp(argv[2], "auto")) {
errExitMsg("Invalid third argument");
}

View File

@ -126,7 +126,7 @@ void setServerSignal(int sig) {
void sigHandlerClient(int sig) {
// Ctrl+C
if (sig == SIGINT) {
if (sig == SIGINT && !clientBot) {
printf("\n" PCLIENT "Quitting game\n");
game_end_t game = {.mtype = GAME_END, .winner = ID ^ 1};
sndGame_end(&game);

View File

@ -122,9 +122,7 @@ void printTile(tile_t t) {
}
}
// ritorna la posizione in cui il giocqtore potra iserire la sua mossa
// gli si passa la colona partendo da 1
// se
// ritorna la posizione in cui il giocatore potra iserire la sua mossa
int checkMove(int collums) {
if (collums < 0 || collums >= _COLLUMS) {
char buf[100];