checkmove
This commit is contained in:
parent
77a16c43a3
commit
9ecee70798
10
TODO.txt
10
TODO.txt
|
@ -2,16 +2,8 @@
|
|||
(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
|
||||
|
|
43
src/forza4.c
43
src/forza4.c
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -76,7 +81,7 @@ int checkWinAll(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 {
|
||||
|
@ -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);
|
||||
|
||||
return height;
|
||||
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;
|
||||
}
|
||||
|
||||
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() {
|
||||
|
||||
}
|
Loading…
Reference in New Issue