parsing state_buffer into an 2d array
This commit is contained in:
parent
b344e39e82
commit
a063a74537
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -4,3 +4,4 @@ my-player
|
||||||
example-player
|
example-player
|
||||||
random-player
|
random-player
|
||||||
othello
|
othello
|
||||||
|
*.swp
|
||||||
|
|
2
Makefile
2
Makefile
|
@ -28,6 +28,8 @@ else
|
||||||
CXXFLAGS += -Weverything -Wno-padded -Wno-weak-vtables
|
CXXFLAGS += -Weverything -Wno-padded -Wno-weak-vtables
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
CFLAGS += -I. -g
|
||||||
|
|
||||||
all : $(TARGETS)
|
all : $(TARGETS)
|
||||||
|
|
||||||
othello : $(SRC_common:.cc=.o) $(ASM_common:.S=.o)
|
othello : $(SRC_common:.cc=.o) $(ASM_common:.S=.o)
|
||||||
|
|
|
@ -16,4 +16,18 @@ getEnemyChar(char c) {
|
||||||
enemyc='X'; break;
|
enemyc='X'; break;
|
||||||
}
|
}
|
||||||
return enemyc;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -1,9 +1,16 @@
|
||||||
#ifndef PLAYERLIB_H
|
#ifndef PLAYERLIB_H
|
||||||
#define PLAYERLIB_H
|
#define PLAYERLIB_H
|
||||||
|
|
||||||
|
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
|
||||||
|
struct cell {
|
||||||
|
char content = '.';
|
||||||
|
unsigned short int timesVisited = 0;
|
||||||
|
};
|
||||||
|
|
||||||
//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
|
||||||
|
extern int readStateBuffer(char*, cell (*)[fieldWidth]);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -19,7 +19,6 @@ send_move(int row, int col)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
int done = 0;
|
int done = 0;
|
||||||
|
@ -49,8 +48,18 @@ int main(void)
|
||||||
if(!enemyc)
|
if(!enemyc)
|
||||||
enemyc = getEnemyChar(state_buffer[0]);
|
enemyc = getEnemyChar(state_buffer[0]);
|
||||||
|
|
||||||
|
//pure C:
|
||||||
|
//struct cell (*field) = malloc(fieldHeight*fieldWidth*sizeof(struct cell));
|
||||||
|
|
||||||
|
//C++ version:
|
||||||
|
auto field = new cell[fieldHeight][fieldWidth]();
|
||||||
|
printf("%p\n", field);
|
||||||
|
|
||||||
|
readStateBuffer(state_buffer, field);
|
||||||
|
|
||||||
// 3. Return result
|
// 3. Return result
|
||||||
//send_move(turn_row, turn_col);
|
//send_move(turn_row, turn_col);
|
||||||
|
delete field;
|
||||||
|
|
||||||
/* END PLAYER-SPECIFIC CODE */
|
/* END PLAYER-SPECIFIC CODE */
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue