/*
 * Faculty of Applied Science and Engineering, University of Toronto
 * CSC181: Introduction to Computer Programming, Fall 2000
 *
 * File: rminimax.h
 * Contains: Interface for MinimaxTPlayer, a computer player which uses
 * the minimax algorithm to play a game of Connect Four.
 * Author: Ray Ortigas (rayo@dgp.toronto.edu)
 */

#ifndef RMINIMAX_H
#define RMINIMAX_H

#include <limits.h>
#include "rtournament.h"

// Indicates a win for max (for the minimax algorithm).
#define T_MAX_WINS (INT_MAX)

// Indicates a win for min (for the minimax algorithm).
#define T_MIN_WINS (-T_MAX_WINS)

/*
 * Represents a computer player which uses the minimax algorithm to
 * play a game of Connect Four.
 */
class MinimaxTPlayer : public TPlayer {
private:
	// The depth to which this player should carry out the minimax
	// algorithm (also known as the "cutoff").
	int depth;

	/* Returns the best move for red (if redToMove is true) or black
	   (if redToMove is false) to play on board b, as determined by
	   the minimax algorithm. */
	int minimaxDecision(TBoard& b, bool redToMove);

	/* Returns the value of board b, as calculated by minimax. This
	   calculation depends on whether max (red) is to move (as
	   indicated by maxToMove) and the depth of the board
	   (currentDepth). */
	int minimaxValue(TBoard& b, bool maxToMove, int currentDepth);
	
protected:
	/* Returns the value of board b, as calculated by this
	   evaluation function. */
	int evaluate(const TBoard& b);

public:
	/* Constructs a Connect Four player which uses the minimax
	   algorithm and looks d moves ahead. */
	MinimaxTPlayer(int d) : depth(d) {}

	/* Returns the best move for this player to play on board b, as
	   determined by the minimax algorithm. The move is a number
	   between 0 and NUM_COLUMNS-1 inclusive, where NUM_COLUMNS is
	   the number of columns in board b. */
	int suggestMove(const TBoard& b);
};

#endif
