#ifndef KALAHA_H #define KALAHA_H /* Constants for the current player (kalaha_state.player). The value * PLAYERNONE is not allowed when calling any of the functions below, * but kalaha_end may set the current player to PLAYERNONE if no more * moves are possible. kalaha_collect will also set the current player * to PLAYERNONE. */ #define PLAYERNONE -1 /* It is no player's turn. */ #define PLAYERA 0 /* It is player A's turn. */ #define PLAYERB 1 /* It is player B's turn. */ /* These constants can be used as indices into kalaha_state.holes */ #define A1 0 #define A2 1 #define A3 2 #define A4 3 #define A5 4 #define A6 5 #define A7 6 #define B1 7 #define B2 8 #define B3 9 #define B4 10 #define B5 11 #define B6 12 #define B7 13 /* State of a Kalaha Game */ typedef struct { int player; /* Current player, either PLAYERA of PLAYERB */ int holes[14]; /* Number of pieces in each hole. */ } kalaha_state; /* Allocate and init a new Kalaha game. * start_player should be either PLAYERA or PLAYERB. */ kalaha_state * kalaha_create (int start_player); /* Check if more moves are possible for the current player. * Return Values: * 1 No more moves possible * 0 More moves possible * state->player will be set to PLAYERNONE if no more moves are possible. */ int kalaha_end (kalaha_state * state); /* Collect the remaining pieces into A7 or B7 if no more moves are possible. * This function can be called even if more moves are possible. It will * move all pieces in A1..A6 into A7 and all pieces in B1..B6 to B7. * This function will set state->player to PLAYERNONE. */ void kalaha_collect (kalaha_state * state); /* Make a kalaha move. Number is an integer in the range 1..6. * Which hole is emptied depends on the current player (state->player) * Return Values: * 0: Illeagal move * 1: Ok. * This function will also change state->player according to the rules. * This function will not detect if more moves are possible. */ int kalaha_move (kalaha_state * state, int number); /* Evaluate the situation from the perspective of the current player. * The return value measures the goodness of the current situation. * If *bestmove will suggest a move that is considered best. * depth is the number of moves that we look ahead in order to * evaluate the current situation. A good value to use here is 6. * Larger values will leed to more accurate evaluation but also to * significantly increased calculation times. Increasing the value of * depth by one will increase the calculation time by a factor of 5-10. */ int Score (kalaha_state * state, int * bestmove, int depth); #endif