#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');
}
