Move the whole dice throwing into the Game struct

parent b0c92b76
......@@ -23,9 +23,26 @@ struct 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 +57,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
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment