/**********************************************************************
 *
 *   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 "card.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(Hand const& h);
    Hand(Player const& player, 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);

    unsigned cardsnumber() const;
    Card const& card(unsigned const i) const;
    vector<Card> const& cards() const;
    vector<Card> cards_single() const;
    unsigned cardsnumber_all() const;
    Card const& card_all(unsigned const i) const;
    vector<Card> const& cards_all() const;
    bool played(unsigned const i) const;
    unsigned played_trick(unsigned const i) const;
    Card const& highest_card() const;
#ifndef OUTDATED
    Card const& highest_card(Game const& game) const;
#endif

    Card requested_card() const;
    unsigned requested_position() const;
    void request_position(unsigned const position);
    void request_position_all(unsigned const position_all);
    void request_card(Card const card);
    void forget_request();

    unsigned pos_to_pos_all(unsigned pos) const;
    unsigned pos_all_to_pos(unsigned pos) const;

    Player const& player() const;
    void set_player(Player const& player);

    unsigned numberof(Card::Value const& value) const;
    unsigned numberof(Card::TColor const& tcolor) const;
    unsigned numberof(Card const& c) const;
    unsigned numberof(Card::TColor const& tcolor,
		      Card::Value const& value) const;

    unsigned numberof(Card::Color const& color, GameType const& gt) const;

    unsigned numberoftrumps() const;
    unsigned numberoftrumpaces() const;
    unsigned numberoftrumpnines() const;
    unsigned numberoftrumpkings() const;
    unsigned numberofnines() const;
    unsigned numberofkings() const;
    unsigned numberofclubqueens() const;

    unsigned numberofall(Card::TColor const& tcolor,
			 Card::Value const& value) const;
    unsigned numberofalltrumpaces() const;

    bool hastrump() const;
    bool existstcolor(Card::TColor const& c) const;

    void playcard(Card const& c);
    void playcard(unsigned pos);
    void unplaycard(Card const& c);

    void add(Card const& card);
    void add(vector<Card> const& cards);
    void add(Hand const& hand);
    unsigned remove(Card const& card);
    void remove(vector<Card> const& cards);
    void remove(Hand const& hand);

    unsigned getpos(Card const&) const;
    unsigned getpos_all(Card const&) const;

    Hand validcards(Trick const& trick) const;

    bool contains(Hand const& hand) const;
    Hand missing_cards(Hand const& hand) const;

  private:
    vector<Card> card_p;      // cards on hand
    vector<Card> card_all_p; // all cards of the hand
    vector<unsigned> played_p; // whether a card is played or not

    unsigned requested_position_p;

    // the player who owns the hand
    Player const* player_;
}; // class Hand

ostream& operator<<(ostream& ostr, Hand const& hand);

bool operator==(Hand const& hand1, Hand const& hand2);
bool operator!=(Hand const& hand1, Hand const& hand2);

#endif // #ifndef CLASS_HAND_HEADER
