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

#include "constants.h"

#include "player.h"

#include "human/human.h"
#include "ai/ai.h"
#include "ai.dummy/ai.h"
#include "../card/hand.h"
#include "../party/party.h"
#include "../party/rule.h"
#include "../misc/setting.h"
#include "../ui/ui.h"
#include "playersDb.h"

/**
 **
 ** -> result
 **
 ** @param       type    playertype
 **
 ** @return      pointer to a new player of the given type
 **
 ** @author      Borg Enders
 ** @author      Diether Knof
 **
 ** @version     0.4.4
 **
 **/
Player*
Player::new_(Type const& type)
{
  DEBUG_CALLING(INFO_PLAYER && INFO_VALUE,
		"Player::new_(const Player::Type type)");

  Player* player = NULL;

  switch(type) {
  case Player::UNSET:
    DEBUG_ASSERTION(false,
		    "Player::new_(type, player):\n"
		    "  type == UNSET");
    break;
  case Player::HUMAN:
    player = new Human();
    break;
  case Player::AI:
    player = new Ai();
    break;
  case Player::AI_DUMMY:
    player = new AiDummy();
    break;
  } // switch(type)

  DEBUG_RETURNING(player,
		  INFO_PLAYER && INFO_VALUE,
		  "new_Player(type)");
} // Player* Player::new_(Type const& type)

/**
 **
 ** -> result
 **
 ** @param	type	playertype
 ** @param	p	the player to be copied
 **
 ** @return	pointer to a new player of the given type and with data
 **		from 'player'
 **
 ** @author	Diether Knof
 **
 ** @version	0.4.4
 **
 **/
Player*
Player::new_(Type const& type, Player const& p)
{
  DEBUG_CALLING(INFO_PLAYER && INFO_VALUE,
		"Player::new_(type, player)");

  Player* player = NULL;

  switch(type) {
  case Player::UNSET:
    DEBUG_ASSERTION(false,
		    "Player::new_(type, player):\n"
		    "  type == UNSET");
    break;
  case Player::HUMAN:
    player = new Human(p);
    break;
  case Player::AI:
#ifdef WORKAROUND
    if (dynamic_cast<Ai const*>(&p) != NULL)
      player = new Ai(dynamic_cast<Ai const&>(p));
    else
      player = new Ai(p);
#else
    // if 'p' is of type 'Human', the GNU C++ compiler calls 'Ai(Player)' but
    // not 'Ai(Ai)' although 'Human' is a child of 'Ai'
    player = new Ai(p);
#endif
    break;
  case Player::AI_DUMMY:
    player = new AiDummy(p);
    break;
  } // switch(type)

  DEBUG_RETURNING(player,
		  INFO_PLAYER && INFO_VALUE,
		  "Player::new_(type, player)");
} // Player* Player::new_(Type const& type, Player const& player)

/**
 **
 ** returns a player, created by the infos of the file
 **
 ** @param	filename	file with the player info
 **
 ** @return	pointer to a new player of the given type
 **
 ** @author	Diether Knof
 **
 ** @version	0.5.2
 **
 **/
Player*
Player::new_(string const& filename)
{
  DEBUG_CALLING(INFO_PLAYER && INFO_VALUE,
		"Player::new_(filename)");

  ifstream istr(filename.c_str());
  if (istr.fail())
    DEBUG_RETURNING(NULL,
		    INFO_PLAYER && INFO_VALUE,
		    "Player::new_(filename)");

  DEBUG_RETURNING(Player::new_(istr),
		  INFO_PLAYER && INFO_VALUE,
		  "Player::new_(filename)");
} // Player* Player::new_(string const& filename)

/**
 **
 ** returns a player, created by the infos of the stream
 **
 ** @param	istr	stream with the player info
 **
 ** @return	pointer to a new player of the given type
 **
 ** @author	Diether Knof
 **
 ** @version	0.5.2
 **
 **/
Player*
Player::new_(istream& istr)
{
  DEBUG_CALLING(INFO_PLAYER && INFO_VALUE,
		"Player::new_(istr)");

  // word that has been read
  string line;

  // the first line has the name 'name':
  // Player n: name
  std::getline(istr, line);
  if ((string(line, 0, strlen("Player:")) != "Player:")
      || istr.fail())
    DEBUG_RETURNING(NULL,
		    INFO_PLAYER && INFO_VALUE,
		    "new_Player(istr)");

  // the name of the player
  string name;
  // the rest of the line is the name of the player
  if (line.length() > strlen("Player: "))
    name = string(line, strlen("Player: "), string::npos);
  else
    name = "";

  // the second line is the player type 'type'
  // Player type: 'type'
  std::getline(istr, line);
  if ((string(line, 0, strlen("Player type:")) != "Player type:")
      || istr.fail()) {
    DEBUG_RETURNING(NULL,
		    INFO_PLAYER && INFO_VALUE,
		    "new_Player(istr)");
  }

  // the rest of the line is the type of the player
  string type = string(line, strlen("Player type: "), string::npos);
  // ignore DOS EOL
  if (*(type.rbegin()) == '\r')
    type.resize(type.size() - 1);

  // new player
  Player* player = NULL;
  
  if (type == ::name(HUMAN)) {
    player = new Human(istr);
  } else if (type == ::name(AI)) {
    player = new Ai(istr);
  } else if (type == ::name(AI_DUMMY)) {
    player = new AiDummy(istr);
  } else { // if (type == 'type')
    DEBUG_ASSERTION(false,
		    "Player::new_(istr):\n"
		    "  player type '" << type << "' not known");
  }

  if (player)
    player->name_set(name);

  DEBUG_RETURNING(player,
		  INFO_PLAYER && INFO_VALUE,
		  "new_Player(istr)");
} // Player* Player::new_(istream& istr)

/**
 **
 ** constructor
 **
 ** @param       type type of the player
 **
 ** @return      -
 **
 ** @version     0.4.4
 **
 ** @author      Borg Enders
 ** @author      Diether Knof
 **
 **/
Player::Player(Type const& type)  :
game_p(NULL),
  type_p(type),
  name_p(),
  no_p(UINT_MAX),
  hand_p(),
  sorted_hand_p(this->hand_p),
#ifndef RELEASE
  db_( NULL ),
#endif
  teaminfo_p(vector<Team>(::party.rule()(Rule::NUMBER_OF_PLAYERS_IN_GAME),
			  TEAM::UNKNOWN))
{
  DEBUG_CALLING(INFO_PLAYER && INFO_INIT,
		"Player::Player(type)");

#ifndef RELEASE
  this->db_ = new PlayersDb();
#endif

  DEBUG_RETURNING(VOID,
		  INFO_PLAYER && INFO_INIT,
		  "Player::Player(type)");
} // Player::Player(Type const& type)  :

