2015-03-07 17:18:50 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "playerlib.h"
|
|
|
|
|
2015-03-11 15:52:48 +01:00
|
|
|
//determines whether move or not and adds them to a movesList
|
|
|
|
int fillMovesList(cell (*)[fieldWidth], movesList *, size_t, size_t, unsigned int *, unsigned int *);
|
|
|
|
|
2015-03-11 11:28:20 +01:00
|
|
|
char enemyc = 0, ownc = 0;
|
2015-03-08 19:16:27 +01:00
|
|
|
|
2015-03-08 18:40:31 +01:00
|
|
|
char
|
|
|
|
getEnemyChar(char c) {
|
|
|
|
char enemyc;
|
|
|
|
switch(c)
|
|
|
|
{
|
|
|
|
case 'X':
|
|
|
|
enemyc='O'; break;
|
|
|
|
case 'O':
|
|
|
|
enemyc='X'; break;
|
|
|
|
}
|
|
|
|
return enemyc;
|
2015-03-10 13:54:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2015-03-11 15:52:48 +01:00
|
|
|
|
|
|
|
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) {
|
|
|
|
for (size_t row = 0;row < fieldHeight; ++row)
|
|
|
|
{
|
2015-03-11 16:00:43 +01:00
|
|
|
//Anzahl eigener/gegnerischer Steine
|
|
|
|
unsigned int ownCount = 0, enemyCount = 0;
|
2015-03-11 15:52:48 +01:00
|
|
|
for (size_t col = 0;col < fieldWidth; ++col)
|
|
|
|
{
|
|
|
|
fillMovesList(field, moves, row, col, &ownCount, &enemyCount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
findHorizontalBackwardMoves(cell (*field)[fieldWidth], movesList *moves) {
|
|
|
|
for (int row = 7; row >= 0; --row)
|
|
|
|
{
|
2015-03-11 16:00:43 +01:00
|
|
|
//Anzahl eigener/gegnerischer Steine
|
|
|
|
unsigned int ownCount = 0, enemyCount = 0;
|
2015-03-11 15:52:48 +01:00
|
|
|
for (int col = 7; col >= 0; --col)
|
|
|
|
{
|
|
|
|
fillMovesList(field, moves, row, col, &ownCount, &enemyCount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
findVerticalForwardMoves(cell (*field)[fieldWidth], movesList *moves) {
|
|
|
|
for (size_t col = 0;col < fieldHeight; ++col)
|
|
|
|
{
|
2015-03-11 16:00:43 +01:00
|
|
|
//Anzahl eigener/gegnerischer Steine
|
|
|
|
unsigned int ownCount = 0, enemyCount = 0;
|
2015-03-11 15:52:48 +01:00
|
|
|
for (size_t row = 0;row < fieldWidth; ++row)
|
|
|
|
{
|
|
|
|
fillMovesList(field, moves, row, col, &ownCount, &enemyCount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
findVerticalBackwardMoves(cell (*field)[fieldWidth], movesList *moves) {
|
|
|
|
for (int col = 7; col >= 0; --col)
|
|
|
|
{
|
2015-03-11 16:00:43 +01:00
|
|
|
//Anzahl eigener/gegnerischer Steine
|
|
|
|
unsigned int ownCount = 0, enemyCount = 0;
|
2015-03-11 15:52:48 +01:00
|
|
|
for (int row = 7; row >= 0; --row)
|
|
|
|
{
|
|
|
|
fillMovesList(field, moves, row, col, &ownCount, &enemyCount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|