main.cpp 2.03 KB
Newer Older
Thomas R. Koll's avatar
Thomas R. Koll committed
1
2
3
#include <stdio.h>      /* printf, scanf, puts, NULL */
#include <stdlib.h>     /* srand, rand */
#include <time.h>       /* time */
4
#include "decimal_to_binary.h"
Thomas R. Koll's avatar
Thomas R. Koll committed
5
6
7

#define DEBUG 1

Thomas R. Koll's avatar
Thomas R. Koll committed
8

Thomas R. Koll's avatar
Thomas R. Koll committed
9
10
11
12
13
struct Player {
  short score; // defaults o 0
  short saturation; // their colour
  int stones[6];
  unsigned int field;
Thomas R. Koll's avatar
Thomas R. Koll committed
14
  char* name;
Thomas R. Koll's avatar
Thomas R. Koll committed
15
  Player();
Thomas R. Koll's avatar
Thomas R. Koll committed
16
  Player(unsigned int field, char* name) : field(field), score(0), name(name) {};
Thomas R. Koll's avatar
Thomas R. Koll committed
17
18
19
20
21
22
};

struct Stone {
  int position; // where a stone is at right now
};

23
24
25
struct Game {
  int numberOfTurns;
  int playingField;
26
27
  int dice;
  int diceValue;
28
  Game() : numberOfTurns(0), playingField(0) {};
29
  void throwDice();
30
31
};

32
33
34
35
36
37
38
39
40
41
42
43
44
45
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
}

Thomas R. Koll's avatar
Thomas R. Koll committed
46
47
48
49
50
51
52
53
54
55
56
57
// 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
//
// 1  2  3  4       18 17
// 9 10 11 12 13 14 15 16
// 5  6  7  8       20 19

const unsigned int playerOneField = 0b11110000111111111100;
const unsigned int playerTwoField = 0b00001111111111110011;
const unsigned int protectedFields = 0b1111111110001; // it's just one field in the middle

58
59
Game game;

60
Stone* possibleMoves(Player player) {
61

Thomas R. Koll's avatar
Thomas R. Koll committed
62
63
}

64
void turn(Player player) {
65
    #ifdef DEBUG
Thomas R. Koll's avatar
Thomas R. Koll committed
66
      printf("New turn #%i for %s\n", game.numberOfTurns, player.name);
67
    #endif
68
  game.throwDice();
69
70
71
  // wait for user input
}

Thomas R. Koll's avatar
Thomas R. Koll committed
72
73
74
75
int moveStone(Player player, Stone stone, int value) {
}

int main() {
76
  game = Game();
Thomas R. Koll's avatar
Thomas R. Koll committed
77
  srand (time(NULL));
Thomas R. Koll's avatar
Thomas R. Koll committed
78
79
  Player playerOne(playerOneField, (char*) "One");
  Player playerTwo(playerTwoField, (char*) "Two");
80
81
82
83
84
85
86
  #ifdef DEBUG
    printf("Starting game...\n");
  #endif
  while(playerOne.score < 6 && playerTwo.score < 6 && game.numberOfTurns < 100) {
    game.numberOfTurns++;
    turn(game.numberOfTurns % 2 ? playerOne : playerTwo);
  }
Thomas R. Koll's avatar
Thomas R. Koll committed
87
}