/**
 **
 ** destructor
 **
 ** @param       -
 **
 ** @return      -
 **
 ** @author      Borg Enders
 ** @author      Diether Knof
 **
 ** @version     0.5.3
 **
 **/
Player::~Player()
{
  DEBUG_CALLING(INFO_PLAYER && INFO_INIT,
		"Player::~Player()");

#ifndef RELEASE
  delete this->db_;
#endif

  DEBUG_RETURNING(VOID,
		  INFO_PLAYER && INFO_INIT,
		  "Player::~Player()");
} // Player::~Player()

/**
 **
 ** copy constructor
 **
 ** @param       player  player to copy
 **
 ** @return      -
 **
 ** @author      Borg Enders
 ** @author      Diether Knof
 **
 ** @version     0.6.4
 **
 **/
Player::Player(const Player& player) :
game_p(player.game_p),
  type_p(Player::UNSET),
  name_p(player.name_p),
  no_p(player.no_p),
  hand_p(player.hand_p),
  sorted_hand_p(player.sorted_hand_p, this->hand_p),
#ifndef RELEASE
db_( (player.db_ == NULL)
     ? NULL
     : new PlayersDb(*(player.db_)) ), // *** DK must use a copy!
#endif
teaminfo_p(player.teaminfo_p)
{
  DEBUG_CALLING(INFO_PLAYER && INFO_INIT,
		"Player::Player(Player)");

  DEBUG_RETURNING(VOID,
		  INFO_PLAYER && INFO_INIT,
		  "Player::Player(Player)");
} // Player::Player(const Player& player)

/**
 **
 ** clone the player
 **
 ** @param       -
 **
 ** @return      pointer of a clone
 **
 ** @author      Diether Knof
 **
 ** @version     0.5.3
 **
 **/
Player*
Player::clone() const
{  
  DEBUG_CALLING(INFO_PLAYER && INFO_INIT,
		"Player::clone()");

  DEBUG_RETURNING(new Player(*this),
		  INFO_PLAYER && INFO_INIT,
		  "Player::clone()");
} // virtual Player* Player::clone() const

/**
 **
 ** copy operator
 **
 ** @param       player  player to be copied
 **
 ** @return      copy of player
 **
 ** @author      Borg Enders
 ** @author      Diether Knof
 **
 ** @version     0.4.4
 **
 **/
Player&
Player::operator=(const Player& player)
{  
  DEBUG_CALLING(INFO_PLAYER && INFO_INIT,
		"Player::operator=(player)");

  // copy the values
  this->game_p = player.game_p;
  this->type_p = player.type_p;
  this->name_p = player.name_p;
  this->no_p = player.no_p;
  this->hand_p = player.hand_p;
  this->sorted_hand_p = SortedHand(player.sorted_hand_p, this->hand_p);
  this->teaminfo_p = player.teaminfo_p;
#ifndef RELEASE
  this->db_        = ((player.db_ == NULL)
		      ? NULL
		      : new PlayersDb(*(player.db_))); // *** DK must use a copy!
#endif

  DEBUG_RETURNING(*this,
		  INFO_PLAYER && INFO_INIT,
		  "Player::operator=(player)");
} // Player& Player::operator=(const Player& player)

/**
 **
 ** -> result
 **
 ** @param       player1 player 1 to compare
 ** @param       player2 player 2 to compare
 **
 ** @return      whether the players are equal (they lie in the same memory)
 **
 ** @author      Diether Knof
 **
 ** @version     0.4.4
 **
 **/
bool
operator==(Player const& player1, Player const& player2)
{
  DEBUG_CALLING(INFO_PLAYER && INFO_VALUE,
		"operator==(Player, Player)");

  DEBUG_RETURNING(&player1 == &player2,
		  INFO_PLAYER && INFO_VALUE,
		  "operator==(Player, Player)");
} // bool operator==(Player const& player1, Player const& player2)

/**
 **
 ** -> result
 **
 ** @param       player1 player 1 to compare
 ** @param       player2 player 2 to compare
 **
 ** @return      whether the players are not equal
 **              (they don't lie in the same memory)
 **
 ** @author      Diether Knof
 **
 ** @version     0.4.4
 **
 **/
bool
operator!=(Player const& player1, Player const& player2)
{
  DEBUG_CALLING(INFO_PLAYER && INFO_VALUE,
		"operator!=(Player, Player)");

  DEBUG_RETURNING(!(player1 == player2),
		  INFO_PLAYER && INFO_VALUE,
		  "operator!=(Player, Player)");
} // bool operator!=(Player const& player1, Player const& player2)

/**
 **
 ** save the player in the file 'filename'
 **
 ** @param	filename    file the player shall be saved
 **
 ** @return	whether the saving was sucessful
 **
 ** @author	Diether Knof
 **
 ** @version	0.5.2
 **
 **/
bool
Player::save(string const& filename) const
{
  DEBUG_CALLING(INFO_PLAYER && INFO_IO,
		"Player::save(filename)");

  ofstream ostr(filename.c_str());
  if (ostr.fail())
    DEBUG_RETURNING(false,
		    INFO_PLAYER && INFO_IO,
		    "Player::save(filename)");    

  this->out(ostr);

  DEBUG_RETURNING(ostr.good(),
		  INFO_PLAYER && INFO_IO,
		  "Player::save(filename)");    
} // virtual bool Player::save(string const& filename) const

/**
 **
 ** ouput of the player in the stream
 **
 ** @param       ostr    output stream
 **
 ** @return      output stream
 **
 ** @author      Borg Enders
 ** @author      Diether Knof
 **
 ** @version     0.4.4
 **
 **/
ostream&
Player::out(ostream& ostr) const
{
  DEBUG_CALLING(INFO_PLAYER && INFO_IO,
		"Player::out(ostr)");

  ostr << "Player: " << this->name() << "\n"
    << "Player type: " << this->type() << "\n";

#if 0
  if (::game_status & GAMESTATUS::GAME) {
    ostr << "Team" << ": " << this->team() << "\n"
      << "Announcement" << ": " << this->announcement()
      << "\n"
      << this->hand()
      << "Teaminfo" << ": \n";
    for(vector<Player*>::const_iterator player = this->game().player_begin();
	player != this->game().player_end();
	player++)
      ostr << (*player)->no() << ": " << this->teaminfo(**player) << "\n";

  } // if (::gamestatus & GAMESTATUS::GAME)
#endif

  DEBUG_RETURNING(ostr,
		  INFO_PLAYER && INFO_IO,
		  "Player::out(ostr)");    
} // virtual ostream& Player::out(ostream& ostr) const

/**
 **
 ** output of the player
 **
 ** @param       ostr    output stream
 ** @param       player  player to be put in the stream
 **
 ** @return      output stream
 **
 ** @author      Borg Enders
 ** @author      Diether Knof
 **
 ** @version     0.4.4
 **
 **/
