Esempio n. 1
0
void dfs(Dice dice,int sx,int sy){
  //check stage
  //1 2
  // 0
  //3 4
  bool isok = false;

  for(int num=6;num>=4;num--){
    if(dice.surface[FRONT] == num){
      int dx = sx;
      int dy = sy - 1;
      if(stage[dy][dx].size() < stage[sy][sx].size()){
	dice.pitch(3);
	dfs(dice,dx,dy);
	isok = true;
	goto found;
      }
    }
    else if(dice.surface[REAR] == num){
      int dx = sx;
      int dy = sy + 1;
      if(stage[dy][dx].size() < stage[sy][sx].size()){
	dice.pitch(1);
	dfs(dice,dx,dy);
	isok = true;
	goto found;
      }
    }
    else if(dice.surface[LEFT] == num){
      int dx = sx - 1;
      int dy = sy;
      if(stage[dy][dx].size() < stage[sy][sx].size()){
	dice.roll(3);
	dfs(dice,dx,dy);
	isok = true;
	goto found;
	      
      }
    }
    else if(dice.surface[RIGHT] == num){
      int dx = sx + 1;
      int dy = sy;
      if(stage[dy][dx].size() < stage[sy][sx].size()){
	dice.roll(1);
	dfs(dice,dx,dy);
	isok = true;
	goto found;
      }
    }
  }
 found:;
  if(!isok){
    stage[sy][sx].push_back(dice.surface[TOP]);
  }
}
Esempio n. 2
0
File: 0198.cpp Progetto: motxx/AOJ
 bool equals(Dice rhs) const {
   for (int i = 0; i < 4; i++) {
     rhs.roll(NORTH);
     if (num[TOP] == rhs.getTop()) break;
     rhs.roll(WEST);
     if (num[TOP] == rhs.getTop()) break;
   }
   for (int i = 0; i < 4; i++) {
     if (check(rhs))
       return true;
     else
       rhs.rightHandedRoll();
   }
   return false;
 }
Esempio n. 3
0
int main()
{
	int i, n;
	float r;

	Dice dice;

	cout << "Enter how many times you wish to roll the dice:";
	cin >> n;

	for (i = 1; i <= n; i++)
	{
		r = dice.roll();
		dice.setsumrollvals(r);
		cout << "Roll " << i << ": " << (int)r << endl;
	}

	cout.precision(4);
	cout << "The average value rolled out of " << n << " rolls is: " << fixed << average(dice, n) << endl;

	const int size = 10;
	int arr[size];

	cout << endl << "Enter the 10 values to put into your array: " << endl;
	for (i = 0; i < size; i++)
	{
		cin >> arr[i];
	}

	cout << "The average value of the array is: " << fixed << average(arr, size) << endl;

	return 0;
}
Esempio n. 4
0
float Dice::average(Dice dice, int numRolls)
{
	int sum = 0;
	int i = 0;
	for (i = 1; i <= numRolls; i++)
	{
		sum += dice.roll();
	}
	return sum / numRolls;
}
Esempio n. 5
0
float Dice::average(Dice obj, int num) //Gets the value of each roll from getSum and then sums + averages
{//First use of the average function
	float av;
	int sum = 0;
	for (int i = 1; i < num; i++)
	{
		sum = sum + obj.roll();
	}
	av = sum / num; //num argument from user
	return av;
}
Esempio n. 6
0
int main()
{
	// Create a die
	Dice die;
	// Roll the die and print the result
	cout << "Die rolls a " << die.roll() << endl;
	// Print the average of 4 rolls
	cout << "4 roll avg: " << die.average(die, 4) << endl;
	// Declare an array of integers
	int rolls[5] = { 2,4,6,1,3 };
	// Find the average of the values in the array
	cout << "5 int avg: " << die.average(rolls, 5) << endl;
}
Dice* DiceManager::GetRandomDie()
{
	checkCreateInstance();
    
    //grab die
	int dice_idx = std::rand() % instance->available_dice.size();
	Dice* dice = instance->available_dice[dice_idx];
	dice->roll();
	
	//make sure this is marked as unavailable
	instance->available_dice.erase(instance->available_dice.begin() + dice_idx);
    
	return dice;
}
Esempio n. 8
0
//-----------------------------------------------------------------------------
void Utility::payRent(
        PlayerManager & i_players
        )
{
    Dice dice;
    dice.roll();
    const unsigned int amountTobePaid = dice.getTotal() *m_rentPrices[0];
    if(i_players.takeBalance(amountTobePaid))
    {
        std::cout << "You have paid " << amountTobePaid << " rent.\n";
        i_players.addBalance(amountTobePaid,m_owner);
    }
    else
    {
        std::cout << "You do not have enough money to pay!\n";
        i_players.withdrawGame();
    }
}
Esempio n. 9
0
int main()
{ //testing the functions
	int arr[3], i;
	Dice d;
	Dice acess1, acess;
	float average1, average2;
	cout << "this is only testing the functionality of the roll(),the average not calculated based on this values," << endl;
	cout << "the generated random numbers are:" << endl;
	srand(time(NULL));
	for (i = 1; i <= 3; i++) {
		cout << "random number is:" << d.roll() << endl;
	}
	average1 = acess1.average(acess1, 3);
	average2 = acess.average(arr, 3);
	cout << "avarage1:" << average1 << endl;
	cout << "average2:" << average2 << endl;
	return 0;
}
Esempio n. 10
0
void Colosseum::play(Pokemon& p1, Pokemon& p2) //function that determines who goes first, when game is over, and constraints the game to 10 rounds
{

    int hp;
    Dice d;
    int j=d.roll();
    string position;
    if(j==1)
    {
        position="first";
    }
    else
    {
        position="second";
    }
    cout << p1.get_name() << " rolls a " << j << " and goes " << position << endl;
    if(position=="first")
    {
        for(int i=1; i<11; i++)
        {

            cout << "Round " << i << "!" << endl;
            if(attack(p1,p2)==true)
            {
                cout << p2.get_name() << " has been defeated!" << endl;
                break;
            }
            if(attack(p2,p1)==true)
            {
                cout << p1.get_name() << " has been defeated!" << endl;
                break;
            }
            if(i==10)
            {
              cout << "Game Over. It's a draw!" << endl;
            }


        }

    }
    else
    {
        for(int i=1; i<11; i++)
        {

            cout << "Round " << i << "!" << endl;
            if(attack(p2,p1)==true)
            {
                cout << p1.get_name() << " has been defeated!" << endl;
                break;
            }
            if(attack(p1,p2)==true)
            {
                cout << p2.get_name() << " has been defeated!" << endl;
                break;
            }
            if(i==10)
            {
              cout << "Game Over. It's a draw!" << endl;
            }

        }

    }

}
Esempio n. 11
0
 void rollDice() {d1.roll();}            //roll the dice