/**********************************************************************
 *
 *   FreeDoko a Doppelkopf-Game
 *    
 *   Copyright (C) 2001-2004  by Diether Knof and Borg Enders
 *
 *   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 can find this license in the file 'gpl.txt'.
 *
 *   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
 *
 *  Contact:
 *    Diether Knof dknof@gmx.de
 *    Borg Enders  borg@borgsoft.de
 *
 **********************************************************************/


#ifndef CLASS_HAND_HEADER
#define CLASS_HAND_HEADER

#include "../basistypes.h"
#include "hand_cards.h"
class Trick;
class Player;

/**
 **
 ** Hand (of a player) with all cards (played and not played)
 **
 ** @author	Borg Enders
 ** @author	Diether Knof
 **
 **/
class Hand {
  public:

    Hand();
    Hand(Player const& player);
    Hand(Player const& player, Hand const& h);
    Hand(Hand const& h);
    Hand(vector<Card> const& cards);
    Hand(Player const& player, vector<Card> const& cards);
    Hand(istream& istr);

    ~Hand();

    Hand& operator=(Hand const& h);

    // checks the data
    bool self_check() const;

    // the player this hand belongs to 
    Player const& player() const;
    // set the player of this hand
    void set_player(Player const& player);

    // the number of cards (which are not played
    unsigned cardsnumber() const;
    // the number of cards (all)
    unsigned cardsnumber_all() const;

    // the i'th card (of the unplayed)
    HandCard const& card(unsigned const i) const;
    // the i'th card (of all)
    HandCard const& card_all(unsigned const i) const;
    // whether the i'th card is played
    bool played(unsigned const i) const;
    // in wich trick the i'th card was played
    unsigned played_trick(unsigned const i) const;

    // all cards without double ones
    HandCards cards_single() const;
    // the highest card 
    HandCard const& highest_card() const;
#ifndef OUTDATED
    Card const& highest_card(Game const& game) const;
#endif

    // get the position of the card
    unsigned getpos(Card const& card) const;
    // get the position of the card (in all cards)
    unsigned getpos_all(Card const&) const;

    // transform the position in the unplayed cards to the position in all cards
    unsigned pos_to_pos_all(unsigned pos) const;
    // transform the position in all cards to the position in the unplayed cards
    unsigned pos_all_to_pos(unsigned pos) const;



    // changing

    // play the card 'card'
    void playcard(HandCard const& card);
    // play the card at the position 'pos'
    void playcard(unsigned pos);
    // unplaye the card 'card'
    void unplaycard(HandCard const& card);

    // add the card to the hand
    void add(Card const& card);
    // add the cards to the hand
    void add(vector<Card> const& cards);
    // add the hand to the hand
    void add(Hand const& hand);

    // remove the card from the hand
    unsigned remove(HandCard const& card);
    // remove the card from the hand
    unsigned remove(Card const& card);
    // remove the cards from the hand
    void remove(HandCards const& cards);



    // card request

    // the requested card
    HandCard requested_card() const;
    // request the card at the position (in the unplayed cards)
    void request_position(unsigned const position);
    // request the card at the position (in all cards)
    void request_position_all(unsigned const position_all);
    // request the card
    void request_card(Card const card);
    // forget the request
    void forget_request();



    // counting

    // the valid cards for the trick
    HandCards validcards(Trick const& trick) const;

    // whether there is a trump card in the hand
    bool hastrump() const;
    // wheteher there exists a card with the given color
    bool existstcolor(Card::TColor const& tcolor) const;

    // the number of cards with the value
    unsigned numberof(Card::Value const& value) const;
    // the number of cards with the trump color
    unsigned numberof(Card::TColor const& tcolor) const;
    // the number of cards 'card'
    unsigned numberof(Card const& card) const;
    // the number of cards 'Card(tcolor, value)'
    unsigned numberof(Card::TColor const& tcolor,
		      Card::Value const& value) const;

    // the number of cards 'Card(color)' without counting trump
    unsigned numberof(Card::Color const& color, Game const& game) const;
    unsigned numberof(Card::Color const& color,
		      GameType const gametype,
		      bool const dollen) const;

    // the number of trumps
    unsigned numberoftrumps() const;
    // the number of trumps aces
    unsigned numberoftrumpaces() const;
    // the number of trumps nines
    unsigned numberoftrumpnines() const;
    // the number of trump kings
    unsigned numberoftrumpkings() const;
    // the number of nines
    unsigned numberofnines() const;
    // the number of kings
    unsigned numberofkings() const;
    // the number of club queens
    unsigned numberofclubqueens() const;

    // the number of cards 'Card(tcolor, value)' in all cards
    unsigned numberofall(Card::TColor const& tcolor,
			 Card::Value const& value) const;
    // the number trump aces in all cards
    unsigned numberofalltrumpaces() const;



    // checking

    // whether 'hand' is contained in this hand
    bool contains(Hand const& hand) const;
    // the cards which are in 'hand' but not in this hand
    HandCards missing_cards(Hand const& hand) const;

  private:
    // the cards on the hand
    PRIV_VAR_R(HandCards, cards);
    // all cards on the hand
    PRIV_VAR_R(HandCards, cards_all);
    // whether a card is played and in which trick
    vector<unsigned> played_;

    // which card is requested
    PRIV_VAR_R(unsigned, requested_position);

    // the player who owns the hand
    PRIV_VAR_CP(Player, player);
}; // class Hand

// write the hand in the output
ostream& operator<<(ostream& ostr, Hand const& hand);

// compare two hands
bool operator==(Hand const& hand1, Hand const& hand2);
// compare two hands
bool operator!=(Hand const& hand1, Hand const& hand2);

#endif // #ifndef CLASS_HAND_HEADER
