add getIndex and setCol and the header of forza4

This commit is contained in:
Edi De Candido 2023-05-16 11:03:51 +02:00
parent 8fc71bc58b
commit b524d834ca
2 changed files with 22 additions and 2 deletions

12
inc/forza4.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef FORZA4_H
#define FORZA4_H
#include <structures.h>
static int col;
void setCollums(int collums);
int getIndex(int i, int j);
int checkWin(tile_t *board, int x, int y, int rows, int collums);
#endif

View File

@ -1,12 +1,20 @@
#include <stdio.h>
#include <structures.h>
static int col;
void setCollums(int collums) {
col = collums;
}
int getIndex(int i, int j) {
return i * col + j;
}
// checks board for a win
// returns player number on win, otherwise 0
// x e y come cartesiani, rows e collums le dimensioni
int checkWin(tile_t *board, int x, int y, int rows, int collums) {
int i;
int i;
tile_t current = board[x + y * collums];
// horrizontal