...
 
Commits (2)
......@@ -5,27 +5,52 @@
#define DEBUG 1
#define PLAYER_STONES 6
struct Stone {
int position; // where a stone is at right now
bool notInPlay;
bool finished;
Stone() : notInPlay(true), finished(false), position(0) {};
};
struct Player {
short score; // defaults o 0
short saturation; // their colour
int stones[6];
Stone* stones;
unsigned int field;
char* name;
Player();
Player(unsigned int field, char* name) : field(field), score(0), name(name) {};
};
struct Stone {
int position; // where a stone is at right now
Player(unsigned int field, char* name) : field(field), score(0), name(name) {
for(int i=0; i < PLAYER_STONES; i++) {
stones[i] = Stone();
}
};
};
struct Game {
int numberOfTurns;
int playingField;
int dice;
int diceValue;
Game() : numberOfTurns(0), playingField(0) {};
void throwDice();
};
void Game::throwDice() {
dice = 0;
diceValue = 0;
for (int i = 0; i < 4; i++ ) {
dice = (dice << 1) | (rand() % 2);
if (dice & 0b1) {
diceValue++;
}
}
#ifdef DEBUG
printf("Thrown dice: %s: %i\n", decimal_to_binary(dice, 4), diceValue);
#endif
}
// two bit masks to with the board layout for each player
// starts with the each player's four outer fields, followed
// by the eight shared field and again each player's two outer finish fields
......@@ -40,29 +65,15 @@ const unsigned int protectedFields = 0b1111111110001; // it's just one field in
Game game;
int diceValue(int dice) {
if(dice > 0) {
return diceValue(dice >> 1) + (dice & 0b1);
}
return 0;
}
Stone* possibleMoves(Player player) {
void throwDice( int dice) {
dice = 0;
for (int i = 0; i < 4; i++ ) {
dice = (dice << 1) | (rand() % 2);
}
#ifdef DEBUG
printf("Thrown dice: %s: %i\n", decimal_to_binary(dice, 4), diceValue(dice));
#endif
}
int turn(Player player) {
void turn(Player player) {
#ifdef DEBUG
printf("New turn #%i for %s\n", game.numberOfTurns, player.name);
#endif
static int dice;
throwDice(dice);
game.throwDice();
// wait for user input
}
......