ostream&
operator<<(ostream& ostr, const Player& player)
{
  DEBUG_CALLING(INFO_PLAYER && INFO_IO,
		"operator<<(ostr, player)");

  player.out(ostr);

  DEBUG_RETURNING(ostr,
		  INFO_PLAYER && INFO_IO,
		  "operator<<(ostr, player)");    
} // ostream& operator<<(ostream& ostr, const Player& player)


/**
 **
 ** -> result
 **
 ** @param       -
 **
 ** @return      game the player is playing
 **
 ** @author      Borg Enders
 ** @author      Diether Knof
 **
 ** @version     0.4.4
 **
 **/
Game&
Player::game()
{
  DEBUG_CALLING(INFO_PLAYER && INFO_VALUE,
		"Player::game()");

  DEBUG_ASSERTION(this->game_p,
		  "Player::game(): 'game_p' is a NULL-pointer");

  DEBUG_RETURNING(*(this->game_p),
		  INFO_PLAYER && INFO_VALUE,
		  "Player::game()");
} // Game& Player::game()

/**
 **
 ** -> result
 **
 ** @param       -
 **
 ** @return      game the player is playing
 **
 ** @author      Borg Enders
 ** @author      Diether Knof
 **
 ** @version     0.4.4
 **
 **/
Game const&
Player::game() const
{
  DEBUG_CALLING(INFO_PLAYER && INFO_VALUE,
		"Player::game()");

  DEBUG_ASSERTION(this->game_p != NULL,
		  "Player::game(): 'game_p' is a NULL-pointer");

  DEBUG_RETURNING(*(this->game_p),
		  INFO_PLAYER && INFO_VALUE,
		  "Player::game()");
} // Game const& Player::game() const

/**
 **
 ** set the game
 **
 ** @param       game    new game
 **
 ** @return      game the player is playing
 **
 ** @author      Borg Enders
 ** @author      Diether Knof
 **
 ** @version     0.4.4
 **
 **/
Game&
Player::game_set(Game& game)
{
  DEBUG_CALLING(INFO_PLAYER && INFO_VALUE,
		"Player::game_set(game)");

  this->game_p = &game;

  DEBUG_RETURNING(this->game(),
		  INFO_PLAYER && INFO_VALUE,
		  "Player::game_set(game)");
} // Game& Player::game()

/**
 **
 ** -> result
 **
 ** @param       -
 **
 ** @return      type
 **
 ** @author      Borg Enders
 ** @author      Diether Knof
 **
 ** @version     0.4.4
 **
 **/
Player::Type const&
Player::type() const
{
  DEBUG_CALLING(INFO_PLAYER && INFO_VALUE,
		"Player::type()");

  DEBUG_RETURNING(this->type_p,
		  INFO_PLAYER && INFO_VALUE,
		  "Player::type()");
} // Player::Type const& Player::type() const

/**
 **
 ** sets the type
 **
 ** @param       type - new player type
 **
 ** @return      new type
 **
 ** @author      Borg Enders
 ** @author      Diether Knof
 **
 ** @version     0.4.4
 **
 **/
Player::Type const&
Player::type_set(Type const& type)
{
  DEBUG_CALLING(INFO_PLAYER && INFO_VALUE,
		"Player::type_set()");

  this->type_p = type;

  DEBUG_RETURNING(this->type(),
		  INFO_PLAYER && INFO_VALUE,
		  "Player::type_set()");
} // Player::Type const& Player::type_set(Type const& type)

/**
 **
 ** -> result
 **
 ** @param       -
 **
 ** @return      name of the player
 **              if it is empty, take a default
 **
 ** @author      Borg Enders
 ** @author      Diether Knof
 **
 ** @version     0.4.4
 **
 **/
string const
Player::name() const
{
  DEBUG_CALLING(INFO_PLAYER && INFO_VALUE,
		"Player::name()");

  if (this->name_p.empty())
    DEBUG_RETURNING(Player::default_name(this->type()),
		    INFO_PLAYER && INFO_VALUE,
		    "Player::name()");


  DEBUG_RETURNING(this->name_p,
		  INFO_PLAYER && INFO_VALUE,
		  "Player::name()");
} // string const Player::name() const

/**
 **
 ** sets the name
 **
 ** @param       name    new name
 **
 ** @return      name
 **
 ** @author      Borg Enders
 ** @author      Diether Knof
 **
 ** @version     0.4.4
 **
 **/
string const
Player::name_set(string const& name)
{
  DEBUG_CALLING(INFO_PLAYER && INFO_VALUE,
		"Player::name_set(name)");

  if (Player::default_name(this->type()) == name)
    this->name_p = "";
  else
    this->name_p = name;

  DEBUG_RETURNING(this->name(),
		  INFO_PLAYER && INFO_VALUE,
		  "Player::name_set(name)");
} // string const Player::name_set(string const& name)

/**
 **
 ** -> result
 **
 ** @param       -
 **
 ** @return      value of the name of the player
 **
 ** @author      Diether Knof
 **
 ** @version     0.5.3
 **
 **/
string const&
Player::name_value() const
{
  DEBUG_CALLING(INFO_PLAYER && INFO_VALUE,
		"Player::name_value()");

  DEBUG_RETURNING(this->name_p,
		  INFO_PLAYER && INFO_VALUE,
		  "Player::name_value()");
} // string const& Player::name_value() const

/**
 **
 ** -> result
 **
 ** @param       type    the type
 **
 ** @return      default name of the type
 **
 ** @author      Diether Knof
 **
 ** @version     0.5.3
 **
 **/
string
Player::default_name(Type const& type)
{
  DEBUG_CALLING(INFO_PLAYER && INFO_BASISTYPES && INFO_NAME,
		"Player::default_name(type)");

  switch(type) {
  case HUMAN:
    DEBUG_RETURNING(::setting(Setting::NAME),
		    INFO_PLAYER && INFO_VALUE,
		    "Player::default_name(type)");
    break;
  default:
    DEBUG_RETURNING(::name(type),
		    INFO_PLAYER && INFO_VALUE,
		    "Player::default_name(type)");
    break;
  } // switch(this->type())
} // string Player::default_name(const Player::Type& type)

/**
 **
 ** -> result
 **
 ** @param       -
 **
 ** @return      the number of the player in the game
 **
 ** @author      Borg Enders
 ** @author      Diether Knof
 **
 ** @version     0.4.4
 **
 **/
