/* '='='=' '@' '='='='='='='='='=' '@' '='='='='='='='='=' '@' '='='='| */
/* ='='=' '@'@' '='='='='='='='=' '@'@' '='='='='='='='=' '@'@' '='='=| */
/* '='=' '@':'@' '='='='='='='=' '@':'@' '='='='='='='=' '@':'@' '='='| */
/* ='=' '@':':'@' '='='='='='=' '@':':'@' '='='='='='=' '@':':'@' '='=| */
/* '=' '@':':':'@' '='='='='=' '@':':':'@' '='='='='=' '@':':':'@' '='| */
/* =' '@':':':':'@' '='='='=' '@':':':':'@' '='='='=' '@':':':':'@' '=| */
/* ' '@':'                                                       '@' '| */
/*  '@'         3rd Year Project - ROY SCHESTOWITZ - 2002          @' | */
/* '@                                                               @'| */
/* @':':':':':':':':'@' ' '@':':':':':':':':'@' ' '@':':':':':':':':'@| */
/* ':':':':':':':':':'@' '@':':':':':':':':':'@' '@':':':':':':':':':'| */
/* :':':':':':':':':':'@'@':':':':':':':':':':'@'@':':':':':':':':':':| */
/* ':':':': : :':':':':'@':':':':': : :':':':':'@':':':':': : :':':':'| */
/*  -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
/*              Name:           computation.h                           */
/*              Version:        0.6.6                                   */
/*              Date:           12/2/2003                               */
/*                                                                      */
/*              Datastructures for the main procedure to compute a      */
/*              smart move in the game                                  */
/*                                                                      */
/*  -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */

/************************************************************************/
/**********************  INCLUDES  **************************************/
/************************************************************************/


/************************************************************************/
/**********************  DEFINES  ***************************************/
/************************************************************************/

/************************** Line values *******************************/
//The following definition are followed by a map showing position X in
//the upper left side of the board

/*==================*/
/** Straight lines **/
/*==================*/

#define LINE_STRAIGHT_EDGE              5

//  X***
//  X***
//  X***
//  X***

#define LINE_STRAIGHT_NEAR_EDGE         3

//  *X**
//  *X**
//  *X**
//  *X**

#define LINE_STRAIGHT_NEAR_MIDDLE       2

//  **X*
//  **X*
//  **X*
//  **X*

#define LINE_STRAIGHT_MIDDLE            2

//  ***X
//  ***X
//  ***X
//  ***X


/*==================*/
/** Diagonal lines **/
/*==================*/

#define LINE_DIAGONAL_MIDDLE                            5

//  X*******
//  *X******
//  **X*****
//  ***X****
//  ****X***
//  *****X**
//  ******X*
//  *******X

#define LINE_DIAGONAL_NEAR_MIDDLE                       4

//  ********
//  X*******
//  *X******
//  **X*****
//  ***X****
//  ****X***
//  *****X**
//  ******X*

#define LINE_DIAGONAL_BETWEEN_MIDDLE_AND_CORNER         3

//  ********
//  ********
//  X*******
//  *X******
//  **X*****
//  ***X****
//  ****X***
//  *****X**

#define LINE_DIAGONAL_NEAR_CORNER                       2

//  ********
//  ********
//  ********
//  X*******
//  *X******
//  **X*****
//  ***X****
//  ****X***

#define LINE_DIAGONAL_CORNER                            1

//  ********
//  ********
//  ********
//  ********
//  X*******
//  *X******
//  **X*****
//  ***X****

/*=============================*/
/** Incomplete Straight lines **/
/*=============================*/

#define INCOMPLETE_LINE_STRAIGHT_EDGE           4

//  ****
//  X***
//  X***
//  X***
//  X***
//  X***
//  X***
//  X***
//
//   OR
//
//  X***
//  X***
//  X***
//  X***
//  X***
//  X***
//  X***
//  ****

#define INCOMPLETE_LINE_STRAIGHT_NEAR_EDGE      3

//  ****
//  *X**
//  *X**
//  *X**
//  *X**
//  *X**
//  *X**
//  *X**
//
//   OR
//
//  *X**
//  *X**
//  *X**
//  *X**
//  *X**
//  *X**
//  *X**
//  ****

#define INCOMPLETE_LINE_STRAIGHT_NEAR_MIDDLE    2

