//==========================> RBallGame Implementation <===================
#include 
#include "rballgame.h"

//=================> Constructor <======================
RBallGame::RBallGame( float A, float B)
{
  _Aprob = A;
  _Bprob = B;
  _Ascore = _Bscore = 0;
  _Aserving = 1;
}

//==================> Ascore() <==========================
int
RBallGame::Ascore()
{
  return _Ascore;
}

//=================> Bscore() <===========================
int
RBallGame::Bscore()
{
  return _Bscore;
}

//================> isOver() <============================
int
RBallGame::isOver()
{
  return   (_Ascore >= 21) 
        || (_Bscore >= 21)
        || ((_Ascore == 11) && (_Bscore == 0))
        || ((_Bscore == 11) && (_Ascore == 0));
}

//================> doRally() <=========================
void
RBallGame::doRally()
{
  if (_Aserving)
    { 
      if (serverWins(_Aprob))
          _Ascore++;
      else
          _Aserving = 0;
    }
  else
    {
      if (serverWins(_Bprob))
          _Bscore++;
      else
          _Aserving = 1;
    }
}

//================> severWins() <========================
int 
RBallGame::serverWins(float Prob)
{
  return (rand() <= Prob * RAND_MAX);
}