/*
  Copyright (C) 2005 Dan Alcantara (dfalcantara@ucdavis.edu, http://wwwcsif.cs.ucdavis.edu/~alcantar)
  Based on the board game "Blokus" by Educational Insights, Inc.
  
  This program is free software; you can redistribute 
  it and/or modify it under the terms of the GNU General 
  Public License as published by the Free Software Foundation; 
  either version 2 of the License, or (at your option) any later version.
  
  This program is distributed in the hope that it will be useful, but 
  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 
  more details.
  
  You should have received a copy of the GNU General Public License along 
  with this program; if not, write to the Free Software Foundation, Inc., 
  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  
  Full license visible at http://www.opensource.org/licenses/gpl-license.php
*/

/*	This file is contains the AI logic.
 */

#ifndef AI_H
#define AI_H

#include "piece.h"
#include "player.h"
#include "board.h"

class AI
{
public:
  enum StepOutcome
  {
    Incomplete, MustReset, Complete
  };

  struct AIOptions
  {
    int weightSize;
    int weightFriendlySpaces;
    int weightEnemySpaces;

    int numFriendlyPiecesToCheck;
    int numEnemyPiecesToCheck;

    AIOptions(int wS = 1, int wFS = 1, int wES = 1, int nFPTC = 5, int nEPTC = 1)
    {
      weightSize = wS;
      weightFriendlySpaces = wFS;
      weightEnemySpaces = wES;
      numFriendlyPiecesToCheck = nFPTC;
      numEnemyPiecesToCheck = nEPTC;
    }
  };

  AI(BlokishBoard &board);

  // Figures out how many spaces have been checked.
  int GetNumDone();
  
	// Resets the AI.  Must be called before Step is run.
  void Reset(AIOptions opts, BlokishID playerID, std::vector<PieceVector*> &allPlayerPieces);
  
	// Runs the AI logic.  If the threads are enabled, it runs everything in one sweep.
	// Otherwise, it evaluates one row, then returns.
  StepOutcome Step(BlokishBoard::Move &move);

protected:
	// Try calculates all the moves possible at one particular square.
  void Try();

  bool                            bRestartedAlready;
  int                             nPiece;
  int                             nRow;
  int                             nCol;
  int                             numWithMaxRating;
  int                             maxRating;
  BlokishID                       player;
  BlokishBoard                    *boardPtr;
  std::vector<PieceVector*>       allPieces;
  std::vector<BlokishBoard::Move> possible_moves;
  AIOptions                       mOptions;
};

#endif
