edi gay
This commit is contained in:
parent
c4fb8a61ef
commit
4af60df4ed
|
@ -8,8 +8,6 @@
|
|||
#define DIAGONAL _COLLUMS - 1
|
||||
#define DIAGONAL_INV _COLLUMS + 1
|
||||
|
||||
#define isValid(pos) (pos > 0 && pos / _COLLUMS < _ROWS)
|
||||
|
||||
// global variable
|
||||
static int _ROWS;
|
||||
static int _COLLUMS;
|
||||
|
@ -27,5 +25,8 @@ int checkMove(tile_t *board, int collums);
|
|||
|
||||
void printBoard(tile_t *board);
|
||||
void printTile(tile_t t);
|
||||
void insertMove(tile_t *board, int pos, int turn);
|
||||
|
||||
int isValid(int pos);
|
||||
|
||||
#endif
|
|
@ -141,6 +141,8 @@ int main(int argc, char *argv[]){
|
|||
|
||||
// PARTITA
|
||||
move_t move = {.mtype = 2};
|
||||
setRows(input.rows); //FIXME:
|
||||
setCollums(input.collums);
|
||||
|
||||
while (1) { //FIXME: potenzialmente da cambiare questo while (ma forse bastano i segnali)
|
||||
// aspetto il mio turno
|
||||
|
@ -149,12 +151,13 @@ int main(int argc, char *argv[]){
|
|||
printBoard(boardClient);
|
||||
|
||||
// input e controllo
|
||||
printf("Your Turn: ");
|
||||
printf(PCLIENT "Your Turn: ");
|
||||
|
||||
int pos;
|
||||
do {
|
||||
scanf("%d", &move.move); //FIXME: c'è di meglio che scanf?
|
||||
move.move--;
|
||||
//FIXME: current_move = checkMove(move.move);
|
||||
} while(move.move < 0);
|
||||
scanf("%d", &move.move);
|
||||
move.move = checkMove(boardClient, move.move);
|
||||
} while (move.move == -1);
|
||||
|
||||
// mando mossa al server
|
||||
sndMove(&move);
|
||||
|
|
|
@ -71,7 +71,7 @@ int main(int argc, char *argv[]){
|
|||
strcpy(name[player.id], player.name_player);
|
||||
pids[player.id] = player.pid;
|
||||
|
||||
printf(PSERVER "Player %s connected", name[player.id]);
|
||||
printf(PSERVER "Player %s connected\n", name[player.id]);
|
||||
|
||||
// aspetto secondo client
|
||||
semOp(semid, 2, -1);
|
||||
|
@ -81,7 +81,7 @@ int main(int argc, char *argv[]){
|
|||
strcpy(name[player.id], player.name_player);
|
||||
pids[player.id] = player.pid;
|
||||
|
||||
printf(PSERVER "Player %s connected", name[player.id]);
|
||||
printf(PSERVER "Player %s connected\n", name[player.id]);
|
||||
|
||||
semOp(semid, 0, 1);
|
||||
semOp(semid, 1, 1);
|
||||
|
@ -107,6 +107,9 @@ int main(int argc, char *argv[]){
|
|||
|
||||
//TMP
|
||||
printf("move: %d\n", move.move);
|
||||
|
||||
insertMove(board, move.move, turn);
|
||||
|
||||
printf("turns left: %d\n", turns_left - 1);
|
||||
|
||||
|
||||
|
@ -119,6 +122,7 @@ int main(int argc, char *argv[]){
|
|||
} else {
|
||||
printf(PSERVER "Game ended\n");
|
||||
}
|
||||
|
||||
game_end_t game_end = {.mtype = 4, .winner = result};
|
||||
sndGame_end(&game_end);
|
||||
sndGame_end(&game_end);
|
||||
|
|
17
src/forza4.c
17
src/forza4.c
|
@ -112,8 +112,11 @@ 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
|
||||
int checkMove(tile_t *board, int collums) {
|
||||
if (collums < 0 || collums > _COLLUMS) {
|
||||
if (collums <= 0 || collums > _COLLUMS) {
|
||||
char buf[100];
|
||||
sprintf(buf, "the collums must be between 1 and %d", _COLLUMS);
|
||||
warningMsg(buf);
|
||||
|
@ -128,7 +131,7 @@ int checkMove(tile_t *board, int collums) {
|
|||
}
|
||||
|
||||
int pos = collums;
|
||||
while (isValid(pos + VERTICAL) && board[pos + VERTICAL] == EMPTY) {
|
||||
while (isValid(pos + VERTICAL) && board[pos + VERTICAL] == EMPTY) {
|
||||
pos += VERTICAL;
|
||||
}
|
||||
|
||||
|
@ -136,11 +139,9 @@ int checkMove(tile_t *board, int collums) {
|
|||
}
|
||||
|
||||
void insertMove(tile_t *board, int pos, int turn) {
|
||||
if (board[pos] != EMPTY) {
|
||||
char buf[100];
|
||||
sprintf(buf, "The position %d indicated isn't empty", pos);
|
||||
errExitMsg(buf);
|
||||
}
|
||||
|
||||
board[pos] = (turn == 0) ? PLAYER1 : PLAYER2;
|
||||
}
|
||||
|
||||
int isValid(int pos) {
|
||||
return pos >= 0 && pos < _ROWS * _COLLUMS;
|
||||
}
|
Loading…
Reference in New Issue