checkmove

This commit is contained in:
Edi De Candido 2023-05-18 11:59:36 +02:00
parent 77a16c43a3
commit 9ecee70798
3 changed files with 52 additions and 35 deletions

View File

@ -1,17 +1,9 @@
- magari fare che (alcune delle) print vengano messe su tutti e tre i terminali
(motivo per cui ho messo le funzioni in nonsodovemetterle)
(forse basta tipo duplicare il fd ma sono stanco ci penso domani)
- controllo input dei client
- sistemare include (FARE SOLO ALLA FINE ALTRIMENTI SPRECO DI TEMPO COME LA TUA VITA)
- invece di fare tutti if == -1 si potrebbe fare come semOp e creare una funzione identica
che fa gia il controllo (ha come svantaggio che non puoi specifare dove va in errore con l'errexit)
(anche se forse basta passare la/le stringe ma vedi riga 3)
- killare il server deve uccidere i figli
- isValid è corretto?
- getIndex con define?
(anche se forse basta passare la/le stringe ma vedi riga 3) EDI APPROVA

View File

@ -9,20 +9,20 @@ void serverSigHandler(int sig) {
static int sigint_count = DEFAULT_SIGINT;
switch (sig) {
case SIGINT:
sigint_count--;
if (sigint_count > 0) {
printf("<Server> Press again Ctrl^C to exit (whitin %d sec)\n", TIME_TO_RESET);
alarm(TIME_TO_RESET);
} else {
// TODO bisogna fare un "at exit"
exit(0);
}
break;
default: //SIGALRM
printf("<Server> Time to exit (%d sec) expired\n", TIME_TO_RESET);
sigint_count = DEFAULT_SIGINT;
break;
case SIGINT:
sigint_count--;
if (sigint_count > 0) {
printf("<Server> Press again Ctrl^C to exit (whitin %d sec)\n", TIME_TO_RESET);
alarm(TIME_TO_RESET);
} else {
// TODO bisogna fare un "at exit"
exit(0);
}
break;
default: //SIGALRM
printf("<Server> Time to exit (%d sec) expired\n", TIME_TO_RESET);
sigint_count = DEFAULT_SIGINT;
break;
}
}

View File

@ -1,6 +1,6 @@
#include <stdio.h>
#include <forza4.h>
#include <errExit.h>
#include <structures.h>
void setRows(int rows) {
@ -11,13 +11,18 @@ void setCollums(int collums) {
_COLLUMS = collums;
}
void setDimension(int rows, int collums) {
setRows(rows);
setCollums(collums);
}
void setTokens(char t1, char t2) {
_TOKEN1 = t1;
_TOKEN2 = t2;
}
int getIndex(int r, int c) {
return r * _COLLUMS + c;
int getIndex(int i, int j) {
return i * _COLLUMS + j;
}
@ -73,10 +78,10 @@ int checkWinAll(tile_t *board){
return EMPTY;
}
void printBoard(tile_t *board){
void printBoard(tile_t *board) {
for (int i=0; i < _ROWS; i++) {
for (int j=0; j < _COLLUMS; j++) {
printTile(board[i * _COLLUMS + j]);
printTile(board[getIndex(i, j)]);
if (j != _COLLUMS - 1) {
printf(" | ");
} else {
@ -84,7 +89,7 @@ void printBoard(tile_t *board){
}
}
for(int j=0; i != _ROWS - 1 && j < _COLLUMS - 1; j++) {
for (int j=0; i != _ROWS - 1 && j < _COLLUMS - 1; j++) {
printf("----");
}
if (i < _ROWS - 1) {
@ -93,7 +98,7 @@ void printBoard(tile_t *board){
}
}
void printTile(tile_t t){
void printTile(tile_t t) {
switch(t) {
case EMPTY:
printf(" ");
@ -107,9 +112,29 @@ void printTile(tile_t t){
}
}
int getHeight(tile_t *board, int col){
int height = _ROWS - 1;
while (height-- >= 0 && board[getIndex(height, col)] == EMPTY);
int checkMove(tile_t *board, int collums) {
if (collums < 0 || collums > _COLLUMS) {
char buf[100];
sprintf(buf, "the collums must be between 1 and %d", _COLLUMS);
warningMsg(buf);
return -1;
}
return height;
if (board[collums] != EMPTY) {
char buf[100];
sprintf(buf, "the collum %d is full", collums + 1);
warningMsg(buf);
return -1;
}
int pos = collums;
while (isValid(pos + VERTICAL) && board[pos + VERTICAL] == EMPTY) {
pos += VERTICAL;
}
return pos;
}
void insertCoin() {
}