From 27d563173e74ca6ffce4b6111bbe92eff3f119ee Mon Sep 17 00:00:00 2001 From: Trolli Schmittlauch Date: Thu, 12 Mar 2015 11:50:39 +0100 Subject: [PATCH] findMoves() now calls all other find(...)Moves() --- players/playerlib.cc | 24 ++++++++++++++++++++++++ players/playerlib.h | 14 +++----------- players/random-player.cc | 15 +-------------- 3 files changed, 28 insertions(+), 25 deletions(-) diff --git a/players/playerlib.cc b/players/playerlib.cc index 0debcce..0dcee79 100644 --- a/players/playerlib.cc +++ b/players/playerlib.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); +} diff --git a/players/playerlib.h b/players/playerlib.h index 49e1eba..94b0662 100644 --- a/players/playerlib.h +++ b/players/playerlib.h @@ -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 diff --git a/players/random-player.cc b/players/random-player.cc index 973de15..bba404b 100644 --- a/players/random-player.cc +++ b/players/random-player.cc @@ -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");