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

master
Trolli Schmittlauch 8 years ago
parent 976efce0fd
commit 27d563173e
  1. 24
      players/playerlib.cc
  2. 14
      players/playerlib.h
  3. 15
      players/random-player.cc

@ -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);
}

@ -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

@ -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");

Loading…
Cancel
Save