TEST (Dice, CanInjectRangeAfterInstantiaton) { Dice dice; dice.Ranged (Range(1,2)); EXPECT_LE (1, dice.Roll()); EXPECT_GE (2, dice.Roll()); }
bool Game::RollDiceBeforeThrowingDoublet(Player* activePlayer, Dice& firstDice, Dice& secondDice, ButtonText& button, bool ShownCard) { int firstRollDice = firstDice.RollDice(); int secondRollDice = secondDice.RollDice(); if (!activePlayer->IsBlocked()) { if (activePlayer->GetPawn().move(firstRollDice + secondRollDice)) activePlayer->AddMoney(200); activePlayer->SetActiveField(true); ShownCard = false; if (firstRollDice == secondRollDice) { activePlayer->SetDoublet(true); button.GetText().setString(L"Wyrzuciłeś dublet!\nRzuć kostkami jeszcze raz!"); } else activePlayer->SetActiveMovement(false); } else { if (firstRollDice == secondRollDice) { activePlayer->SetDoublet(true); button.GetText().setString(L"Wyrzuciłeś dublet!\nRzuć kostkami jeszcze raz!"); } else { button.GetText().setString(L"Nie udało się wyrzucić dubletu!\nOddaj ruch kolejnemu graczowi!"); activePlayer->SetActiveMovement(false); } --(*activePlayer); } return ShownCard; }
ShipBattle::Hits ShipBattle::GetHitsToDestroy(const Group& group, Dice& dice, int toHit) const { const auto shipIndices = GetShipIndicesWeakestFirst(group); Hits hits; for (int shipIndex : shipIndices) { int lives = group.lifeCounts[shipIndex]; Dice used = dice.Remove(lives, toHit); if (used.empty()) break; // Can't destroy any more ships in this group. // We can destroy this ship. int damage = used.GetDamage(); if (damage > lives) // Don't want to waste damage. Can we destroy a healthier ship? { for (int shipIndex2 : shipIndices) if (group.lifeCounts[shipIndex2] == damage) { // We can destroy this one with no waste. shipIndex = shipIndex2; lives = damage; break; } } hits.push_back(Hit(group.shipType, shipIndex, used)); } return hits; }
TEST (Dice, DiceRollsWithGivenRange) { Range range (1,6); Dice dice (range); EXPECT_LE (1, dice.Roll()); EXPECT_GE (6, dice.Roll()); }
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; }
int main() { const int start=1; const int stop=12; int storeroll[13]; // this is an array declaration for an array of 12 integers //storeroll[0]=0; // this will remain unused, but we can initialize it. int loopcount =1; Dice cube; // make a six-sided die cube.Roll(); //For debugging purposes, the same number will be generated by EVERY SINGLE first roll. //So, unless you want the same number for each first roll, we must throw away the first roll. //which we do by ignoring the first roll and not storing it or printing it out. storeroll[0] = cube.Roll(); cout << storeroll[0] << endl; cout << "This loop displays "<<stop-start+1 <<" rolls of a 6-sided dice:\n" << endl; for (loopcount=start; loopcount<=stop; loopcount++) { storeroll[loopcount]=cube.Roll(); // put the roll into the array cout << "Roll " <<loopcount<< " is " << storeroll[loopcount] << "."<< endl; } cout << "\nRolled the six-sided dice " << cube.NumRolls()-1 << " times.\n" << endl; return 0; }
int main(int argc, char** argv) { Dice dice; std::string fileName = "C:\\Users\\mike8\\Desktop\\diceData.txt"; dice.runProgram(fileName); return 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]); } }
// Returns a string representation of the event string MonopolyEvent::str() { string returnStr("The following event occured:\n"); returnStr += player->str() + " with cash : " + itos(player->cash()) + " "; switch (kind) { case DICE_EVENT: { returnStr += "rolled the dice with value:\n"; // Gets the current dice Dice *d = static_cast<Dice*>(other); // Tells user about the dice actions returnStr += itos(d->get_total_value()); if (d->all_same()) returnStr += "\nDice match! Player moves."; break; } case PASS_EVENT: { returnStr += "passed the following tile:\n"; // Gets the current tile Tile *t = static_cast<Tile*>(other); // Tells user about the tile returnStr += t->str(); break; } case LAND_EVENT: { returnStr += "landed on the following tile:\n"; // Gets the current tile Tile *t = static_cast<Tile*>(other); // Tells user about the tile returnStr += t->str(); break; } case MOVE_EVENT: { returnStr += "is moving."; break; } case TRANSACTION_EVENT: { // Gets cash int *cash = static_cast<int*>(other); // Tells the player of the transaction returnStr += "made a transaction worth: " + itos(*cash); break; } default: returnStr += "an unrecognised move."; } returnStr += "\n"; return returnStr; }
int main() { Dice diceObj; int rolls; cout << "Enter Number of rolls max 12" << endl; cin >> rolls; diceObj.setRolls(rolls); cout << "Average Using Object " << diceObj.Average(diceObj, rolls) << endl; return 0; };
vector<Dice> allState() const { vector<Dice> Ret; Dice d = *this; for (int i = 0; i < 6; i++) { if (i % 2 == 0) d.rollX(); else d.rollY(); for (int j = 0; j < 4; j++) { d.rollZ(); Ret.push_back(d); } } return Ret; }
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; }
int main(int argc, char* argv[]) { // Print a message... std::cout << "hello world" << std::endl; // Set a random seed. Rand::getInstance().seed(500); for (int i=0; i<10; ++i) { Dice d; std::cout << "Rolled: " << d.get1() << ", " << d.get2() << ".\n"; } return 0; }
int main() { int loop; while(cin >> loop && loop != 0) { Dice dice; int sum = 1; string command; for(int i = 0; i < loop; ++i) { cin >> command; if(command == "South") dice.to_south(); else if(command == "North") dice.to_north(); else if(command == "East") dice.to_east(); else if(command == "West") dice.to_west(); else if(command == "Right") dice.turn_right(); else if(command == "Left") dice.turn_left(); sum += dice.get_top(); } cout << sum << 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; }
int main() { ios::sync_with_stdio(false); int n; while (cin >> n) { if (n == 0) break; int ans = 1; Dice dice; for (int i = 0; i < n; ++i) { string op; cin >> op; if (op == "North") dice.rotateY(1); else if (op == "East") dice.rotateX(1); else if (op == "South") dice.rotateY(-1); else if (op == "West") dice.rotateX(-1); else if (op == "Right") dice.rotateZ(1); else dice.rotateZ(-1); ans += dice.get(Dice::TOP); } cout << ans << endl; } return 0; }
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; }
int main(){ Dice dice; for(int i=0;i<6;i++){ cin>>dice.num[i]; } int q,ue,mae; cin>>q; for(int i=0;i<q;i++){ cin>>ue>>mae; while(!(ue==dice.num[0]&&mae==dice.num[1])){ if(rand()%2==0) dice.N(); else dice.E(); } cout<<dice.num[2]<<endl; } }
/********************************************************************* ** Function: Defend() ** Description: Implement Vampire special defend starategey. ** Parameters: Opponent attack points *********************************************************************/ void Vampire::Defend(int attackPoints) // overrides Creature's Defend functions since it is diffrent { Dice charm(2); int restult = charm.rollDie(); if (restult != 12) { Dice dice (defenseDieSides); int defensePoints = 0; for (int x = 0; x < nDefenseRolls; x++) { defensePoints += dice.rollDie(); } std::cout << "Defender's total defend points: " << defensePoints << std::endl; std::cout << "Defender's Armor: " << armor << std::endl; int damage = 0; damage = attackPoints - defensePoints - armor; if (damage < 0) damage = 0; if (damage <= 0) { strengthPoints = strengthPoints; } else { strengthPoints = strengthPoints - damage; } std::cout << "Damage inflicted: " << damage << std::endl; std::cout << "Defender's Strength Points: " << strengthPoints << std::endl; if(strengthPoints <= 0) { std::cout << "Defender is Dead!" << std::endl; alive = false; } } else { strengthPoints = strengthPoints; std::cout << "Vampire charmed the attacker!!! (no points reduced)" << std::endl; } }
bool Battle::attack(){ //create instance of dice Dice theDice = Dice(); while (attackBool) {//stay in battle pahse while attacker whishes to attack //proceed with attack phase //get corresponding die based on Troop strength getAttackingDie(); getDefendingDie(); if (!all) {//if person is not all in, procees with this command order //system("CLS"); //roll and comapre die theDice.rollDice(attackDie, defendDie); theDice.compareDice(attackDie, defendDie, attackVal, defendVal); DisplayTroopStrength(); //system("PAUSE"); if (checkWin()) change = true; else continueAttack(); } else { theDice.rollDice(attackDie, defendDie); theDice.compareDice(attackDie, defendDie, attackVal, defendVal); if (checkWin()) { DisplayTroopStrength(); change = true; } } } return takeOver; }
float average(Dice dice, int num) { float avrg; avrg = dice.getsumrollvals() / (float)num; return avrg; }
//----------------------------------------------------------------------------- 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(); } }
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; }
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; }
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; }
float Average(Dice myDice, int rolls) { int sum; int* myroll = myDice.getArray(); for (int i = 0; i < rolls; i++) { sum += *myroll; *myroll++; } return sum / rolls; };
int DispatcherSystem::Dispatch60GetAttackDice(objHndl obj, DispIoAttackDice* dispIo) { BonusList localBonlist; if (!dispIo->bonlist) dispIo->bonlist = &localBonlist; Dispatcher * dispatcher = objects.GetDispatcher(obj); if (!dispatcherValid(dispatcher)) return 0; if (dispIo->weapon) { int weaponDice = objects.getInt32(dispIo->weapon, obj_f_weapon_damage_dice); dispIo->dicePacked = weaponDice; dispIo->attackDamageType = (DamageType)objects.getInt32(dispIo->weapon, obj_f_weapon_attacktype); } DispatcherProcessor(dispatcher, dispTypeGetAttackDice, 0, dispIo); int overallBonus = bonusSys.getOverallBonus(dispIo->bonlist); Dice diceNew ; diceNew = diceNew.FromPacked(dispIo->dicePacked); int bonus = diceNew.GetModifier() + overallBonus; int diceType = diceNew.GetSides(); int diceNum = diceNew.GetCount(); Dice diceNew2(diceNum, diceType, bonus); return diceNew.ToPacked(); }
int main() { int N; char S[6]; while( scanf( "%d", &N ) && N ) { Dice dice; while( N-- ) { scanf( "%s", S ); switch( *S ) { case 'n': dice.north(); break; case 's': dice.south(); break; case 'e': dice.east(); break; case 'w': dice.west(); } } printf( "%d\n", dice.top() ); } }
int main() { Dice *D = new Dice; vector<int> dieRolls; //int players=10;int drolls[] = {5,3,5,6,5,2,2,1,6,3,6};dieRolls.insert(dieRolls.begin(),drolls,&drolls[sizeof(drolls)/sizeof(*drolls)]); //int players=3;int drolls[] = {1, 2, 3, 4, 5, 6, 1, 2, 3, 4};dieRolls.insert(dieRolls.begin(),drolls,&drolls[sizeof(drolls)/sizeof(*drolls)]); //int players=4;int drolls[] = {5, 2, 6, 6, 6, 6, 5, 5, 4, 5};dieRolls.insert(dieRolls.begin(),drolls,&drolls[sizeof(drolls)/sizeof(*drolls)]); //int players=4;int drolls[] = {2, 4, 6, 2, 4, 6, 2, 4, 6, 2, 4};dieRolls.insert(dieRolls.begin(),drolls,&drolls[sizeof(drolls)/sizeof(*drolls)]); //int players=8;int drolls[] = {5, 5, 3, 2, 2, 4, 1, 1, 1, 1, 1};dieRolls.insert(dieRolls.begin(),drolls,&drolls[sizeof(drolls)/sizeof(*drolls)]); int players=3;int drolls[] = {2, 2, 3, 4, 5, 6, 5, 4, 2, 1, 2};dieRolls.insert(dieRolls.begin(),drolls,&drolls[sizeof(drolls)/sizeof(*drolls)]); vector<int> finalScore = D->getScores(players,dieRolls); for (int i = 0; i < finalScore.size(); ++i) { cout<<finalScore[i]<<" "; } cout<<"\n"; return 0; }
bool fall(int &x, int &y, Dice &dice){ Dice maxDice = dice; int maxX = x; int maxY = y; int maxID = 0; for(int i=0; i<4; i++){ int nx = x + dx[i]; int ny = y + dy[i]; if(ht[y][x] <= ht[ny][nx])continue; if(i == 0 && !ok[dice.n]) continue; if(i == 1 && !ok[dice.e]) continue; if(i == 2 && !ok[dice.s]) continue; if(i == 3 && !ok[dice.w]) continue; Dice tmp; if(i == 0) tmp = dice.rotate_front(); if(i == 1) tmp = dice.rotate_right(); if(i == 2) tmp = dice.rotate_back(); if(i == 3) tmp = dice.rotate_left(); if(maxID < tmp.b){ maxID = tmp.b; maxX = nx; maxY = ny; maxDice = tmp; } } if(x != maxX || y != maxY){ x = maxX; y = maxY; dice = maxDice; return true; } return false; }