unsigned
Player::no() const
{
  DEBUG_CALLING(INFO_PLAYER && INFO_VALUE,
		"Player::no()");

#ifdef POSTPHONED
  DEBUG_ASSERTION((::game_status & GAMESTATUS::GAME),
		  "Player::no():\n"
		  "  game_status is not GAME");
#endif

#ifdef POSTPHONED
  DEBUG_RETURNING(this->game().no_of_player(*this),
		  INFO_PLAYER && INFO_VALUE,
		  "Player::no()");
#else
  DEBUG_ASSERTION((this->no_p != UINT_MAX),
		  "Player::no():\n"
		  "  no not set (use Player::no_set(unsigned))");

  DEBUG_RETURNING(this->no_p,
		  INFO_PLAYER && INFO_VALUE,
		  "Player::no()");
#endif
} // unsigned Player::no() const

/**
 **
 ** sets the playernumber
 **
 ** @param       no      new playernumber
 **
 ** @return      the playernumber
 **
 ** @author      Diether Knof
 **
 ** @version     0.4.4
 **
 **/
unsigned
Player::no_set(unsigned const no)
{
  DEBUG_CALLING(INFO_PLAYER && INFO_VALUE,
		"Player::no_set()");

#ifdef POSTPHONED
  DEBUG_ASSERTION((::game_status & GAMESTATUS::GAME),
		  "Player::no_set():\n"
		  "  game_status is not GAME");

  DEBUG_ASSERTION((no < this->game().playerno()),
		  "Player::no_set():\n"
		  "  no is too great");
#else
  DEBUG_ASSERTION((no < ::party.playerno()),
		  "Player::no_set():\n"
		  "  no is too great");
#endif

  this->no_p = no;

  DEBUG_RETURNING(this->no(),
		  INFO_PLAYER && INFO_VALUE,
		  "Player::playerno()");
} // unsigned Player::no() const

/**
 **
 ** -> result
 **
 ** @param       -
 **
 ** @return      hand
 **
 ** @author      Borg Enders
 ** @author      Diether Knof
 **
 ** @version     0.4.4
 **
 **/
Hand const&
Player::hand() const
{
  DEBUG_CALLING(INFO_PLAYER && INFO_VALUE,
		"Player::hand() const");

  DEBUG_RETURNING(this->hand_p,
		  INFO_PLAYER && INFO_VALUE,
		  "Player::hand() ");
} // Hand const& Player::hand() const

/**
 **
 ** -> result
 **
 ** @param       -
 **
 ** @return      hand
 **
 ** @author      Borg Enders
 ** @author      Diether Knof
 **
 ** @version     0.4.4
 **
 **/
Hand&
Player::hand()
{
  DEBUG_CALLING(INFO_PLAYER && INFO_VALUE,
		"Player::hand()");

  DEBUG_RETURNING(this->hand_p,
		  INFO_PLAYER && INFO_VALUE,
		  "Player::hand() ");
} // Hand& Player::hand()


/**
 **
 ** -> result
 **
 ** @param       -
 **
 ** @return      sorted hand
 **
 ** @author      Diether Knof
 **
 ** @version     0.6.4
 **
 **/
SortedHand const&
Player::sorted_hand() const
{
  DEBUG_CALLING(INFO_PLAYER && INFO_VALUE,
		"Player::sorted_hand() const");

  DEBUG_RETURNING(this->sorted_hand_p,
		  INFO_PLAYER && INFO_VALUE,
		  "Player::sorted_hand() ");
} // SortedHand const& Player::sorted_hand() const

/**
 **
 ** -> result
 **
 ** @param       -
 **
 ** @return      hand
 **
 ** @author      Diether Knof
 **
 ** @version     0.6.4
 **
 **/
SortedHand&
Player::sorted_hand()
{
  DEBUG_CALLING(INFO_PLAYER && INFO_VALUE,
		"Player::sorted_hand()");

  DEBUG_RETURNING(this->sorted_hand_p,
		  INFO_PLAYER && INFO_VALUE,
		  "Player::sorted_hand() ");
} // SortedHand& Player::hand()


/**
 **
 ** sort the hand
 **
 ** @param       -
 **
 ** @return      sorted hand
 **
 ** @author      Borg Enders
 ** @author      Diether Knof
 **
 ** @version     0.5.4
 **
 **/
Hand const&
Player::hand_sort()
{
  DEBUG_CALLING(INFO_PLAYER && INFO_VALUE,
		"Player::hand_sort()");

  if (::setting(Setting::CARDS_ORDER).sorted()
      && (this->game_p != NULL)
      && !(this->game().isvirtual())) {
    bool const changed = this->sorted_hand().sort();
    if (changed)
      ::ui->hand_update(*this);
  } // if (::setting(Setting::CARDS_ORDER).sorted())

  DEBUG_RETURNING(this->hand(),
		  INFO_PLAYER && INFO_VALUE,
		  "Player::hand_sort()");
} // Hand const& Player::hand_sort()

/**
 **
 ** mixes the hand
 **
 ** @param       -
 **
 ** @return      mixed hand
 **
 ** @author      Borg Enders
 ** @author      Diether Knof
 **
 ** @version     0.5.4
 **
 **/
Hand const&
Player::hand_mix()
{
  DEBUG_CALLING(INFO_PLAYER && INFO_VALUE,
		"Player::hand_mix()");

  if (!::setting(Setting::CARDS_ORDER).sorted()) {
    this->sorted_hand().mix();
    if ((this->game_p != NULL)
	&& (!this->game().isvirtual()))
      ::ui->hand_update(*this);
  } // if (!::setting(Setting::CARDS_ORDER).sorted())

  DEBUG_RETURNING(this->hand(),
		  INFO_PLAYER && INFO_VALUE,
		  "Player::hand_mix()");
} // Hand const& Player::hand_mix()


/**
 **
 ** set the hand
 **
 ** @param       hand    new hand
 **
 ** @return      player with hand h
 **
 ** @author      Borg Enders
 ** @author      Diether Knof
 **
 ** @version     0.6.4
 **
 **/
Hand const&
Player::hand_set(Hand const& hand)
{
  DEBUG_CALLING(INFO_PLAYER && INFO_VALUE,
		"Player::hand_set(hand)");

  this->hand_p = hand;
  if (!this->game().isvirtual()
      && (*this == this->game().player(this->no())) )
    // In virtual games the hand is not shown, so it does not have to be sorted.
    if (::setting(Setting::CARDS_ORDER).sorted())
      this->hand_sort();
    else
      this->hand_mix();

  DEBUG_RETURNING(this->hand(),
		  INFO_PLAYER && INFO_VALUE,
		  "Player::hand_set(hand)");
} // Hand const& Player::hand_set(Hand const& hand)


/**
 **
 ** -> result
 **
 ** @param       -
 **
 ** @return      whether the player is re
 **
 ** @author      Borg Enders
 ** @author      Diether Knof
 **
 ** @version     0.4.4
 **
 **/
bool
Player::isre() const
{
  DEBUG_CALLING(INFO_PLAYER && INFO_VALUE,
		"Player::isre()");

  DEBUG_RETURNING((this->teaminfo(*this) == TEAM::RE),
		  INFO_PLAYER && INFO_VALUE,
		  "Player::isre()");
} // bool Player::isre() const