//  ****
//  **X*
//  **X*
//  **X*
//  **X*
//  **X*
//  **X*
//  **X*
//
//   OR
//
//  **X*
//  **X*
//  **X*
//  **X*
//  **X*
//  **X*
//  **X*
//  ****

#define INCOMPLETE_LINE_STRAIGHT_MIDDLE         2

//  ****
//  ***X
//  ***X
//  ***X
//  ***X
//  ***X
//  ***X
//  ***X
//
//   OR
//
//  ***X
//  ***X
//  ***X
//  ***X
//  ***X
//  ***X
//  ***X
//  ****



/*=============================*/
/** Incomplete Diagonal lines **/
/*=============================*/

#define INCOMPLETE_LINE_DIAGONAL_MIDDLE                         5

//  X*******
//  *X******
//  **X*****
//  ***X****
//  ****X***
//  *****X**
//  ******X*
//  ********
//
//    OR
//
//  ********
//  *X******
//  **X*****
//  ***X****
//  ****X***
//  *****X**
//  ******X*
//  *******X

#define INCOMPLETE_LINE_DIAGONAL_NEAR_MIDDLE                    4

//  ********
//  X*******
//  *X******
//  **X*****
//  ***X****
//  ****X***
//  *****X**
//  ********
//
//    OR
//
//  ********
//  ********
//  *X******
//  **X*****
//  ***X****
//  ****X***
//  *****X**
//  ******X*
#define INCOMPLETE_LINE_DIAGONAL_BETWEEN_MIDDLE_AND_CORNER      3

//  ********
//  ********
//  X*******
//  *X******
//  **X*****
//  ***X****
//  ****X***
//  ********
//
//    OR
//
//  ********
//  ********
//  ********
//  *X******
//  **X*****
//  ***X****
//  ****X***
//  *****X**

#define INCOMPLETE_LINE_DIAGONAL_NEAR_CORNER                    2

//  ********
//  ********
//  ********
//  X*******
//  *X******
//  **X*****
//  ***X****
//  ********
//
//    OR
//
//  ********
//  ********
//  ********
//  ********
//  *X******
//  **X*****
//  ***X****
//  ****X***

#define INCOMPLETE_LINE_DIAGONAL_CORNER                         1

//  ********
//  ********
//  ********
//  ********
//  ********
//  *X******
//  **X*****
//  ***X****
//
//    OR
//
//  ********
//  ********
//  ********
//  ********
//  X*******
//  *X******
//  **X*****
//  ********



/************************** Position values *******************************/
//The following definition are followed by a map showing position X in
//the upper left side of the board

#define CORNER_POS                      10000

//  X***
//  ****
//  ****
//  ****

#define SIDE_MIDDLE_POS                 800

//  ***X
//  ****
//  ****
//  X***

#define SIDE_FAR_POS                    1000

//  **X*
//  ****
//  X***
//  ****

#define MIDDLE_4_POS                    50

//  ****
//  ****
//  ****
//  ***X

#define MIDDLE_8_POS                    10

//  ****
//  ****
//  ***X
//  **X*

#define MIDDLE_DIAGONAL_4_POS           30

//  ****
//  ****
//  **X*
//  ****

#define NEAR_SIDES_MIDDLE_POS           -500

//  ****
//  ***X
//  ****
//  *X**

#define NEAR_SIDES_FAR_POS              -450

//  ****
//  **X*
//  *X**
//  ****

#define DIAGONAL_NEAR_CORNER_POS        -5000

//  ****
//  *X**
//  ****
//  ****

#define SIDES_NEAR_CORNER_POS           -3000

//  *X**
//  X***
//  ****
//  ****



/***************************/
/** Evaluation activators **/
/***************************/

#define EVALUATE_POSITION_ACTIVE                        1
// sets the evaluation by positions of stones

#define EVALUATE_MOBILITY_ACTIVE                        1
// sets the evaluation by mobility difference

#define EVALUATE_SCORE_ACTIVE                           1
// sets the evaluation by score difference

#define EVALUATE_LINES_ACTIVE                           1
// sets the evaluation by control of lines


/********************************/
/** Line evaluation activators **/
/********************************/

#define STRAIGHT_COMPLETE_LINES_ACTIVE                  1
// complete straight lines

#define DIAGONAL_COMPLETE_LINES_ACTIVE                  1
// complete diagonal lines

