#include #include #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 getEnemyChar(char c) { char enemyc; switch(c) { case 'X': enemyc='O'; break; case 'O': enemyc='X'; break; } return enemyc; } int readStateBuffer(char *stateBuffer, struct cell (*gameField)[fieldWidth]) { for(size_t row=0; row< fieldHeight; ++row) { for(size_t col=0; col< fieldWidth; ++col) { int index = row*fieldHeight+col+1; gameField[row][col].content = stateBuffer[index]; //printf("gameField %lu %lu =stateBuffer %d = %c\n", row, col, index, gameField[row][col].content); } } 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; }