Unverified Commit 8fe9feb8 authored by Thomas R. Koll's avatar Thomas R. Koll
Browse files

Add binary printout for dice

parent 2e86d132
......@@ -4,13 +4,33 @@
#define DEBUG 1
/** returns pointer to binary representation of 'n' zero padded to 'sz'.
* returns pointer to string contianing binary representation of
* unsigned 64-bit (or less ) value zero padded to 'sz' digits.
* https://stackoverflow.com/questions/32488011/printing-the-binary-representation-of-a-number#
*/
char *binpad (unsigned long n, size_t sz);
char *binpad (unsigned long n, size_t sz)
{
static char s[32 + 1] = {0};
char *p = s + 32;
register size_t i;
for (i = 0; i < sz; i++)
*--p = (n>>i & 1) ? '1' : '0';
return p;
}
struct Player {
short score; // defaults o 0
short saturation; // their colour
int stones[6];
unsigned int field;
Player();
Player(unsigned int field) : field(field) {};
Player(unsigned int field) : field(field), score(0) {};
};
struct Stone {
......@@ -34,8 +54,8 @@ void throwDice( int dice) {
for (int i = 0; i < 3; i++ ) {
dice = (dice << 1) | (rand() % 2);
}
#ifdef DEBUG
printf("Thrown dice: %b", dice);
#ifdef DEBUG
printf("Thrown dice: %s\n", binpad(dice, 4));
#endif
}
......@@ -46,6 +66,6 @@ int main() {
srand (time(NULL));
Player playerOne(playerOneField);
Player playerTwo(playerTwoField);
trowDice();
trowDice();
static int dice;
throwDice(dice);
}
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