funziona tuttogit push!
This commit is contained in:
parent
8ff7c1123d
commit
4fe93002e3
|
@ -2,6 +2,7 @@
|
||||||
#define CLIENT_H
|
#define CLIENT_H
|
||||||
|
|
||||||
extern int ID;
|
extern int ID;
|
||||||
|
extern int clientBot;
|
||||||
extern pid_t SERVER_PID;
|
extern pid_t SERVER_PID;
|
||||||
|
|
||||||
void setupClient(int argc, char *argv[]);
|
void setupClient(int argc, char *argv[]);
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
#define CLEAR 1
|
#define CLEAR 1
|
||||||
|
|
||||||
#define TIME_TO_MOVE 15
|
#define TIME_TO_MOVE 10
|
||||||
|
|
||||||
// semaphore
|
// semaphore
|
||||||
union semun {
|
union semun {
|
||||||
|
|
|
@ -22,9 +22,9 @@ void checkClientinput(int argc, char *argv[]);
|
||||||
int generateMove();
|
int generateMove();
|
||||||
|
|
||||||
int main(int argc, char *argv[]){
|
int main(int argc, char *argv[]){
|
||||||
int clientBot = 0;
|
|
||||||
printf("Il mio pid per killarmi: %d\n", getpid()); //TMP
|
printf("Il mio pid per killarmi: %d\n", getpid()); //TMP
|
||||||
printf("%d\n", argc);
|
|
||||||
setupClient(argc, argv);
|
setupClient(argc, argv);
|
||||||
|
|
||||||
// aspetto che il server mi dia il permesso di collegarmi e segnalo collegamento al server
|
// 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")) {
|
if (!strcmp(argv[2], "auto")) {
|
||||||
clientBot = 1;
|
clientBot = 1;
|
||||||
|
printf("sono un bot\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
strcpy(player.name_player, argv[1]);
|
strcpy(player.name_player, argv[1]);
|
||||||
sndPlayer(&player);
|
sndPlayer(&player);
|
||||||
|
|
||||||
printf(PCLIENT "Searching for oponent...\n");
|
if (!clientBot) {
|
||||||
|
printf(PCLIENT "Searching for oponent...\n");
|
||||||
|
}
|
||||||
semOp(_SEMID, ID, -1);
|
semOp(_SEMID, ID, -1);
|
||||||
|
|
||||||
printf(PCLIENT "Opponent found\n");
|
if (!clientBot) {
|
||||||
|
printf(PCLIENT "Opponent found\n");
|
||||||
printBoard();
|
printBoard();
|
||||||
printf(PCLIENT "Waiting for oponent\n");
|
printf(PCLIENT "Waiting for oponent\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -63,10 +66,13 @@ int main(int argc, char *argv[]){
|
||||||
while (1) {
|
while (1) {
|
||||||
// aspetto il mio turno
|
// aspetto il mio turno
|
||||||
semOp(_SEMID, ID, -1);
|
semOp(_SEMID, ID, -1);
|
||||||
printBoard();
|
|
||||||
|
|
||||||
// input e controllo
|
if (!clientBot) {
|
||||||
printf(PCLIENT "Your Turn: ");
|
printBoard();
|
||||||
|
|
||||||
|
// input e controllo
|
||||||
|
printf(PCLIENT "Your Turn: ");
|
||||||
|
}
|
||||||
|
|
||||||
int pos;
|
int pos;
|
||||||
do {
|
do {
|
||||||
|
@ -83,14 +89,24 @@ int main(int argc, char *argv[]){
|
||||||
sndMove(&move);
|
sndMove(&move);
|
||||||
|
|
||||||
semOp(_SEMID, ID, -1);
|
semOp(_SEMID, ID, -1);
|
||||||
printBoard();
|
if (!clientBot) {
|
||||||
|
printBoard();
|
||||||
printf(PCLIENT "Waiting for opponent\n");
|
printf(PCLIENT "Waiting for opponent\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int generateMove() {
|
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];
|
||||||
}
|
}
|
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
int ID;
|
int ID;
|
||||||
pid_t SERVER_PID;
|
pid_t SERVER_PID;
|
||||||
|
int clientBot = 0;
|
||||||
|
|
||||||
void checkClientinput(int argc, char *argv[]);
|
void checkClientinput(int argc, char *argv[]);
|
||||||
|
|
||||||
|
@ -55,7 +56,6 @@ void checkClientinput(int argc, char *argv[]){
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argv[2]) {
|
if (argv[2]) {
|
||||||
printf("%s\n", argv[2]);
|
|
||||||
if (strcmp(argv[2], "bot") && strcmp(argv[2], "auto")) {
|
if (strcmp(argv[2], "bot") && strcmp(argv[2], "auto")) {
|
||||||
errExitMsg("Invalid third argument");
|
errExitMsg("Invalid third argument");
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,7 +126,7 @@ void setServerSignal(int sig) {
|
||||||
|
|
||||||
void sigHandlerClient(int sig) {
|
void sigHandlerClient(int sig) {
|
||||||
// Ctrl+C
|
// Ctrl+C
|
||||||
if (sig == SIGINT) {
|
if (sig == SIGINT && !clientBot) {
|
||||||
printf("\n" PCLIENT "Quitting game\n");
|
printf("\n" PCLIENT "Quitting game\n");
|
||||||
game_end_t game = {.mtype = GAME_END, .winner = ID ^ 1};
|
game_end_t game = {.mtype = GAME_END, .winner = ID ^ 1};
|
||||||
sndGame_end(&game);
|
sndGame_end(&game);
|
||||||
|
|
|
@ -122,9 +122,7 @@ void printTile(tile_t t) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ritorna la posizione in cui il giocqtore potra iserire la sua mossa
|
// ritorna la posizione in cui il giocatore potra iserire la sua mossa
|
||||||
// gli si passa la colona partendo da 1
|
|
||||||
// se
|
|
||||||
int checkMove(int collums) {
|
int checkMove(int collums) {
|
||||||
if (collums < 0 || collums >= _COLLUMS) {
|
if (collums < 0 || collums >= _COLLUMS) {
|
||||||
char buf[100];
|
char buf[100];
|
||||||
|
|
Loading…
Reference in New Issue