#define SQUARES_ON_BOARD (16*16)
#define BITS_PER_BYTE 8
typedef int h_bitset[SQUARES_ON_BOARD /
(sizeof(unsigned int) * BITS_PER_BYTE)];
typedef struct {
h_bitset occupied;
h_bitset colour;
} h_board;
#define SQUARES_ON_BOARD (16*16)
#define BITS_PER_BYTE 8
#define PEGS_PER_COLOUR 19
#define WHITE 0
#define BLACK 1
#define NO_PLAYERS 2
typedef int h_bitset[SQUARES_ON_BOARD /
(sizeof(unsigned int) * BITS_PER_BYTE)];
typedef struct {
h_bitset occupied;
h_bitset colour;
unsigned char position[NO_PLAYERS][PEGS_PER_COLOUR];
} h_board;
void board_init (h_board *b)
{
add_piece (b, WHITE, 0, 0);
add_piece (b, WHITE, 1, 1);
add_piece (b, WHITE, 2, 2);
add_piece (b, WHITE, 3, 3);
add_piece (b, WHITE, 4, 16);
add_piece (b, WHITE, 5, 17);
add_piece (b, WHITE, 6, 18);
add_piece (b, WHITE, 7, 32);
add_piece (b, WHITE, 8, 33);
add_piece (b, WHITE, 9, 34);
add_piece (b, WHITE, 10, 48);
add_piece (b, WHITE, 11, 49);
add_piece (b, WHITE, 12, 50);
add_piece (b, WHITE, 13, 64);
add_piece (b, WHITE, 14, 65);
}
void add_piece (h_board *b, int colour, int piece, int square)
{
INCL(b->occupied, square);
if (colour == WHITE)
EXCL(b->colour, square);
else
INCL(b->colour, square);
b->position[piece] = square;
}
void INCL (h_bitset *b, int element)
{
int array_element = element/(sizeof(unsigned int)
* BITS_PER_BYTE);
int bit_in_element = element % sizeof(unsigned int);
b[array_element] |= (1 << bit_in_element);
}
void EXCL (h_bitset *b, int element)
{
int array_element = element/(sizeof(unsigned int)
* BITS_PER_BYTE);
int bit_in_element = element % sizeof(unsigned int);
b[array_element] &= (! (1 << bit_in_element));
}
int IS_IN (h_bitset *b, int element)
{
int array_element = element/(sizeof(unsigned int)
* BITS_PER_BYTE);
int bit_in_element = element % sizeof(unsigned int);
return (b[array_element] & (1 << bit_in_element)) != 0;
}
This document was produced using groff-1.19.