/**
 **
 ** -> result
 **
 ** @param       -
 **
 ** @return      whether the player has swines
 **
 ** @author      Borg Enders
 ** @author      Diether Knof
 **
 ** @version     0.4.5
 **
 **/
bool
Player::swines_has() const
{
  DEBUG_CALLING(INFO_PLAYER && INFO_VALUE,
		"Player::swines_has()");

  if (this->game().swines_announced()
      && (this == this->game().swines_owner())) {
    if ((::game_status == GAMESTATUS::GAME_POVERTY_SHIFT)
	&& (*this == this->game().soloplayer()))
      DEBUG_RETURNING(true,
		      INFO_PLAYER && INFO_VALUE,
		      "Player::swines_has() = true");
    // search a swine in all cards of the hand
    for (unsigned c = 0; c < hand().cardsnumber_all(); c++)
      if (hand().card_all(c).isswine())
	DEBUG_RETURNING(true,
			INFO_PLAYER && INFO_VALUE,
			"Player::swines_has() = true");
  } // if (this->game().swines_announced())

  DEBUG_RETURNING(false,
		  INFO_PLAYER && INFO_VALUE,
		  "Player::swines_has() = false");
} // bool Player::swines_has() const

/**
 **
 ** -> result
 **
 ** @param       -
 **
 ** @return      whether the player has hyperswines
 **
 ** @author      Borg Enders
 ** @author      Diether Knof
 **
 ** @version     0.4.5
 **
 **/
bool
Player::hyperswines_has() const
{
  DEBUG_CALLING(INFO_PLAYER && INFO_VALUE,
		"Player::hyperswines_has()");

  if (this->game().hyperswines_announced()
      && (this == this->game().hyperswines_owner())) {
    // search a hyperswine in all cards of the hand
    for (unsigned c = 0; c < hand().cardsnumber_all(); c++)
      if (hand().card_all(c).ishyperswine())
	DEBUG_RETURNING(true,
			INFO_PLAYER && INFO_VALUE,
			"Player::hyperswines_has()");
  } // if (this->game().hyperswines_announced())

  DEBUG_RETURNING(false,
		  INFO_PLAYER && INFO_VALUE,
		  "Player::hyperswines_has()");
} // bool Player::hyperswines_has() const


/**
 **
 ** -> result
 **
 ** @param       -
 **
 ** @return      team of the player
 **
 ** @author      Borg Enders
 ** @author      Diether Knof
 **
 ** @version     0.4.4
 **
 **/
Team
Player::team() const
{
  DEBUG_CALLING(INFO_PLAYER && INFO_VALUE,
		"Player::team()");

  DEBUG_RETURNING(this->teaminfo(*this),
		  INFO_PLAYER && INFO_VALUE,
		  "Player::team()");
} // Team Player::team() const

/**
 **
 ** -> result
 **
 ** @param       player whose teaminfo is returned
 **
 ** @return      the team of the given player, as far as this player knows it
 **
 ** @author      Borg Enders
 ** @author      Diether Knof
 **
 ** @version     0.4.4
 **
 **/
Team const&
Player::teaminfo(Player const& player) const
{
  DEBUG_CALLING(INFO_PLAYER && INFO_VALUE,
		"Player::teaminfo(player)");

  DEBUG_ASSERTION((player.no() < this->teaminfo_p.size()),
		  "Player::teaminfo(player):\n"
		  "  player.no() too great");

  DEBUG_RETURNING(this->teaminfo_p[player.no()],
		  INFO_PLAYER && INFO_VALUE,
		  "Player::teaminfo(player)");    
} // Team const& Player::teaminfo(Player const& player) const


/**
 **
 ** updates the information of the teams (uses the current trick)
 **
 ** @param       -
 **
 ** @return      the known teams
 **
 ** @author      Borg Enders
 ** @author      Diether Knof
 **
 ** @version     0.4.4
 **
 ** @todo	two contra + 1 re without trump
 **
 **/
void
Player::teaminfo_update()
{
  DEBUG_CALLING(INFO_PLAYER && INFO_VALUE,
		"Player::teaminfo_update()");

  using namespace TEAM;

  // update with the teaminfo of 'game'
  for(vector<Player*>::const_iterator player = this->game().player_begin();
      player != this->game().player_end();
      player++) {
    if ((this->game().teaminfo(**player) == RE)
	|| (this->game().teaminfo(**player) == CONTRA))
      this->teaminfo_p[(*player)->no()] = this->game().teaminfo(**player);
  }

  // set the team of himself
  if ((this->game().type() == GAMETYPE::NORMAL)
      && (this->teaminfo(*this) == UNKNOWN))
    // look, whether there is a club queen in the hand
    this->teaminfo_p[this->no()]
      = ((this->hand().getpos_all(Card::CLUB_QUEEN) != UINT_MAX) ? RE : CONTRA);

  { // count the re and contra
    unsigned re_no = 0; // number of re
    unsigned contra_no = 0; // number of re

    for(vector<Player*>::const_iterator player = this->game().player_begin();
	player != this->game().player_end();
	player++) {
      if (this->teaminfo(**player) == RE)
	re_no += 1;
      else if (this->teaminfo(**player) == CONTRA)
	contra_no += 1;
    } // for (player)

    if (re_no + contra_no
	< this->game().rule()(Rule::NUMBER_OF_PLAYERS_IN_GAME)) {
      // there are no more the two players in the re team
      if (re_no == this->game().rule()(Rule::NUMBER_OF_PLAYERS_PER_TEAM))
	for(vector<Player*>::const_iterator player = this->game().player_begin();
	    player != this->game().player_end();
	    player++)
	  if (this->teaminfo(**player) != RE) {
	    teaminfo_p[(*player)->no()] = CONTRA;
	    if (&(this->game()) == &(::party.game()))
	      ::ui->teaminfo_update(**player);
	  }

      // one player must be re
      if ((contra_no == this->game().rule()(Rule::NUMBER_OF_PLAYERS_IN_GAME) - 1)
	  || ((contra_no
	       == this->game().rule()(Rule::NUMBER_OF_PLAYERS_IN_GAME) - 2)
	      && (this->team() == RE))) {
	// if there are 3 contra, the remaining player must be re
	// if I am re and there are two contra, the remaining player must be re
	for(vector<Player*>::const_iterator player = this->game().player_begin();
	    player != this->game().player_end();
	    player++)
	  if (this->teaminfo(**player) != CONTRA) {
	    teaminfo_p[(*player)->no()] = RE;
	    if (&(this->game()) == &(::party.game()))
	      ::ui->teaminfo_update(**player);
	  }
      } // if (contra max)
    } // if (not all teams known)
  } // count the re and contra

  DEBUG_RETURNING(VOID,
		  INFO_PLAYER && INFO_VALUE,
		  "Player::teaminfo_update()");
} // void Player::teaminfo_update()

