find vertical and horizontal moves, forwards and backwards
This commit is contained in:
parent
9b291a2c19
commit
a9399ddf06
|
@ -3,6 +3,9 @@
|
||||||
|
|
||||||
#include "playerlib.h"
|
#include "playerlib.h"
|
||||||
|
|
||||||
|
//determines whether move or not and adds them to a movesList
|
||||||
|
int fillMovesList(cell (*)[fieldWidth], movesList *, size_t, size_t, unsigned int *, unsigned int *);
|
||||||
|
|
||||||
char enemyc = 0, ownc = 0;
|
char enemyc = 0, ownc = 0;
|
||||||
|
|
||||||
char
|
char
|
||||||
|
@ -31,3 +34,89 @@ readStateBuffer(char *stateBuffer, struct cell (*gameField)[fieldWidth]) {
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
fillMovesList(cell (*field)[fieldWidth], movesList *moves, size_t row, size_t col, unsigned int *ownCount, unsigned int *enemyCount) {
|
||||||
|
++(field[row][col].timesVisited);
|
||||||
|
if (field[row][col].content == ownc)
|
||||||
|
{
|
||||||
|
++(*ownCount);
|
||||||
|
*enemyCount = 0;
|
||||||
|
printf("%d,%d: ownCount: %d, enemyCount: %d\n", row, col, *ownCount, *enemyCount);
|
||||||
|
}
|
||||||
|
if(field[row][col].content == enemyc && ownCount)
|
||||||
|
{
|
||||||
|
++(*enemyCount);
|
||||||
|
printf("%d,%d: ownCount: %d, enemyCount: %d\n", row, col, *ownCount, *enemyCount);
|
||||||
|
}
|
||||||
|
if(field[row][col].content == '.')
|
||||||
|
{
|
||||||
|
if (*ownCount && *enemyCount > 0)
|
||||||
|
{
|
||||||
|
printf("BAM!\n");
|
||||||
|
moves->list[moves->movesNumber].turnRow = row+1;
|
||||||
|
moves->list[moves->movesNumber].turnCol = col+1;
|
||||||
|
++(moves->movesNumber);
|
||||||
|
}
|
||||||
|
*ownCount = 0;
|
||||||
|
*enemyCount = 0;
|
||||||
|
printf("%d,%d: ownCount: %d, enemyCount: %d\n", row, col, *ownCount, *enemyCount);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
findHorizontalForwardMoves(cell (*field)[fieldWidth], movesList *moves) {
|
||||||
|
//Anzahl eigener/gegnerischer Steine
|
||||||
|
unsigned int ownCount = 0, enemyCount = 0;
|
||||||
|
for (size_t row = 0;row < fieldHeight; ++row)
|
||||||
|
{
|
||||||
|
for (size_t col = 0;col < fieldWidth; ++col)
|
||||||
|
{
|
||||||
|
fillMovesList(field, moves, row, col, &ownCount, &enemyCount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
findHorizontalBackwardMoves(cell (*field)[fieldWidth], movesList *moves) {
|
||||||
|
//Anzahl eigener/gegnerischer Steine
|
||||||
|
unsigned int ownCount = 0, enemyCount = 0;
|
||||||
|
for (int row = 7; row >= 0; --row)
|
||||||
|
{
|
||||||
|
for (int col = 7; col >= 0; --col)
|
||||||
|
{
|
||||||
|
fillMovesList(field, moves, row, col, &ownCount, &enemyCount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
findVerticalForwardMoves(cell (*field)[fieldWidth], movesList *moves) {
|
||||||
|
//Anzahl eigener/gegnerischer Steine
|
||||||
|
unsigned int ownCount = 0, enemyCount = 0;
|
||||||
|
for (size_t col = 0;col < fieldHeight; ++col)
|
||||||
|
{
|
||||||
|
for (size_t row = 0;row < fieldWidth; ++row)
|
||||||
|
{
|
||||||
|
fillMovesList(field, moves, row, col, &ownCount, &enemyCount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
findVerticalBackwardMoves(cell (*field)[fieldWidth], movesList *moves) {
|
||||||
|
//Anzahl eigener/gegnerischer Steine
|
||||||
|
unsigned int ownCount = 0, enemyCount = 0;
|
||||||
|
for (int col = 7; col >= 0; --col)
|
||||||
|
{
|
||||||
|
for (int row = 7; row >= 0; --row)
|
||||||
|
{
|
||||||
|
fillMovesList(field, moves, row, col, &ownCount, &enemyCount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
@ -18,15 +18,15 @@ struct movesList {
|
||||||
move *list = new move[fieldWidth*fieldHeight-4]();
|
move *list = new move[fieldWidth*fieldHeight-4]();
|
||||||
};
|
};
|
||||||
|
|
||||||
enum iterDirection
|
|
||||||
{
|
|
||||||
forwards, backwards
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
//returns the character used for the enemy's stones
|
//returns the character used for the enemy's stones
|
||||||
extern char getEnemyChar(char);
|
extern char getEnemyChar(char);
|
||||||
//reads the stateBuffer string into a 2d matrix
|
//reads the stateBuffer string into a 2d matrix
|
||||||
extern int readStateBuffer(char*, cell (*)[fieldWidth]);
|
extern int readStateBuffer(char*, cell (*)[fieldWidth]);
|
||||||
|
|
||||||
|
//adds all hotizontally-forward found moves to movesList
|
||||||
|
int findHorizontalForwardMoves(cell (*)[fieldWidth], movesList *);
|
||||||
|
int findHorizontalBackwardMoves(cell (*)[fieldWidth], movesList *);
|
||||||
|
int findVerticalForwardMoves(cell (*)[fieldWidth], movesList *);
|
||||||
|
int findVerticalBackwardMoves(cell (*)[fieldWidth], movesList *);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -19,38 +19,6 @@ send_move(int row, int col)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
|
||||||
findVerticalMoves(cell (*field)[fieldWidth], movesList *moves, iterDirection direction) {
|
|
||||||
//Anzahl eigener/gegnerischer Steine
|
|
||||||
unsigned int ownCount = 0, enemyCount = 0;
|
|
||||||
if (direction == forwards)
|
|
||||||
{
|
|
||||||
for (size_t row = 0;row < fieldHeight; ++row)
|
|
||||||
{
|
|
||||||
for (size_t col = 0;col < fieldWidth; ++col)
|
|
||||||
{
|
|
||||||
//TODO: diesen Teil auslagern
|
|
||||||
++(field[row][col].timesVisited);
|
|
||||||
if (field[row][col].content == ownc)
|
|
||||||
++ownCount;
|
|
||||||
if(field[row][col].content == enemyc && ownCount)
|
|
||||||
++enemyCount;
|
|
||||||
if(field[row][col].content == '.')
|
|
||||||
{
|
|
||||||
if (ownCount && enemyCount > 0)
|
|
||||||
{
|
|
||||||
moves->list[moves->movesNumber].turnRow = row+1;
|
|
||||||
moves->list[moves->movesNumber].turnCol = col+1;
|
|
||||||
++(moves->movesNumber);
|
|
||||||
}
|
|
||||||
ownCount = 0;
|
|
||||||
enemyCount = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
|
@ -93,8 +61,10 @@ int main(void)
|
||||||
|
|
||||||
readStateBuffer(state_buffer, field); //stateBuffer ist Pointer auf char, field ist Pointer auf struct cell[]
|
readStateBuffer(state_buffer, field); //stateBuffer ist Pointer auf char, field ist Pointer auf struct cell[]
|
||||||
movesList *moves = new movesList();
|
movesList *moves = new movesList();
|
||||||
iterDirection direct = forwards;
|
findHorizontalForwardMoves(field, moves);
|
||||||
findVerticalMoves(field, moves, direct);
|
findHorizontalBackwardMoves(field, moves);
|
||||||
|
findVerticalForwardMoves(field, moves);
|
||||||
|
findVerticalBackwardMoves(field, moves);
|
||||||
|
|
||||||
for (unsigned int i=0; i<moves->movesNumber; ++i)
|
for (unsigned int i=0; i<moves->movesNumber; ++i)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue