#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include "othello.h"


void     replay_moves();
int      ABminimize();
int      ABmaximize();
int      endvalue();
void     dump_movelist();
void     dumpstate();



/*
 * Reset 'state' and redo the moves from zero to currentmove. This
 * is used when the user wants to undo a move.
 */

void    replay_moves(state, moves, currentmove)
State      *state;
Savemove   moves[];
int        currentmove;
{
    int   i;

    reuse_positions(state->fertile);
    reuse_positions(state->alive);
    resetstate(state);

    for (i = 0; i < currentmove; ++i)
	(void) do_move(state, moves[i].pos, moves[i].color, FALSE);
}



/*
 * Do a move in the position embedded in 'move'. If the remaining
 * search level 'level' is deeper than 1, then continue the minimax
 * search by calling ABmaximize().
 */




/*
 * Do a move in the position embedded in 'move'. If the remaining
 * search level 'level' is deeper than 1, then continue the minimax
 * search by calling ABminimize().
 */

/*
 * Print a movelist. Only used for debugging purposes.
 */

void dump_movelist(movelist)
Move   *movelist;
{
    Move   *mv;

    printf("pos: ");
    for (mv = movelist; mv != NULL; mv = mv->next)
	printf("  %c%c", COL(mv->pos) + 'A' - 1, ROW(mv->pos) + '0');
    putchar('\n');
    printf("val: ");
    for (mv = movelist; mv != NULL; mv = mv->next)
	printf("%4d", mv->val);
    putchar('\n');
}


/**************************** State ****************************/





/*
 * Print the contents of 'state'. Only used for debugging purposes.
 */

void   dumpstate(state)
State   *state;
{
    print_board(&(state->board[0]));
    printf("mydead = %d\tyourdead = %d\n", state->mydead, state->yourdead);
    printf("alive = ");
    printlist(state->alive);
    printf("\nfertile = ");
    printlist(state->fertile);
    putchar('\n');
    putchar('\n');
}


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

Here follows the pieces of code that has to do with the edge tables:

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

From the State struct in othello.h:

    int      row1index;
    int      row8index;
    int      col1index;
    int      col8index;


From do_move in lowlevel.c (line 150):

	/* Check if the move was on an edge. */
	if (ROW(sq) == 1)
	    state->row1index = get_edgeindex_row1(state);
	if (ROW(sq) == 8)
	    state->row8index = get_edgeindex_row8(state);
	if (COL(sq) == 1)
	    state->col1index = get_edgeindex_col1(state);
	if (COL(sq) == 8)
	    state->col8index = get_edgeindex_col8(state);

From resetstate in lowlevel.c (line 376):


    state->row1index = 0;
    state->row8index = 0;
    state->col1index = 0;
    state->col8index = 0;

From function statevalue in highlevel.c (line 557):

    /* The general case: evaluate the two main factors, */
    /* stable pieces and mobility. */
    if (color == MYCOLOR)
	val += edgeval_you_to_move[state->row1index]
	    +  edgeval_you_to_move[state->row8index]
	    +  edgeval_you_to_move[state->col1index]
	    +  edgeval_you_to_move[state->col8index];
    else 
	val += edgeval_me_to_move[state->row1index]
	    +  edgeval_me_to_move[state->row8index]
	    +  edgeval_me_to_move[state->col1index]
	    +  edgeval_me_to_move[state->col8index];

From before statevalue:

int   value_board[] = {
      0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
      0,   0, -20,  19,  13,  13,  19, -20,   0,   0,
      0, -20, -1020,  -8, -10, -10,  -8, -1020, -20,   0,
      0,  19,  -8,   0,   0,   0,   0,  -8,  19,   0,
      0,  13, -10,   0,   0,   0,   0, -10,  13,   0,
      0,  13, -10,   0,   0,   0,   0, -10,  13,   0,
      0,  19,  -8,   0,   0,   0,   0,  -8,  19,   0,
      0, -20, -1020,  -8, -10, -10,  -8, -1020, -20,   0,
      0,   0, -20,  19,  13,  13,  19, -20,   0,   0,
      0,   0,   0,   0,   0,   0,   0,   0,   0,   0
};

Also from before statevalue:

int    stabilityvalue = 100;	/* value per stable piece */
int    mobilityvalue = 6000;	/* max total value for mobility  */
#define XSQVAL   1500

struct {
    int   corner;
    int   x_square;
} xsq[] = {
    {11, 22},
    {18, 27},
    {81, 72},
    {88, 77}
};

int   xpoints[9] = { 
    0, -XSQVAL, XSQVAL,		/* The corner empty. */
    0,	     0,      0,		/* My piece in the corner. */
    0,	     0,      0		/* Your piece in the corner. */
}; 


From statevalue:

    /* If the x square is occupied, but not the corner, add some points. */
    for (i = 0; i < 4; ++i)
	val += xpoints[state->board[xsq[i].corner] * 3 
		       + state->board[xsq[i].x_square]];

    /* If the x square is occupied, but not the corner, add some points. */
    for (i = 0; i < 4; ++i)
	val += xpoints[state->board[xsq[i].corner] * 3 
		       + state->board[xsq[i].x_square]];

From main:

    init_edgevals();