/**
 **
 ** -> result
 **
 ** @param       -
 **
 ** @return      announcment of this player (taken from 'game')
 **
 ** @author      Borg Enders
 ** @author      Diether Knof
 **
 ** @version     0.4.4
 **
 **/
Announcement const&
Player::announcement() const
{
  DEBUG_CALLING(INFO_PLAYER && INFO_VALUE,
		"Player::announcement()");

  DEBUG_RETURNING(this->game().announcement_of_player(*this).announcement,
		  INFO_PLAYER && INFO_VALUE,
		  "Player::announcement()");
} // Announcement const& Player::announcement() const

/**
 **
 ** -> result
 **
 ** @param       -
 **
 ** @return      the number of tricks the player has (taken from 'game')
 **
 ** @author      Diether Knof
 **
 ** @version     0.6.0
 **
 **/
unsigned
Player::number_of_tricks() const
{
  DEBUG_CALLING(INFO_PLAYER && INFO_VALUE,
		"Player::number_of_tricks()");

  DEBUG_ASSERTION((this->game_p != NULL),
		  "Player::number_of_tricks():\n"
		  "  'this->game' == NULL");

  DEBUG_RETURNING(this->game().numberoftricks_of_player(*this),
		  INFO_PLAYER && INFO_VALUE,
		  "Player::number_of_tricks()");
} // unsigned Player::number_of_tricks() const

/**
 **
 ** -> result
 **
 ** @param       -
 **
 ** @return      the points of the tricks the player has (taken from 'game')
 **
 ** @author      Diether Knof
 **
 ** @version     0.6.0
 **
 **/
unsigned
Player::points_in_trickpile() const
{
  DEBUG_CALLING(INFO_PLAYER && INFO_VALUE,
		"Player::points_in_trickpile()");

  DEBUG_ASSERTION((this->game_p != NULL),
		  "Player::points_in_trickpile():\n"
		  "  'this->game' == NULL");

  DEBUG_RETURNING(this->game().points_of_player(*this),
		  INFO_PLAYER && INFO_VALUE,
		  "Player::points_in_trickpile()");
} // unsigned Player::points_in_trickpile() const

/**
 **
 ** the player can make an announcement
 **
 ** @param       -
 **
 ** @return      announcement of the player
 **
 ** @author      Borg Enders
 ** @author      Diether Knof
 **
 ** @version     0.4.4
 **
 **/
Announcement
Player::announcement_request() const
{
  DEBUG_CALLING(INFO_PLAYER && INFO_OTHER_FUNCTION,
		"Player::announcement_request()");

  DEBUG_RETURNING(ANNOUNCEMENT::NOANNOUNCEMENT,
		  INFO_PLAYER && INFO_OTHER_FUNCTION,
		  "Player::announcement_request()");
} // Announcement Player::announcement_request() const

/**
 **
 ** the given player has made the given announcement
 **
 ** @param       announcement    the announcement
 ** @param       player          the player, who has made the announcement
 **
 ** @return      -
 **
 ** @author      Borg Enders
 ** @author      Diether Knof
 **
 ** @version     0.4.4
 **
 **/
void
Player::announcement_made(Announcement const& announcement,
			  Player const& player)
{
  DEBUG_CALLING(INFO_PLAYER && INFO_OTHER_FUNCTION,
		"Player::announcement_made(announcement, player)");

  DEBUG_RETURNING(VOID,
		  INFO_PLAYER && INFO_OTHER_FUNCTION,
		  "Player::announcement_made(announcement, player)");
} // void Player::announcement_made(Announcement const& announcement, Player const& player)

/**
 **
 ** 'player' shifts 'cardno' cards
 **
 ** @param      player  the player who shifts the cards
 ** @param      cardno  the number of cards that are shifted
 **
 ** @return     -
 **
 ** @author     Diether Knof
 **
 ** @version    0.4.5
 **
 **/
void
Player::poverty_shift(Player const& player, unsigned const cardno)
{ 
  DEBUG_CALLING(INFO_PLAYER && INFO_GAMEPLAY,
		"Player::poverty_shift(player, cardno)");

  DEBUG_RETURNING(VOID,
		  INFO_PLAYER && INFO_GAMEPLAY,
		  "Player::poverty_shift(player, cardno)");
} // void Player::poverty_shift(Player const& player, unsigned const cardno)

/**
 **
 ** 'player' denied to take the shifted cards
 **
 ** @param      player  the player who has denied to take the cards
 **
 ** @return     -
 **
 ** @author     Diether Knof
 **
 ** @version    0.4.5
 **
 **/
void
Player::poverty_take_denied(Player const& player)
{ 
  DEBUG_CALLING(INFO_PLAYER && INFO_GAMEPLAY,
		"Player::poverty_take_denied(player)");

  DEBUG_RETURNING(VOID,
		  INFO_PLAYER && INFO_GAMEPLAY,
		  "Player::poverty_take_denied(player)");
} // void Player::poverty_take_denied(Player const& player)

/**
 **
 ** all players have denied to take the cards
 **
 ** @param      -
 **
 ** @return     -
 **
 ** @author     Diether Knof
 **
 ** @version    0.4.5
 **
 **/
void
Player::poverty_take_denied_by_all()
{ 
  DEBUG_CALLING(INFO_PLAYER && INFO_GAMEPLAY,
		"Player::poverty_take_denied_by_all()");

  DEBUG_RETURNING(VOID,
		  INFO_PLAYER && INFO_GAMEPLAY,
		  "Player::poverty_take_denied_by_all()");
} // void Player::poverty_take_denied_by_all()

/**
 **
 ** 'player' accepts to take the shifted cards
 ** and returns 'cardno' cards with 'trumpno' trumps
 **
 ** @param      player  the player who has accepted to take the cards
 ** @param      cardno  number of cards that are given back
 ** @param      trumpno number of trumps of the cards
 **
 ** @return     -
 **
 ** @author     Diether Knof
 **
 ** @version    0.4.5
 **
 **/
void
Player::poverty_take_accepted(Player const& player,
			      unsigned const cardno, unsigned const trumpno)
{ 
  DEBUG_CALLING(INFO_PLAYER && INFO_GAMEPLAY,
		"Player::poverty_take_accepted(player, cardno, trumpno)");

  DEBUG_RETURNING(VOID,
		  INFO_PLAYER && INFO_GAMEPLAY,
		  "Player::poverty_take_accepted(player, cardno, trumpno)");
} // void Player::poverty_take_accepted(Player const& player, unsigned const cardno, unsigned const trumpno)

