/**********************************************************************
 *
 *   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_TRICK_HEADER
#define CLASS_TRICK_HEADER

#include "../basistypes.h"

#include "card.h"
#include "../game/specialpoint.h"
class Game;
class Player;
class Hand;

/**
 ** @brief represents a trick (the cards and the startplayer)
 **
 ** This class is part of game
 **
 ** @see Game
 ** @see Card
 **
 ** @author Borg Enders
 ** @author Diether Knof
 **
 ** @version 0.4.4
 **
 **/
class Trick {
  friend class Game;
  public:
  /// constructor
  Trick(Player const& startplayer);
  /// constructor
  Trick(istream& istr);
  /// constructor
  Trick();
  /// destructor
  ~Trick();

  /// copy the trick
  Trick(Trick const& t);
  /// copy the trick
  Trick& operator=(Trick const& trick);

  // checks the data
  bool self_check() const;

  /// output of the trick
  ostream& out(ostream& ostr) const;

  /// add a card to the trick
  Trick& operator+=(Card const& c);

  // the number of the trick
  unsigned no() const;

  /// returns the requested card
  Card const& card(unsigned const i) const;
  /// returns the card played by the player
  Card const& card_of_player(Player const& player) const;

  /// returns the player of the card no i
  Player const& player_of_card(unsigned const c) const;
  /// returns at which position the player 'player' plays his card
  unsigned cardno_of_player(Player const& player) const;

  // returns the game the trick is part of
  Game const& game() const;
  /// returns the startplayer
  Player const& startplayer() const;
  /// set the startplayer
  void startplayer_set(Player const& startplayer);
  /// returns the startcard
  Card const& startcard() const;
  /// returns whether this is the startcard
  bool isstartcard() const;
  /// returns whether the trick is empty
  bool isempty() const;
  /// returns whether the trick is full
  bool isfull() const;
  /// returns whether there only lacks one card
  bool islastcard() const;

  // returns whether the trick is in the trickpile
  bool intrickpile() const;
  // moves the trick in the trickpile
  void move_in_trickpile();

  /// returns how many cards are in the trick
  unsigned actcardno() const;
  /// returns which player has to play a card
  Player const& actplayer() const;

  /// returns the points of the trick
  unsigned points() const;

  /// returns whether the card is valid for the hand
  bool isvalid(Card const& card, Hand const& hand) const;

  /// returns the winnerplayer
  Player const& winnerplayer() const;
  /// returns the winnerteam
  Team winnerteam() const;
  /// returns the winnercard
  Card winnercard() const;
  /// returns the number of the winnercard
  unsigned winnercardno() const;

  // returns whether this is the last trick
  bool islast() const;


  // returns the specialpoints of the trick
  // with all information taken from 'game'
  Specialpointsvector specialpoints() const;
  /// returns the specialpoints of the trick
  Specialpointsvector specialpoints(GameType const gametype,
				    vector<Team> const& real_team,
				    bool const islasttrick) const;
  /// returns the specialpoints of the trick
  Specialpointsvector specialpoints(GameType const gametype,
				    vector<Team> const& real_team,
				    vector<Team> const& known_team,
				    bool const islasttrick) const;
  // returns a vector with the cards that get a specialpoint
  vector<Card> specialpoints_cards() const;

  private:
  // cards in this trick (sorted in the order of playing)
  vector<Card> card_p;

  protected:
  // the game, the trick is part of
  Game const* game_p;

  // the number of the trick
  unsigned no_;

  // player, who played the first card
  Player const* startplayer_p;
  // winnerplayer
  Player const* winnerplayer_p;

  private:
  // whether the trick is in the trickpile
  bool intrickpile_p;

  private: // not to be used
}; // class Trick

/// output of the trick
ostream& operator<<(ostream& ostr, Trick const& trick);

/// comparison of the tricks
bool operator==(Trick const& trick1, Trick const& trick2);
bool operator!=(Trick const& trick1, Trick const& trick2);

#endif // #ifndef CLASS_TRICK_HEADER
