/* This file is part of cardwords
   (c) 1998 1999 2000 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_dicbot_cardtablecell.hh

/* Classes containing _DicBot_ and files containing _dicbot_ indicate
   classes and files for dicbot. dicbot will be the dictionary and
   robot process started by the cardwords server.

   The server delegates the following tasks to dicbot:

   - Check if a move is valid. This means:
   . * Check if there is enough space on the card-table to actually lay the
   .   cards.
   . * Check if all words created by that move are valid. This can be
   .   disabled.
   - Calculate the score of a move. This contains a validity check as above.
   - Calculate the best possible move for a given set of cards. The best
   . possible move means the one that gets the most points.
   . This contains several score calculations as above.
*/

#ifndef CARDWORDS_DICBOT_CARDTABLECELL_HH
#define CARDWORDS_DICBOT_CARDTABLECELL_HH

// This file defines The class CardWords_DicBot_CardTableCell.
// This class contains all information dicbot wants to have about a
// special cell of the card-table.

#include "cardwords_carddescription.hh"
#include "cardwords_direction.hh"
namespace CardWords {
class DicBot_CardTableMustNot;

class DicBot_CardTableCell {
public:
  // everything is modifyable through accessing functions
  DicBot_CardTableCell ();

  // Each cell remembers if it is possible to start or end a word here, de-
  // pending on the direction. E.g. it is not possible to start a horizontal
  // word on a cell whose left neighbour carries already a card.
  bool
  is_startPossible (Direction) const;

  bool
  is_endPossible (Direction) const;

  // Because a cell has no clue what happens with its neighbours, this info
  // has to come from the outside:
  void
  set_startPossible (Direction, bool = true);

  void
  unset_startPossible (Direction);

  void
  set_endPossible (Direction, bool = true);

  void
  unset_endPossible (Direction);


  // if this cell carries a card:
  bool
  get_containsCard(void) const;

  // use remove_card and change_card instead of this:
  //  void set_containsCard(bool);

  // return the CardDescription:
  const CardDescription *
  get_card(void) const;

  // remove the card:
  void
  remove_card(void);

  // change the card, also used for adding:
  void
  change_card (const CardDescription &);

  // get and set the letter and word factors:
  int
  get_letter_factor(void) const;

  int
  get_word_factor  (void) const;

  int
  get_cell_points  (void) const;

  bool
  is_cell_blocked  (void) const;


  
  void
  set_letter_factor(int);

  void
  set_word_factor  (int);

  void
  set_cell_points  (int);

  void
  set_cell_blocked (bool);


  
  // Methods to modify the must_not information:
  // The direction parameter that every method takes is equivalent to the
  // direction of the words that must not contain these must_not characters.
  DicBot_CardTableMustNot *
  get_must_not(Direction);

  const DicBot_CardTableMustNot *
  get_must_not(Direction) const;


  // Check if the must_not allows char c, or if there is a card in this
  // cell, if that card's meaning is the same as c:
  bool
  test_allowed(Char c, Direction) const;

  // Add a forbidden char to the must nots:
  void
  add_must_not(Char c, Direction);

  // Clear all must nots because of a new card-table situation that has an
  // impact on this field:
  void
  clear_must_nots(Direction);

private:
  bool startPossible[2];
  bool endPossible[2];

  bool containsCard;

  CardDescription card;

  int letter_factor;
  int word_factor;
  int cell_points;
  bool cell_blocked;
  
  DicBot_CardTableMustNot * mustNot[2];
};
}
// everything is modifyable through accessing functions
#endif