#define STRAIGHT_INCOMPLETE_LINES_ACTIVE                1
// incomplete straight lines

#define DIAGONAL_INCOMPLETE_LINES_ACTIVE                1
// incomplete diagonal lines


/************************************************/
/********* Evaluation Coefficients **************/
/************************************************/

#define SCORE_COEFFICIENT                               50
// defines the number of points a score unit is worth

#define MOBILITY_COEFFICIENT                            70
// defines the number of points a mobility unit is worth

#define POSITION_VALUE_COEFFICIENT                      1
// defines the coefficient of a given position value

#define LINE_STATE_COEFFICIENT                          1
// defines the coefficient of a lines value

/************************/
/** Lines coefficients **/
/************************/

#define LINING_COEFFICIENT_STRAIGHT_COMPLETE            12
// defines the coefficient of a given straight line layout value

#define LINING_COEFFICIENT_DIAGONAL_COMPLETE            10
// defines the coefficient of a given diagonal line layout value

#define LINING_COEFFICIENT_STRAIGHT_INCOMPLETE          5
// defines the coefficient of a given straight incomplete line layout value

#define LINING_COEFFICIENT_DIAGONAL_INCOMPLETE          4
// defines the coefficient of a given diagonal incomplete line layout value

/******************/
/** Width search **/
/******************/


#define MOVE_FACTOR                                     100
// the initial factor for a given possible move

#define MOVE_FACTOR_DIVIDER                             10
// the dynamic behaviour of the factor - the speed it grows smaller

#define MOVES_UPPER_BOUND                               60
// defines the upper bound of moves available

#define SCORE_LOWER_BOUND                               -10000000
// defines the minimum score obtainable - lower bound

/************************/
/** Randomisation keys **/
/************************/

#define BEGINNER_RANDOMISATION_KEY                      4
// Defines the number N which in the expression N/100 defines the chance
// that a given move will be taken in the difficulty beginner
// it also defines the maximum offset (pre-cent) added to an evaluation

#define NOVICE_RANDOMISATION_KEY                        5
// Defines the maximum offset (pre-cent) added to an evaluation
// when the the current difficulty is novice

#define EXPERT_RANDOMISATION_KEY                        4
// Defines the maximum offset (pre-cent) added to an evaluation
// when the the current difficulty is expert

#define PRE_MASTER_RANDOMISATION_KEY                    6
// Defines the maximum offset (pre-cent) added to an evaluation
// when the the current difficulty is pre-master

#define MASTER_RANDOMISATION_KEY                        6
// Defines the maximum offset (pre-cent) added to an evaluation
// when the the current difficulty is master

/************************/
/** Opening Library    **/
/************************/

#define  OPENING_LIBRARY_HASH_SIZE                      50
//The size of the hashtable that stores the opening library


/************************************************************************/
/**********************  DATA STRUCTURES  *******************************/
/************************************************************************/

typedef struct
{
  int score;
  int i;
  int j;
}
move_score;

/************************************************************************/
/**********************  PROTOTYPES  ************************************/
/************************************************************************/

/*******************/
/** Main routines **/
/*******************/

void cpu_move ( int color );
board_map compute_move_for_color ( board_map inputboard, int color );
board_map make_nth_best_move ( board_map inputboard, int color,
			       int priority );

/******************/
/** Calculations **/
/******************/

int calculate_mobility_difference_of_board ( board_map inputboard,
					     int color );
int calculate_score_difference_of_board ( board_map inputboard, int color );
int get_mobility_of_color ( board_map inputboard, int color );

/******************/
/** Evaluations  **/
/******************/

int find_value_of_position ( int i, int j, int color );
int evaluate ( int, board_map );
int evaluate_lines ( board_map input_board, int color );

/***************************/
/** Specific evaluations  **/
/***************************/

int evaluate_straight_lines_complete ( board_map input_board, int color );
int evaluate_diagonal_lines_complete ( board_map input_board, int color );
int evaluate_straight_lines_incomplete ( board_map input_board, int color );
int evaluate_diagonal_lines_incomplete ( board_map input_board, int color );


/************/
/** Misc.  **/
/************/

int zero_one_random ( void );
int random_number ( int N );
void init_opening_library ( void );
char *find_board_state_ident ( void );
int load_opening_library_file ( char *filename );

/*                                                                      */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  */
/*                     end of computation.h                             */
/************************************************************************/

