replace fieldWidth and fieldHeight with fieldSize (field is a square)
This commit is contained in:
parent
8ac7a59a34
commit
48400b8ce2
|
@ -5,11 +5,11 @@
|
|||
#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 *);
|
||||
int fillMovesList(cell (*)[fieldSize], movesList *, size_t, size_t, unsigned int *, unsigned int *);
|
||||
|
||||
int iterDiagForwards(cell (*)[fieldWidth], movesList *, size_t, size_t);
|
||||
int iterDiagForwards(cell (*)[fieldSize], movesList *, size_t, size_t);
|
||||
|
||||
int iterDiagBackwards(cell (*)[fieldWidth], movesList *, int, int);
|
||||
int iterDiagBackwards(cell (*)[fieldSize], movesList *, int, int);
|
||||
|
||||
char enemyc = 0, ownc = 0;
|
||||
|
||||
|
@ -27,12 +27,12 @@ getEnemyChar(char c) {
|
|||
}
|
||||
|
||||
int
|
||||
readStateBuffer(char *stateBuffer, struct cell (*gameField)[fieldWidth]) {
|
||||
for(size_t row=0; row< fieldHeight; ++row)
|
||||
readStateBuffer(char *stateBuffer, struct cell (*gameField)[fieldSize]) {
|
||||
for(size_t row=0; row< fieldSize; ++row)
|
||||
{
|
||||
for(size_t col=0; col< fieldWidth; ++col)
|
||||
for(size_t col=0; col< fieldSize; ++col)
|
||||
{
|
||||
int index = row*fieldHeight+col+1;
|
||||
int index = row*fieldSize+col+1;
|
||||
gameField[row][col].content = stateBuffer[index];
|
||||
#ifdef debugprint
|
||||
//printf("gameField %lu %lu =stateBuffer %d = %c\n", row, col, index, gameField[row][col].content);
|
||||
|
@ -43,7 +43,7 @@ readStateBuffer(char *stateBuffer, struct cell (*gameField)[fieldWidth]) {
|
|||
}
|
||||
|
||||
int
|
||||
fillMovesList(cell (*field)[fieldWidth], movesList *moves, size_t row, size_t col, unsigned int *ownCount, unsigned int *enemyCount) {
|
||||
fillMovesList(cell (*field)[fieldSize], movesList *moves, size_t row, size_t col, unsigned int *ownCount, unsigned int *enemyCount) {
|
||||
++(field[row][col].timesVisited);
|
||||
if (field[row][col].content == ownc)
|
||||
{
|
||||
|
@ -81,12 +81,12 @@ fillMovesList(cell (*field)[fieldWidth], movesList *moves, size_t row, size_t co
|
|||
}
|
||||
|
||||
int
|
||||
findHorizontalForwardMoves(cell (*field)[fieldWidth], movesList *moves) {
|
||||
for (size_t row = 0;row < fieldHeight; ++row)
|
||||
findHorizontalForwardMoves(cell (*field)[fieldSize], movesList *moves) {
|
||||
for (size_t row = 0;row < fieldSize; ++row)
|
||||
{
|
||||
//Anzahl eigener/gegnerischer Steine
|
||||
unsigned int ownCount = 0, enemyCount = 0;
|
||||
for (size_t col = 0;col < fieldWidth; ++col)
|
||||
for (size_t col = 0;col < fieldSize; ++col)
|
||||
{
|
||||
fillMovesList(field, moves, row, col, &ownCount, &enemyCount);
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ findHorizontalForwardMoves(cell (*field)[fieldWidth], movesList *moves) {
|
|||
}
|
||||
|
||||
int
|
||||
findHorizontalBackwardMoves(cell (*field)[fieldWidth], movesList *moves) {
|
||||
findHorizontalBackwardMoves(cell (*field)[fieldSize], movesList *moves) {
|
||||
for (int row = 7; row >= 0; --row)
|
||||
{
|
||||
//Anzahl eigener/gegnerischer Steine
|
||||
|
@ -109,12 +109,12 @@ findHorizontalBackwardMoves(cell (*field)[fieldWidth], movesList *moves) {
|
|||
}
|
||||
|
||||
int
|
||||
findVerticalForwardMoves(cell (*field)[fieldWidth], movesList *moves) {
|
||||
for (size_t col = 0;col < fieldHeight; ++col)
|
||||
findVerticalForwardMoves(cell (*field)[fieldSize], movesList *moves) {
|
||||
for (size_t col = 0;col < fieldSize; ++col)
|
||||
{
|
||||
//Anzahl eigener/gegnerischer Steine
|
||||
unsigned int ownCount = 0, enemyCount = 0;
|
||||
for (size_t row = 0;row < fieldWidth; ++row)
|
||||
for (size_t row = 0;row < fieldSize; ++row)
|
||||
{
|
||||
fillMovesList(field, moves, row, col, &ownCount, &enemyCount);
|
||||
}
|
||||
|
@ -123,7 +123,7 @@ findVerticalForwardMoves(cell (*field)[fieldWidth], movesList *moves) {
|
|||
}
|
||||
|
||||
int
|
||||
findVerticalBackwardMoves(cell (*field)[fieldWidth], movesList *moves) {
|
||||
findVerticalBackwardMoves(cell (*field)[fieldSize], movesList *moves) {
|
||||
for (int col = 7; col >= 0; --col)
|
||||
{
|
||||
//Anzahl eigener/gegnerischer Steine
|
||||
|
@ -137,10 +137,10 @@ findVerticalBackwardMoves(cell (*field)[fieldWidth], movesList *moves) {
|
|||
}
|
||||
|
||||
int
|
||||
iterDiagForwards(cell (*field)[fieldWidth], movesList *moves, size_t row, size_t col) {
|
||||
iterDiagForwards(cell (*field)[fieldSize], movesList *moves, size_t row, size_t col) {
|
||||
//Anzahl eigener/gegnerischer Steine
|
||||
unsigned int ownCount = 0, enemyCount = 0;
|
||||
for (; row < fieldWidth && col < fieldHeight; ++row, ++col)
|
||||
for (; row < fieldSize && col < fieldSize; ++row, ++col)
|
||||
{
|
||||
fillMovesList(field, moves, row, col, &ownCount, &enemyCount);
|
||||
#ifdef debugprint
|
||||
|
@ -151,7 +151,7 @@ iterDiagForwards(cell (*field)[fieldWidth], movesList *moves, size_t row, size_t
|
|||
}
|
||||
|
||||
int
|
||||
iterDiagBackwards(cell (*field)[fieldWidth], movesList *moves, int row, int col) {
|
||||
iterDiagBackwards(cell (*field)[fieldSize], movesList *moves, int row, int col) {
|
||||
//Anzahl eigener/gegnerischer Steine
|
||||
unsigned int ownCount = 0, enemyCount = 0;
|
||||
for (; row >= 0 && col >= 0; --row, --col)
|
||||
|
@ -165,8 +165,8 @@ iterDiagBackwards(cell (*field)[fieldWidth], movesList *moves, int row, int col)
|
|||
}
|
||||
|
||||
int
|
||||
findDiagonalBottomRightMoves(cell (*field)[fieldWidth], movesList *moves) {
|
||||
for (size_t col = 0; col < fieldHeight; ++col)
|
||||
findDiagonalBottomRightMoves(cell (*field)[fieldSize], movesList *moves) {
|
||||
for (size_t col = 0; col < fieldSize; ++col)
|
||||
{
|
||||
#ifdef debugprint
|
||||
printf("F%d\n",col);
|
||||
|
@ -186,35 +186,35 @@ findDiagonalBottomRightMoves(cell (*field)[fieldWidth], movesList *moves) {
|
|||
}
|
||||
|
||||
int
|
||||
findDiagonalTopLeftMoves(cell (*field)[fieldWidth], movesList *moves) {
|
||||
for (int col = fieldHeight-1; col >= 0; --col)
|
||||
findDiagonalTopLeftMoves(cell (*field)[fieldSize], movesList *moves) {
|
||||
for (int col = fieldSize-1; col >= 0; --col)
|
||||
{
|
||||
#ifdef debugprint
|
||||
printf("F%d\n",col);
|
||||
printf("\n---------------------------------\n");
|
||||
#endif
|
||||
iterDiagBackwards(field, moves, fieldHeight-1, col);
|
||||
if(col != fieldHeight-1)
|
||||
iterDiagBackwards(field, moves, fieldSize-1, col);
|
||||
if(col != fieldSize-1)
|
||||
{
|
||||
#ifdef debugprint
|
||||
printf("\n---------------------------------\n");
|
||||
#endif
|
||||
iterDiagBackwards(field, moves, col, fieldWidth-1);
|
||||
iterDiagBackwards(field, moves, col, fieldSize-1);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
findDiagonalBottomLeftMoves(cell (*field)[fieldWidth], movesList *moves) {
|
||||
for(unsigned int i=0; i<fieldHeight; ++i)
|
||||
findDiagonalBottomLeftMoves(cell (*field)[fieldSize], movesList *moves) {
|
||||
for(int i=0; i<fieldSize; ++i)
|
||||
{
|
||||
#ifdef debugprint
|
||||
printf("\n---------------------------------\n");
|
||||
#endif
|
||||
//Anzahl eigener/gegnerischer Steine
|
||||
unsigned int ownCount=0, enemyCount=0;
|
||||
for(int row=0; row<= i && row < fieldHeight; ++row)
|
||||
for(int row=0; row<= i && row < fieldSize; ++row)
|
||||
{
|
||||
int col = i-row;
|
||||
#ifdef debugprint
|
||||
|
@ -224,7 +224,7 @@ findDiagonalBottomLeftMoves(cell (*field)[fieldWidth], movesList *moves) {
|
|||
}
|
||||
}
|
||||
|
||||
for(int i=fieldWidth; i<2*fieldWidth-1; ++i)
|
||||
for(int i=fieldSize; i<2*fieldSize-1; ++i)
|
||||
{
|
||||
#ifdef debugprint
|
||||
printf("i=%d\n", i);
|
||||
|
@ -233,7 +233,7 @@ findDiagonalBottomLeftMoves(cell (*field)[fieldWidth], movesList *moves) {
|
|||
unsigned int ownCount=0, enemyCount=0;
|
||||
int col=7;
|
||||
int row= i-col;
|
||||
while(row < fieldWidth-1)
|
||||
while(row < fieldSize-1)
|
||||
{
|
||||
row= i-col;
|
||||
#ifdef debugprint
|
||||
|
@ -248,8 +248,8 @@ findDiagonalBottomLeftMoves(cell (*field)[fieldWidth], movesList *moves) {
|
|||
}
|
||||
|
||||
int
|
||||
findDiagonalTopRightMoves(cell (*field)[fieldWidth], movesList *moves) {
|
||||
for(int i=2*fieldWidth-2; i>=fieldWidth; --i)
|
||||
findDiagonalTopRightMoves(cell (*field)[fieldSize], movesList *moves) {
|
||||
for(int i=2*fieldSize-2; i>=fieldSize; --i)
|
||||
{
|
||||
#ifdef debugprint
|
||||
printf("i=%d\n", i);
|
||||
|
@ -258,7 +258,7 @@ findDiagonalTopRightMoves(cell (*field)[fieldWidth], movesList *moves) {
|
|||
unsigned int ownCount=0, enemyCount=0;
|
||||
int row=7;
|
||||
int col= i-row;
|
||||
while(col<fieldWidth-1)
|
||||
while(col<fieldSize-1)
|
||||
{
|
||||
col= i-row;
|
||||
#ifdef debugprint
|
||||
|
@ -268,7 +268,7 @@ findDiagonalTopRightMoves(cell (*field)[fieldWidth], movesList *moves) {
|
|||
row--;
|
||||
}
|
||||
}
|
||||
for(int i=fieldWidth-1; i>=0; --i)
|
||||
for(int i=fieldSize-1; i>=0; --i)
|
||||
{
|
||||
#ifdef debugprint
|
||||
printf("\n---------------------------------\n");
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
#ifndef PLAYERLIB_H
|
||||
#define PLAYERLIB_H
|
||||
|
||||
const int fieldHeight=8;
|
||||
const int fieldWidth=fieldHeight; //spätere Annahme: Feld quadratisch
|
||||
const int fieldSize=8;
|
||||
|
||||
extern char enemyc; //initially 0, contains char of enemy's stone
|
||||
extern char ownc;
|
||||
|
@ -23,16 +22,16 @@ struct movesList {
|
|||
//returns the character used for the enemy's stones
|
||||
extern char getEnemyChar(char);
|
||||
//reads the stateBuffer string into a 2d matrix
|
||||
extern int readStateBuffer(char*, cell (*)[fieldWidth]);
|
||||
extern int readStateBuffer(char*, cell (*)[fieldSize]);
|
||||
|
||||
//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 *);
|
||||
int findDiagonalTopLeftMoves(cell (*)[fieldWidth], movesList *);
|
||||
int findDiagonalBottomRightMoves(cell (*)[fieldWidth], movesList *);
|
||||
int findDiagonalBottomLeftMoves(cell (*)[fieldWidth], movesList *);
|
||||
int findDiagonalTopRightMoves(cell (*)[fieldWidth], 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 *);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -54,10 +54,10 @@ int main(void)
|
|||
}
|
||||
|
||||
//pure C:
|
||||
//struct cell (*field)[fieldWidth] = malloc(fieldHeight*fieldWidth*sizeof(struct cell));
|
||||
//struct cell (*field)[fieldSize] = malloc(fieldSize*fieldSize*sizeof(struct cell));
|
||||
|
||||
//C++ version:
|
||||
auto field = new cell[fieldHeight][fieldWidth]();
|
||||
auto field = new cell[fieldSize][fieldSize]();
|
||||
|
||||
readStateBuffer(state_buffer, field); //stateBuffer ist Pointer auf char, field ist Pointer auf struct cell[]
|
||||
movesList *moves = new movesList();
|
||||
|
@ -85,7 +85,7 @@ int main(void)
|
|||
|
||||
// 3. Return result
|
||||
//send_move(turn_row, turn_col);
|
||||
//for(int i=0; i<fieldHeight; ++i)
|
||||
//for(int i=0; i<fieldSize; ++i)
|
||||
// delete [] field[i];
|
||||
delete [] field;
|
||||
delete [] moves;
|
||||
|
|
Loading…
Reference in a new issue