findMoves() now calls all other find(...)Moves()

This commit is contained in:
Trolli Schmittlauch 2015-03-12 11:50:39 +01:00
parent 976efce0fd
commit 27d563173e
3 changed files with 28 additions and 25 deletions

View file

@ -11,6 +11,18 @@ int iterDiagForwards(cell (*)[fieldSize], movesList *, size_t, size_t);
int iterDiagBackwards(cell (*)[fieldSize], movesList *, int, int);
//adds all hotizontally-forward found moves to movesList
int findHorizontalForwardMoves(cell (*)[fieldSize], movesList *);
int findHorizontalBackwardMoves(cell (*)[fieldSize], movesList *);
int findVerticalForwardMoves(cell (*)[fieldSize], movesList *);
int findVerticalBackwardMoves(cell (*)[fieldSize], movesList *);
int findDiagonalTopLeftMoves(cell (*)[fieldSize], movesList *);
int findDiagonalBottomRightMoves(cell (*)[fieldSize], movesList *);
int findDiagonalBottomLeftMoves(cell (*)[fieldSize], movesList *);
int findDiagonalTopRightMoves(cell (*)[fieldSize], movesList *);
char enemyc = 0, ownc = 0;
char
@ -286,3 +298,15 @@ findDiagonalTopRightMoves(cell (*field)[fieldSize], movesList *moves) {
}
return 0;
}
int
findMoves(cell (*field)[fieldSize], movesList *moves) {
return findHorizontalForwardMoves(field, moves) +
findHorizontalBackwardMoves(field, moves) +
findVerticalForwardMoves(field, moves) +
findVerticalBackwardMoves(field, moves) +
findDiagonalBottomRightMoves(field, moves) +
findDiagonalTopLeftMoves(field, moves) +
findDiagonalBottomLeftMoves(field, moves) +
findDiagonalTopRightMoves(field, moves);
}

View file

@ -1,7 +1,7 @@
#ifndef PLAYERLIB_H
#define PLAYERLIB_H
const int fieldSize=8;
const int fieldSize=8; // =fieldHeight=fieldWidth
extern char enemyc; //initially 0, contains char of enemy's stone
extern char ownc;
@ -24,14 +24,6 @@ extern char getEnemyChar(char);
//reads the stateBuffer string into a 2d matrix
extern int readStateBuffer(char*, cell (*)[fieldSize]);
//adds all hotizontally-forward found moves to movesList
int findHorizontalForwardMoves(cell (*)[fieldSize], movesList *);
int findHorizontalBackwardMoves(cell (*)[fieldSize], movesList *);
int findVerticalForwardMoves(cell (*)[fieldSize], movesList *);
int findVerticalBackwardMoves(cell (*)[fieldSize], movesList *);
int findDiagonalTopLeftMoves(cell (*)[fieldSize], movesList *);
int findDiagonalBottomRightMoves(cell (*)[fieldSize], movesList *);
int findDiagonalBottomLeftMoves(cell (*)[fieldSize], movesList *);
int findDiagonalTopRightMoves(cell (*)[fieldSize], movesList *);
//iterates through field in all directions, stores moves into movesList
int findMoves(cell (*)[fieldSize], movesList *);
#endif

View file

@ -65,20 +65,7 @@ int main(void)
readStateBuffer(state_buffer, field); //stateBuffer ist Pointer auf char, field ist Pointer auf struct cell[]
movesList *moves = new movesList();
findHorizontalForwardMoves(field, moves);
findHorizontalBackwardMoves(field, moves);
findVerticalForwardMoves(field, moves);
findVerticalBackwardMoves(field, moves);
findDiagonalBottomRightMoves(field, moves);
findDiagonalTopLeftMoves(field, moves);
#ifdef debugprint
printf("BottomLeft\n");
#endif
findDiagonalBottomLeftMoves(field, moves);
#ifdef debugprint
printf("TopRight\n");
#endif
findDiagonalTopRightMoves(field, moves);
findMoves(field, moves);
#ifdef debugprint
printf("\nZüge:\n");