Score *Player::serveAPoint() {
    if( playersIdx != MAX_PLAYERS ) {
	std::cerr << "You need two players to play this game!" << std::endl;
	exit( 1 );
    }
    int rand = getARandomNumber(1, 100);
    Score *score = new PointScore( players[0], players[1] );
    score->addScore( rand <= getProbabilityOfWinningAServe() ? this : Player::otherPlayer( this ) );
    return score;
  }
Beispiel #2
0
Score *Player::serveAPoint() {
  //This function simulates a players server
  if( playersIdx != MAX_PLAYERS ) { //if there are less than two players
	std::cerr << "You need two players to play this game!" << std::endl;
	exit( 1 );
  }
  int rand = getARandomNumber(1, 100);
  Score *score = new PointScore( players[0], players[1] ); //create a new score object
  //if the random number is less than the probability of the player serving, return that player
  score->addScore( rand <= getProbabilityOfWinningAServe() ? this : Player::otherPlayer( this ) );
  return score; //returns the result of what and how a player won the serve
}