/*
 * Faculty of Applied Science and Engineering, University of Toronto
 * CSC181: Introduction to Computer Programming, Fall 2000
 *
 * File: tournament.h
 * Contains: Interface for Connect Four modules (for tournament play).
 * Author: Ray Ortigas (rayo@dgp.toronto.edu)
 */

#ifndef TOURNAMENT_H
#define TOURNAMENT_H

#define T_NUM_ROWS (6)
#define T_NUM_COLUMNS (7)
#define T_NUM_TO_CONNECT (4)

class TPlayer;
struct TPosition;
class TBoard;

/*
 * Represents a Connect Four player.
 */
class TPlayer {
public:
	/* Asks this player to analyze the given board, and returns
	   the move suggested by the player. */
	virtual int suggestMove(const TBoard& b) = 0;
};

/*
 * Represents a position on a Connect Four board.
 */
struct TPosition {
	/* The row of the position. */
	int r;

	/* The column of the position. */
	int c;
};

/*
 * The TBoard type represents Connect Four boards. Each instance of this
 * type is initialized with two players (Red and Black) and an empty
 * board, and can subsequently be used to record the placement of their
 * pieces on the board.
 *
 * The columns of the board take on indices from 0 (the leftmost column) 
 * to T_NUM_COLUMNS-1 (the rightmost column), where T_NUM_COLUMNS is
 * seven for a conventional game. The rows of the Connect Four board
 * take on indices from 0 (the bottommost row) to T_NUM_ROWS-1 (the
 * topmost row), where T_NUM_ROWS is six for a conventional game. This
 * indexing scheme can be visualized as follows:
 * 
 *  +-+-+-+-+-+-+-+
 * 5| | | | | | | |
 *  +-+-+-+-+-+-+-+
 * 4| | | | | | | |
 *  +-+-+-+-+-+-+-+
 * 3| | | | | | | |
 *  +-+-+-+-+-+-+-+
 * 2| | | | | | | |
 *  +-+-+-+-+-+-+-+
 * 1| | | | | | | |
 *  +-+-+-+-+-+-+-+
 * 0| | | | | | | |
 *  +-+-+-+-+-+-+-+
 *   0 1 2 3 4 5 6
 */
class TBoard {
public:
	/* Returns a clone of this board. */
	virtual TBoard* clone() const = 0;

	/* Returns the Red player for the board. */
	virtual TPlayer* getRed() const = 0;

	/* Returns the Black player for the board. */
	virtual TPlayer* getBlack() const = 0;

	/* Returns the player whose piece occupies the square at row r,
	   column c, 0 (null pointer) if no piece occupies the square. */
	virtual TPlayer* getPiece(int r, int c) const = 0;

	/* Returns the player whose piece occupies position p, 0 (null
	   pointer) if no piece occupies the square. */
	virtual TPlayer* getPiece(const TPosition& p) const = 0;

	/* Counts and returns how many of Red's pieces occupy the n
	   positions in array ps. */
	virtual int countRed(const TPosition ps[], int n) const = 0;

	/* Counts and returns how many of Black's pieces occupy the n
	   positions in array ps. */
	virtual int countBlack(const TPosition ps[], int n) const = 0;

	/* Returns the winner of the game, 0 (null pointer) if there is
	   none. */
	virtual TPlayer* getWinner() const = 0;

	/* Returns true if a piece can be dropped into column c, false
	   otherwise. */
	virtual bool isLegalMove(int c) const = 0;

	/* Returns true if the board has a column that can accommodate
	   another piece, false otherwise. */
	virtual bool hasLegalMoves() const = 0;

	/* Drops player p's piece in column c, making it the top piece
	   in that column. */
	virtual void dropPiece(TPlayer* p, int c) = 0;

	/* Removes the top piece from column c (the last piece played
	   in that column), and returns the player who owned that
	   piece. */
	virtual TPlayer* removeTopPiece(int c) = 0;
};

#endif
