/*
 * File: othello.h
 *
 * This file declares most of the data structures used in GNU Othello.
 * It also declares many functions in highlevel.c and lowlevel.c
 * as extern.
 */


/* A simple boolean type */
#ifndef bool
#define bool   int
#endif
#ifndef FALSE
#define FALSE  0
#define TRUE   1
#endif


/* ================================================================ */
/*     Definition of and operations on the abstract type 'Color'    */


typedef   unsigned char  Color;	/* Is int perhaps faster??? */

/* Colors used in the user interface. */
#define   WHITE          0
#define   BLACK          1

/* Colors used in the thinking part of the program. */
#define   EMPTY          0	/* color of an empty square */
#define   MYCOLOR        1	/* color of the machine's pieces */
#define   YOURCOLOR      2	/* color of the human's pieces */
#define   OTHER(color)   (3 - (color))


/* The border is marked with a color that is both MY and YOUR */
/* since this will make more efficient searches. */
#define   BORDER     (MYCOLOR | YOURCOLOR)

/* Some special values for use in the alfa-beta search. */
#define   VERY_GOOD     100000	/* used for a winning position */
#define   VERY_BAD     -100000	/* used for a losing position */
#define   INFINITY      999999	/* used as init value in searches */


/* ================================================================ */

#include "sqlist.h"


/* ================================================================ */
/*                  Definition of the type 'Board'                  */

/*
 * A Board consists not only of the playing area itself but also
 * of the border which surrounds it.  The playing area is 8x8 and
 * the border takes up one square at each side.  Thus the total
 * area of the board is 10x10 or 100.
 */

typedef Color   Board[100];


/* ================================================================ */
/*                    Definition of the type 'State'                */

/*
 * A State captures most of the aspects of a position.  In addition
 * to the board the following properties are kept in a State to
 * speed up the evaluation process:
 *   Sqlist   neighbors    - A list of all empty squares which are
 *                           directly adjacent to an occupied square
 *                           on the board.
 *   Sqlist   stablepieces - A list of the stable pieces on the board.
 *                           These are the pieces that can never again
 *                           be turned, regardless of color.
 *   int      mystable     - The number of stable pieces the computer owns.
 *   int      yourstable   - The number of stable pieces the human owns.
 */

typedef struct {
    Board    board;
    Sqlist   neighbors;
    Sqlist   stablepieces;
    int      mystable;
    int      yourstable;
} State;


/* ================================================================ */
/*                  Definition of the type 'Move'                   */

/*
 * A Move is used in the search procedures get_best_move(), ABminimize()
 * and ABmaximize to hold data associated with a position which 
 * appears after a move has been done in a previous position. Moves
 * often appear in linked lists.
 *
 * The Move structure consists of the following parts:
 *   Square   sq           - The square the move was made to.
 *   int      val          - The value of the resulting position.
 *   State    state        - The resulting state after the move.
 *   Sqlist   legal_moves  - A list of legal moves from here for the
 *                           side which did NOT make the original move.
 *   Move   * next         - A pointer to the next Move in the list.
 */

typedef struct move_t {
    Square          sq;
    int             val;
    State           state;
    Sqlist          legal_moves;
    struct move_t   *next;
} Move;


/* ================================================================ */
/*                 Definition of the type 'Savemove'                */

/*
 * The Savemove struct is used to record moves done throughout the
 * game. It is solely used for being able to undo moves and in the
 * future to save games to file.
 */

typedef struct {
    Square   sq;
    Color    color;
} Savemove;


/* ================================================================ */
/*	       Declarations of functions in highlevel.c             */


extern Square   get_best_move();
extern int      ABminimize();
extern int      ABmaximize();
extern Move   * do_legal_moves();
extern Move   * sort_moves();
extern Move   * sort_move();
extern Move   * alloc_move();
extern void     reuse_moves();
extern int      statevalue();
extern int      endvalue();


/* ================================================================ */
/*	       Declarations of functions in lowlevel.c              */


/*
 * Copy the state FROM into the state TO. Also make copies
 * of all lists.
 */

#define copy_state(from, to) \
    bcopy((char *)from, (char *)to, sizeof(State));

extern bool    game_ended();
extern bool    can_move();
extern bool    do_move();
extern void    check_stability();
extern bool    stable_half_row();
extern void    get_legal_moves();
extern int     num_legal_moves();
extern void    resetstate();
extern void    count_pieces();
