/* This file is part of cardwords
   (c) 1999 Tobias Peters
   see file COPYING for the copyright terms.
   
   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
*/

// cardwords_cardtable.hh

#ifndef CARDWORDS_CARDTABLE_HH
#define CARDWORDS_CARDTABLE_HH

#include "cardwords_cardcontainer2dim.hh"
#include "cardwords_iostream.hh"
#include "cardwords_move.hh"
#include "cardwords_pile.hh"

class CardWords_CardTable : public CardWords_CardContainer2Dim {
private:
  CardWords_CardTableLocation starting_pos;
  CardWords_Matrix<int>  letter_factors;
  CardWords_Matrix<int>  word_factors;
  CardWords_Matrix<int>  cell_points;
  CardWords_Matrix<bool> cell_blocked;
  
public:
  // These functions are here for counting the cards on the card-table:
  // remove a special card from the container:
  virtual void remove_card (CardWords_Card *);
    
  // add a card to the container:
  virtual void add_card (CardWords_Card*, CardWords_CardTableLocation);

  const CardWords_CardTableLocation & get_starting_pos (void) const
    { return starting_pos; }

  int get_word_factor (CardWords_CardTableLocation loc)const
    { return word_factors[loc]; }
  int get_word_factor (size_t x, size_t y) const
    {return get_word_factor (CardWords_CardTableLocation(x,y));}

  int get_letter_factor (CardWords_CardTableLocation loc)const
    { return letter_factors[loc]; }
  int get_letter_factor (size_t x, size_t y) const
    {return get_letter_factor (CardWords_CardTableLocation(x,y));}

  int get_cell_points (CardWords_CardTableLocation loc)const
    { return cell_points[loc]; }
  int get_cell_points (size_t x, size_t y) const
    {return get_cell_points (CardWords_CardTableLocation(x,y));}

  bool is_cell_blocked (CardWords_CardTableLocation loc)const
    { return cell_blocked[loc]; }
  bool is_cell_blocked (size_t x, size_t y) const
    {return is_cell_blocked (CardWords_CardTableLocation(x,y));}

  friend CardWords_CardTable * read_card_table (istream &);
  CardWords_CardTable (size_t columns,
                 size_t rows,
                 CardWords_CardTableLocation start);
  // Add the move, get the cards from this container:
  void
  add_move(const CardWords_Move &, CardWords_CardContainer1Dim *);

  // Check if such a move would fit on the card-table.
  // Moves creating 1-letters-words are marked as not-fitting.
  bool
  check_move_fits(const CardWords_Move &) const;

  size_t
  get_number_of_cards(void) const;

  bool 
  has_cell_neighbour_card(CardWords_CardTableLocation) const;
  
private:
  size_t number_of_cards;
};

ostream & operator << (ostream &, const CardWords_CardTable &);

#endif