/**
 **
 ** returns which cards the player shifts
 **
 ** @param      -
 **
 ** @return     the cards that are to be shifted
 **
 ** @author     Diether Knof
 **
 ** @version    0.4.5
 **
 **/
Hand
Player::poverty_shift()
{ 
  DEBUG_CALLING(INFO_PLAYER && INFO_GAMEPLAY,
		"Player::poverty_shift()");

  cerr << "call of Player::poverty shift()"
    << endl;

  DEBUG_RETURNING(Hand(),
		  INFO_PLAYER && INFO_GAMEPLAY,
		  "Player::poverty_shift()");
} // void Player::poverty_shift(Player const& player)

/**
 **
 ** returns whether 'player' accepts the shifted cards
 **
 ** @param      cardno  the number of shifted cards
 **
 ** @return     whether to accept the cards
 **
 ** @author     Diether Knof
 **
 ** @version    0.4.5
 **
 **/
bool
Player::poverty_take_accept(unsigned const cardno)
{ 
  DEBUG_CALLING(INFO_PLAYER && INFO_GAMEPLAY,
		"Player::poverty_take_accept(cardno)");

  cerr << "call of Player::poverty_take_accept(cardno)"
    << endl;

  DEBUG_RETURNING(false,
		  INFO_PLAYER && INFO_GAMEPLAY,
		  "Player::poverty_take_accept(cardno)");
} // void Player::poverty_take_accept(unsigned const cardno)

/**
 **
 ** changes the cards from the poverty-player
 **
 ** @param      cards   the cards that are given to the player
 **
 ** @return     the cards that are returned to the poverty-player
 **
 ** @author     Diether Knof
 **
 ** @version    0.4.5
 **
 **/
Hand
Player::poverty_cards_change(Hand const& cards)
{ 
  DEBUG_CALLING(INFO_PLAYER && INFO_GAMEPLAY,
		"Player::poverty_cards_change(cards)");

  cerr << "call of Player::poverty_cards_change(cards)"
    << endl;

  DEBUG_RETURNING(Hand(),
		  INFO_PLAYER && INFO_GAMEPLAY,
		  "Player::poverty_cards_change(cards)");
} // void Player::poverty_cards_change(Hand const& cards)

/**
 **
 ** gets the cards from the partner and add them to the hand
 **
 ** @param	cards	the cards that are given to the player
 **
 ** @return	-
 **
 ** @author	Diether Knof
 **
 ** @version	0.5
 **
 **/
void
Player::poverty_cards_get_back(Hand const& cards)
{ 
  DEBUG_CALLING(INFO_PLAYER && INFO_GAMEPLAY,
		"Player::poverty_cards_get_back(cards)");

  this->hand().add(cards);
  this->hand_sort();

  DEBUG_RETURNING(VOID,
		  INFO_PLAYER && INFO_GAMEPLAY,
		  "Player::poverty_cards_get_back(cards)");
} // void Player::poverty_cards_get_back(Hand const& cards)

/**
 **
 ** genscher: -> result
 **
 ** @param	-
 **
 ** @return	pointer to the new teammate,
 **		NULL if the genscher is not to be announced
 **
 ** @author	Diether Knof
 **
 ** @version	0.5.4
 **
 **/
Player const*
Player::genscher_partner()
{ 
  DEBUG_CALLING(INFO_PLAYER && INFO_GAMEPLAY,
		"Player::genscher_partner()");

  DEBUG_RETURNING(NULL,
		  INFO_PLAYER && INFO_GAMEPLAY,
		  "Player::genscher_partner()");
} // Player const* Player::genscher_partner()

/**
 **
 ** genscher: Information of the new team
 **
 ** @param	player	genscher player
 ** @param	partner	partner of the gensher player
 **
 ** @return	-
 **
 ** @author	Diether Knof
 **
 ** @version	0.5.4
 **
 **/
void
Player::genscher(Player const& player,
		 Player const& partner)
{ 
  DEBUG_CALLING(INFO_PLAYER && INFO_GAMEPLAY,
		"Player::genscher(player, partner)");

  DEBUG_RETURNING(VOID,
		  INFO_PLAYER && INFO_GAMEPLAY,
		  "Player::genscher(player, partner)");
} // void Player::genscher(Player const& player, Player const& partner)

/**
 **
 ** a new game has started - init the player:
 ** empty the hand,
 ** set the teaminfo to the teaminfo of the game
 **
 ** @param       game    the game
 **
 ** @return      -
 **
 ** @author      Borg Enders
 ** @author      Diether Knof
 **
 ** @version     0.4.4
 **
 **/
void
Player::new_game(Game& game)
{ 
  DEBUG_CALLING(INFO_PLAYER && INFO_VALUE,
		"Player::new_game()");

  this->game_p = &game;
  this->hand_p = Hand();

  this->teaminfo_p = vector<Team>(this->game().playerno(), TEAM::UNKNOWN);

  DEBUG_RETURNING(VOID,
		  INFO_PLAYER && INFO_VALUE,
		  "Player::new_game()");
} // void Player::new_game()

/**
 **
 ** the player makes his reservation
 **
 ** @param       isDuty ?
 **
 ** @return      reservation of the player
 **
 ** @author      Borg Enders
 ** @author      Diether Knof
 **
 ** @version     0.4.4
 **
 ** @todo	isDuty documentation
 **
 **/
Reservation
Player::reservation_get( bool isDuty ) 
{ 
  DEBUG_CALLING(INFO_PLAYER && INFO_VALUE,
		"Player::reservation_get()");

  DEBUG_ASSERTION(false,
		  "Player::reservation_get():\n"
		  "  call of this function");

  DEBUG_RETURNING(this->reservation_get_default(),
		  INFO_PLAYER && INFO_VALUE,
		  "Player::reservation_get()");
} // Reservation Player::reservation_get() const

/**
 **
 ** -> result
 ** that is swines and hyperswines, if the player has them,
 ** poverty (nines, kings, trump), marriage
 **
 ** @param	-
 **
 ** @return	default reservation of the player
 **
 ** @author	Diether Knof
 **
 ** @version	0.6.0
 **
 **/
