// Player.cpp

#include "Player.h"

inline int max(int a, int b) { return (a > b) ? a : b; }

int Player::takeTurn(int opponentsLastRoll)
{
  RandomInt die1(1, 6);            // Declare the random dice.
  RandomInt die2(1, 6);

  myCurrentRoll = 0;
  myFirstRoll = die1 + die2;
  int scoreThisTurn = myFirstRoll;
  cout << "\n First Roll: " << die1 << " + " << die2
           << " = " << die1 + die2;

  updateData(opponentsLastRoll);   // Keep track of opponent if desired.

  for (;;)                         // Continue rolling until Stop() returns 

    {                              // true.
      if ( stop() )
        {
          cout << ". Stopping.\n" << endl;
          break;
        }
      else
          cout << ". Continuing . . . ";

      myCurrentRoll = die1.generate() + die2.generate();
      cout << "\n Next Roll: " << die1 << " + " << die2
           << " = " << die1 + die2;

      if (myCurrentRoll == myFirstRoll)
        {
          cout << ". OOOOPS!\n" << endl;
          scoreThisTurn = 0;
          break;
        }
      else
        scoreThisTurn = max(scoreThisTurn, myCurrentRoll);
    }

  raiseScore (scoreThisTurn);
  return scoreThisTurn;
}
