/**********************************************************************
 *
 *   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;


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

    Hand();
    Hand(unsigned const cardno);
    Hand(Hand const& h);
    Hand(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 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;

    bool hastrump() const;

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

    unsigned numberof(Card::Color const& c,GameType const& t) const;

    unsigned numberoftrumps() const;
    unsigned numberoftrumpaces() const;
    unsigned numberoftrumpnines() const;
    unsigned numberoftrumpkings() const;
    unsigned numberofnines() const;
    unsigned numberofkings() const;
    unsigned numberofclubqueens() 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);

#ifdef OUTDATED
    // 0.6.4
    bool sort();
    void mix();
#endif

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

    Hand validcards(Trick const& trick) 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;
}; // 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
