begin work on strategic my-player
numX, numO contains number of X/O stones
This commit is contained in:
parent
27d563173e
commit
76981af571
2
Makefile
2
Makefile
|
@ -40,7 +40,7 @@ othello : $(SRC_mcp:.cc=.o)
|
|||
example-player: players/example-player.o
|
||||
$(CXX) $^ -o $@ $(LDFLAGS)
|
||||
|
||||
my-player : players/my-player.o
|
||||
my-player : players/my-player.o players/playerlib.o
|
||||
$(CXX) $^ -o $@ $(LDFLAGS)
|
||||
|
||||
random-player : players/random-player.o players/playerlib.o
|
||||
|
|
|
@ -1,13 +1,17 @@
|
|||
/* -*- Mode: C -*- */
|
||||
#define debugprint
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <mcp.h>
|
||||
|
||||
#include "playerlib.h"
|
||||
|
||||
static int
|
||||
send_move(int row, int col)
|
||||
{
|
||||
|
@ -21,6 +25,7 @@ send_move(int row, int col)
|
|||
int main(void)
|
||||
{
|
||||
int done = 0;
|
||||
srandom(time(NULL));
|
||||
|
||||
while (!done) {
|
||||
int turn_row = 0;
|
||||
|
@ -44,6 +49,34 @@ int main(void)
|
|||
|
||||
// 2. TODO: Strategie hier einfügen. Resultat in turn_row und turn_col speichern.
|
||||
|
||||
//number of stones of X/O
|
||||
unsigned int numX=0, numO=0; //TODO: make it a property of field struct
|
||||
if(!enemyc)
|
||||
{
|
||||
ownc = state_buffer[0];
|
||||
enemyc = getEnemyChar(ownc);
|
||||
}
|
||||
|
||||
auto field = new cell[fieldSize][fieldSize]();
|
||||
readStateBuffer(state_buffer, field, &numX, &numO); //stateBuffer ist Pointer auf char, field ist Pointer auf struct cell[]
|
||||
movesList *moves = new movesList();
|
||||
|
||||
findMoves(field, moves);
|
||||
if(!moves->movesNumber)
|
||||
{
|
||||
turn_row=0;
|
||||
turn_col=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
#ifdef debugprint
|
||||
printf("numX: %d, numO: %d\n", numX, numO);
|
||||
#endif
|
||||
|
||||
// 3. Return result
|
||||
send_move(turn_row, turn_col);
|
||||
|
||||
|
|
|
@ -39,13 +39,17 @@ getEnemyChar(char c) {
|
|||
}
|
||||
|
||||
int
|
||||
readStateBuffer(char *stateBuffer, struct cell (*gameField)[fieldSize]) {
|
||||
readStateBuffer(char *stateBuffer, struct cell (*gameField)[fieldSize], unsigned int *numX, unsigned int *numO) {
|
||||
for(size_t row=0; row < fieldSize; ++row)
|
||||
{
|
||||
for(size_t col=0; col< fieldSize; ++col)
|
||||
{
|
||||
int index = row*fieldSize+col+1;
|
||||
gameField[row][col].content = stateBuffer[index];
|
||||
if (stateBuffer[index] == 'X')
|
||||
++(*numX);
|
||||
if (stateBuffer[index] == 'O')
|
||||
++(*numO);
|
||||
#ifdef debugprint
|
||||
//printf("gameField %lu %lu =stateBuffer %d = %c\n", row, col, index, gameField[row][col].content);
|
||||
#endif
|
||||
|
|
|
@ -22,7 +22,7 @@ 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 (*)[fieldSize]);
|
||||
extern int readStateBuffer(char*, cell (*)[fieldSize], unsigned int *, unsigned int *);
|
||||
|
||||
//iterates through field in all directions, stores moves into movesList
|
||||
int findMoves(cell (*)[fieldSize], movesList *);
|
||||
|
|
|
@ -50,6 +50,9 @@ int main(void)
|
|||
|
||||
// 2. TODO: Strategie hier einfügen. Resultat in turn_row und turn_col speichern.
|
||||
|
||||
//number of stones of X/O
|
||||
unsigned int numX=0, numO=0; //TODO: make it a property of field struct
|
||||
|
||||
if(!enemyc)
|
||||
{
|
||||
ownc = state_buffer[0];
|
||||
|
@ -62,7 +65,7 @@ int main(void)
|
|||
//C++ version:
|
||||
auto field = new cell[fieldSize][fieldSize]();
|
||||
|
||||
readStateBuffer(state_buffer, field); //stateBuffer ist Pointer auf char, field ist Pointer auf struct cell[]
|
||||
readStateBuffer(state_buffer, field, &numX, &numO); //stateBuffer ist Pointer auf char, field ist Pointer auf struct cell[]
|
||||
movesList *moves = new movesList();
|
||||
|
||||
findMoves(field, moves);
|
||||
|
|
Loading…
Reference in a new issue