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

#ifndef CARDWORDS_CARD_HH
#define CARDWORDS_CARD_HH

#include "cardwords_cardbase.hh"

class CardWords_Card : public CardWords_CardBase {
public:
  virtual bool is_wildcard(void) const;
  
  // Get the char that is written on this card:
  virtual const CardWords_Char &
  get_faceValue(void) const;

  // Get the score for this card:
  virtual
  int
  get_points(void) const;

  CardWords_Card( CardWords_Char face,
                  CardWords_Char means,
                  int score);
  CardWords_Card( Machine_Char face,
                  Machine_Char means,
                  int score);
  CardWords_Card( Machine_Char faceAndMeans,
                  int score);

  // read the card definition from a stream:
  CardWords_Card( istream & );

  bool operator < (const CardWords_Card &)const;
  bool operator == (const CardWords_Card &)const;
  bool operator > (const CardWords_Card &)const;

  int compare(const CardWords_Card &)const;

  // The container where this card is currently stored:
  class CardWords_CardContainer *
  get_container(void) const;

  void 
  set_container(class CardWords_CardContainer *);

private:
  bool wildcard;
  int  points; // The score for this card.


  CardWords_Char faceValue; // The char that is written on this card.

  // every card is contained in a cardcontainer:
  class CardWords_CardContainer * container;

  // Every card gets a unique number. This way Two cards always have a
  // lesser/greater order. This is important as they will be referenced
  // by sets.
  long unsigned uniqueNumber;
  // This will be assigned and incremented at every constructor:
  static long unsigned nextUniqueNumber;
};

// the test if this card is a wildcard:
inline
bool
CardWords_Card::is_wildcard(void) const
{
  return wildcard;
}

// Get the char that is written on this card:
inline
const CardWords_Char &
CardWords_Card::get_faceValue(void) const
{
  return faceValue;
}

// Get the score for this card:
inline
int
CardWords_Card::get_points(void) const
{
  return points;
}

inline
CardWords_Card::CardWords_Card( CardWords_Char face,
                                CardWords_Char means,
                                int score)
  : CardWords_CardBase(means),
    wildcard  (face == CardWords_Char::blanko),
    points    (score),
    faceValue (face),
    container (0),
    uniqueNumber (nextUniqueNumber++)
{}

inline
CardWords_Card::CardWords_Card( Machine_Char face,
                                Machine_Char means,
                                int score)
  : CardWords_CardBase(means),
    wildcard  (CardWords_Char(face) == CardWords_Char::blanko),
    points    (score),
    faceValue (face),
    container (0),
    uniqueNumber (nextUniqueNumber++)
{}

inline
CardWords_Card::CardWords_Card( Machine_Char faceAndMeans,
                                int score)
  : CardWords_CardBase(faceAndMeans),
    wildcard  (CardWords_Char(faceAndMeans) == CardWords_Char::blanko),
    points    (score),
    faceValue (faceAndMeans),
    container (0),
    uniqueNumber (nextUniqueNumber++)
{}

inline
int
CardWords_Card::compare(const CardWords_Card & other) const
{
  if (faceValue < other.faceValue)
    return -1;
  if (faceValue > other.faceValue)
    return 1;
  if (get_points() < other.get_points())
    return -1;
  if (get_points() > other.get_points())
    return 1;
  if (uniqueNumber < other.uniqueNumber)
    return -1;
  if (uniqueNumber > other.uniqueNumber)
    return 1;
  return 0;
}

inline bool
CardWords_Card::operator < (const CardWords_Card & other) const
{
  return (compare(other) < 0);
}

inline bool
CardWords_Card::operator == (const CardWords_Card & other) const
{
  return (compare(other) == 0);
}


inline bool
CardWords_Card::operator > (const CardWords_Card & other) const
{
  return (compare(other) > 0);
}

// The container where this card is currently stored:
inline
class CardWords_CardContainer *
CardWords_Card::get_container(void) const
{
  return container;
}

inline
void 
CardWords_Card::set_container(class CardWords_CardContainer *c)
{
  container = c;
}
#endif