Reservation
Player::reservation_get_default() const
{ 
  DEBUG_CALLING(INFO_PLAYER && INFO_VALUE,
		"Player::reservation_get_default()");

  Reservation reservation;

  if (this->hand().numberofclubqueens()
      == this->game().rule()(Rule::NUMBER_OF_SAME_CARDS)) {
    reservation.game_type = GAMETYPE::MARRIAGE;
    if (this->game().rule()(MARRIAGE_SELECTOR::FIRST_FOREIGN))
      reservation.marriage_selector = MARRIAGE_SELECTOR::FIRST_FOREIGN;
    else if (this->game().rule()(MARRIAGE_SELECTOR::FIRST_COLOR))
      reservation.marriage_selector = MARRIAGE_SELECTOR::FIRST_COLOR;
    else if (this->game().rule()(MARRIAGE_SELECTOR::FIRST_TRUMP))
      reservation.marriage_selector = MARRIAGE_SELECTOR::FIRST_TRUMP;
    else if (this->game().rule()(MARRIAGE_SELECTOR::FIRST_CLUB))
      reservation.marriage_selector = MARRIAGE_SELECTOR::FIRST_CLUB;
    else if (this->game().rule()(MARRIAGE_SELECTOR::FIRST_SPADE))
      reservation.marriage_selector = MARRIAGE_SELECTOR::FIRST_SPADE;
    else if (this->game().rule()(MARRIAGE_SELECTOR::FIRST_HEART))
      reservation.marriage_selector = MARRIAGE_SELECTOR::FIRST_HEART;
    else
      DEBUG_ASSERTION(false,
		      "Player::reservation_get_default():\n"
		      "  no marriage selector valid.\n"
		      "  Ruleset:"
		      << this->game().rule());
  }

  if (this->game().rule()(Rule::SWINES)
      && (this->hand().numberoftrumpaces()
	  == this->game().rule()(Rule::NUMBER_OF_SAME_CARDS)))
    reservation.swines = true;

  if (this->game().rule()(Rule::HYPERSWINES)
      && (this->hand().numberoftrumpnines()
	  == this->game().rule()(Rule::NUMBER_OF_SAME_CARDS)))
    reservation.hyperswines = true;

  if (this->game().rule()(Rule::POVERTY)
      && (this->hand().numberoftrumps()
	  <= Rule::MAX_NUMBER_OF_POVERTY_TRUMPS))
    reservation.game_type = GAMETYPE::POVERTY;

  if (this->game().rule()(Rule::THROW_WHEN_FOX_HIGHEST_TRUMP)) {
    unsigned c;
    for (c = 0; c < this->hand().cardsnumber(); ++c)
      if (Card(Card::DIAMOND, Card::ACE).less(this->hand().card(c),
					      this->game()))
	break;

    if (c == this->hand().cardsnumber())
      reservation.game_type = GAMETYPE::FOX_HIGHEST_TRUMP;
  } // test fox highest trump

  if (this->game().rule()(Rule::THROW_WITH_FIVE_NINES)
      && (this->hand().numberofnines()
	  >= Rule::MIN_NUMBER_OF_THROWING_NINES))
    reservation.game_type = GAMETYPE::FIVE_NINES;

  if (this->game().rule()(Rule::THROW_WITH_SIX_KINGS)
      && (this->hand().numberofkings()
	  >= Rule::MIN_NUMBER_OF_THROWING_KINGS))
    reservation.game_type = GAMETYPE::SIX_KINGS;

  DEBUG_RETURNING(reservation,
		  INFO_PLAYER && INFO_VALUE,
		  "Player::reservation_get_default()");
} // Reservation Player::reservation_get_default() const

/**
 **
 ** the player plays a card
 **
 ** @param       -
 **
 ** @return      card of the player
 **
 ** @author      Borg Enders
 ** @author      Diether Knof
 **
 ** @version     0.4.4
 **
 **/
Card
Player::card_get()
{ 
  DEBUG_CALLING(INFO_PLAYER && INFO_VALUE,
		"Player::card_get()");

  DEBUG_ASSERTION(false,
		  "Player::card_get():\n"
		  "  call of this function");

  DEBUG_RETURNING(this->hand().card(0),
		  INFO_PLAYER && INFO_VALUE,
		  "Player::card_get()");
} // Card Player::card_get()

/**
 **
 ** 'player' has played the card 'card'
 **
 ** @param       card    played card
 ** @param       player  player who has played the card
 **
 ** @return      -
 **
 ** @author      Borg Enders
 ** @author      Diether Knof
 **
 ** @version     0.4.4
 **
 **/
void
Player::card_played(Card const& card, Player const& player)
{ 
  DEBUG_CALLING(INFO_PLAYER && INFO_VALUE,
		"Player::card_played(card, player)");

  DEBUG_RETURNING(VOID,
		  INFO_PLAYER && INFO_VALUE,
		  "Player::card_played(card, player)");
} // void Player::card_played(Card const& card, Player const& player)

/**
 **
 ** the trick is full
 **
 ** @param      trick   full trick
 **
 ** @return     -
 **
 ** @author     Diether Knof
 **
 ** @version    0.4.5
 **
 **/
void
Player::trick_full(Trick const& trick)
{ 
  DEBUG_CALLING(INFO_PLAYER && INFO_GAMEPLAY,
		"Player::trick_full(trick)");

  DEBUG_RETURNING(VOID,
		  INFO_PLAYER && INFO_GAMEPLAY,
		  "Player::trick_full(trick)");
} // void Player::trick_full(Trick const& trick)

/**
 **
 ** evaluation of game for playersDb
 **
 ** @param      g	gamepoints
 **
 ** @return     -
 **
 ** @author     Borg Enders
 **
 ** @version    0.6.1
 **
 **/
void Player::evaluate( GamePoints& g )
{
#ifndef RELEASE
  db_->evaluate( *this, g );
#endif
}

/**
 **
 ** -> result
 **
 ** @param       type    the type
 **
 ** @return      name of the type
 **
 ** @author      Borg Enders
 ** @author      Diether Knof
 **
 ** @version     0.4.4
 **
 **/
string
name(const Player::Type& type)
{
  DEBUG_CALLING(INFO_PLAYER && INFO_BASISTYPES && INFO_NAME,
		"string name(Player::Type)");

  string name;

  switch(type) {
  case Player::UNSET:
    name = "player type unset";
    break;
  case Player::HUMAN:
    name = "human";
    break;
  case Player::AI:
    name = "ai";
    break;
  case Player::AI_DUMMY:
    name = "dummy ai";
    break;
  } // switch(type)

  DEBUG_RETURNING(name,
		  INFO_PLAYER && INFO_BASISTYPES && INFO_NAME,
		  "string name(Player::Type)");
} // string name(const Player::Type& type)

/**
 **
 ** output of the name of 'type'
 **
 ** @param       ostr    output stream
 ** @param       type    player type
 **
 ** @return      output stream
 **
 ** @author      Borg Enders
 ** @author      Diether Knof
 **
 ** @version     0.4.4
 **
 **/
ostream&
operator<<(ostream& ostr, const Player::Type& type)
{
  DEBUG_CALLING(INFO_PLAYER && INFO_BASISTYPES && INFO_IO,
		"ostream& operator<<(ostr, Player::Type)");

  ostr << name(type);

  DEBUG_RETURNING(ostr,
		  INFO_PLAYER && INFO_BASISTYPES && INFO_IO,
		  "ostream& operator<<(ostr, Player::Type)");
} // ostream operator<<(ostream, type);
