#ifndef CBOARD_H
#define CBOARD_H

////////////////////////////////////////
//                                    //
//  This class represents the board.  //
//                                    //
////////////////////////////////////////

class CBoard
{
  CBasePiece* Board[8][8];
  type_color Turn;
  type_piece Promotion;
  CBasePiece* ToDelete;

  void Create();
  void Destroy();

 public:
  CBoard();
  CBoard(const CBoard& board);
  CBoard& operator = (const CBoard& board);
  ~CBoard();

  CBasePiece*& operator()(char x, char y)
    { return Board[x][y]; }
  const CBasePiece *const & operator()(char x, char y) const
    { return Board[x][y]; }

  type_color GetTurn() const { return Turn; }
  void SwitchTurn() { Turn = ( (Turn == WHITE) ? BLACK : WHITE ); }
  void SetTurn(type_color NewTurn) { Turn = NewTurn; }
  type_piece GetPromotion() const { return Promotion; }
  void SetPromotion(type_piece promotion) { Promotion = promotion; }
  void SetToDelete(CBasePiece * todelete) { ToDelete = todelete; }

  bool IsCheck(type_color Col) const;
  void Draw() const;
  bool IsMoveValid(const CMove& move) const
    { return ( Board[move.GetSourceX()][move.GetSourceY()]->IsMoveValid(move)); }
  void Move(const CMove& Move);
};

std::ostream& operator <<(std::ostream& o, const CBoard& board);

#endif
