now able to find all vertical forward moves

This commit is contained in:
Trolli Schmittlauch 2015-03-11 11:28:20 +01:00
parent a063a74537
commit 9b291a2c19
3 changed files with 69 additions and 6 deletions

View file

@ -3,7 +3,7 @@
#include "playerlib.h" #include "playerlib.h"
char enemyc = 0; char enemyc = 0, ownc = 0;
char char
getEnemyChar(char c) { getEnemyChar(char c) {

View file

@ -3,10 +3,26 @@
const unsigned int fieldHeight=8, fieldWidth=8; const unsigned int fieldHeight=8, fieldWidth=8;
extern char enemyc; //initially 0, contains char of enemy's stone extern char enemyc; //initially 0, contains char of enemy's stone
extern char ownc;
struct cell { struct cell {
char content = '.'; char content = '.';
unsigned short int timesVisited = 0; unsigned short int timesVisited = 0;
}; };
struct move {
unsigned int turnRow;
unsigned int turnCol;
};
struct movesList {
unsigned int movesNumber = 0;
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);

View file

@ -19,6 +19,40 @@ 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)
{ {
int done = 0; int done = 0;
@ -46,20 +80,33 @@ int main(void)
// 2. TODO: Strategie hier einfügen. Resultat in turn_row und turn_col speichern. // 2. TODO: Strategie hier einfügen. Resultat in turn_row und turn_col speichern.
if(!enemyc) if(!enemyc)
enemyc = getEnemyChar(state_buffer[0]); {
ownc = state_buffer[0];
enemyc = getEnemyChar(ownc);
}
//pure C: //pure C:
//struct cell (*field) = malloc(fieldHeight*fieldWidth*sizeof(struct cell)); //struct cell (*field)[fieldWidth] = malloc(fieldHeight*fieldWidth*sizeof(struct cell));
//C++ version: //C++ version:
auto field = new cell[fieldHeight][fieldWidth](); auto field = new cell[fieldHeight][fieldWidth]();
printf("%p\n", field);
readStateBuffer(state_buffer, field); readStateBuffer(state_buffer, field); //stateBuffer ist Pointer auf char, field ist Pointer auf struct cell[]
movesList *moves = new movesList();
iterDirection direct = forwards;
findVerticalMoves(field, moves, direct);
for (unsigned int i=0; i<moves->movesNumber; ++i)
{
printf("%d,%d\n",moves->list[i].turnRow,moves->list[i].turnCol);
}
// 3. Return result // 3. Return result
//send_move(turn_row, turn_col); //send_move(turn_row, turn_col);
delete field; //for(int i=0; i<fieldHeight; ++i)
// delete [] field[i];
delete [] field;
delete [] moves;
/* END PLAYER-SPECIFIC CODE */ /* END PLAYER-SPECIFIC CODE */