bool check_priority() { // true if battle, false if surrender if (PLAYER1_ACTION == SURRENDER_A || PLAYER2_ACTION == SURRENDER_A) { return false; } int player1_priority = get_priority(PLAYER1); int player2_priority = get_priority(PLAYER2); if (player1_priority == player2_priority) { int player1_speed = calc_speed(PLAYER1_POKEMON); int player2_speed = calc_speed(PLAYER2_POKEMON); if (player1_speed == player2_speed) { set_curr((roll(.5) ? PLAYER1 : PLAYER2)); return true; } else { set_curr((player1_speed > player2_speed ? PLAYER1 : PLAYER2)); return true; } } else { set_curr((player1_priority > player2_priority ? PLAYER1 : PLAYER2)); return true; } return true; }
static void generateBatter( const player_s *player, const int season, fileplayer_s *players_file ) { batter_s *batter = player->details.batting; filebatting_s *batting = &(players_file->filestats.filebatting); filehand_e hand = mapHandedness( player->handedness ); fileposition_e primary = mapPosition( batter->primary_position ); fileposition_e secondary = mapPosition( batter->secondary_position ); int arm = adjustRating( batter->arm, season, player ); int running = adjustRating( batter->running, season, player ); int range = adjustRating( batter->range, season, player ); int power = adjustRating( batter->power, season, player ); int bunt = adjustRating( batter->bunt, season, player ); int hit_n_run = adjustRating( batter->hit_n_run, season, player ); players_file->position[0] = (primary << 4) + secondary; batting->ratings[0] = (hand << 4) + arm; batting->ratings[1] = (running << 4) + range; batting->ratings[2] = (power << 4) + player->longevity; batting->ratings[3] = (bunt << 4) + hit_n_run; if ( player->skin_tone == st_Dark ) int2byte( batting->color, fc_Dark ); else int2byte( batting->color, fc_Light ); int games = (rand() % 25) + 120; int ab = (int)round( (double)games * ab_per_game ); int po = (int)round( (double)games * ((double)getValueForTwo( put_outs, primary, range ) / 100.0) ); int as = (int)round( (double)games * ((double)getValueForTwo( assists, primary, arm ) / 100.0) ); int ba = getValueForTwo( batting_avg, power, hit_n_run ); int soa = getValueForOne( strikeout_avg, hit_n_run ); int fa = getValueForTwo( fielding_avg, range, arm ) + 9000; int fa2 = roll( 9500, fa - 9500 ); int hits = (int)round( (double)ab * (double)ba / 1000.0 ); int so = (int)round( (double)ab * (double)soa / 1000.0 ); int err = (int)round( (double)(po + as) / (double)fa * 10000.0 ) - (po + as); if ( err < 0 ) err = 0; hits += getValueForOne( extra_hits, running ); int2word( players_file->real_avg, ba ); int2byte( batting->real_games, games ); int2byte( batting->real_sb, getValueForOne( steals, running ) ); int2word( batting->vl_ab, ab ); int2word( batting->vl_hits, hits ); int2byte( batting->vl_2b, getValueForOne( doubles, power ) ); int2byte( batting->vl_3b, getValueForTwo( triples, power, running ) ); int2byte( batting->vl_hr, getValueForOne( home_runs, power ) ); int2byte( batting->vl_bb, getValueForOne( walks, hit_n_run ) ); int2byte( batting->vl_so, so ); int2byte( batting->real_runs, batting->vl_hr[0] + getValueForOne( runs, running ) ); int2byte( batting->real_rbi, batting->vl_hr[0] + getValueForOne( rbi, power ) ); int2word( batting->real_po, po ); int2word( batting->real_as, as ); int2byte( batting->real_err, err ); int2byte( batting->real_fa2, (int)round( (10000.0 - (double)fa2) / 10.0 ) ); }
static void generateBatter( fileplayer_s *player, const names_s *name, const position2_e position ) { batter_attr_s attributes = { 0 }; rollBatterAttributes( &attributes ); strcpy( attributes.last_name, name->last_name ); strcpy( attributes.first_name, name->first_name ); int games = (rand() % 25) + 120; int ab = (int)round( (double)games * ab_per_game ); int po = (int)round( (double)games * ((double)getValueForTwo( put_outs, position, attributes.range ) / 100.0) ); int as = (int)round( (double)games * ((double)getValueForTwo( assists, position, attributes.arm ) / 100.0) ); int ba = getValueForTwo( batting_avg, attributes.power, attributes.hit_n_run ); int soa = getValueForOne( strikeout_avg, attributes.hit_n_run ); int fa = getValueForTwo( fielding_avg, attributes.range, attributes.arm ) + 9000; int fa2 = roll( 9500, fa - 9500 ); int hits = (int)round( (double)ab * (double)ba / 1000.0 ); int so = (int)round( (double)ab * (double)soa / 1000.0 ); int err = (int)round( (double)(po + as) / (double)fa * 10000.0 ) - (po + as); if ( err < 0 ) err = 0; hits += getValueForOne( extra_hits, attributes.speed ); memset( player, '\0', sizeof(fileplayer_s) ); strncpy( player->last_name, attributes.last_name, sizeof(player->last_name) ); strncpy( player->first_name, attributes.first_name, sizeof(player->first_name) ); termName( player->last_name, sizeof(player->last_name) ); termName( player->first_name, sizeof(player->first_name) ); int2word( player->real_avg, ba ); player->year[0] = 0x9D; player->position[0] = (position * 0x10) + getSecondaryPosition( position ); struct batting_s *batting = &(player->filestats.filebatting); setBatterRatings( batting->ratings, &attributes ); batting->real_games[0] = games; batting->real_sb[0] = getValueForOne( steals, attributes.speed ); batting->vl_2b[0] = getValueForOne( doubles, attributes.power ); batting->vl_3b[0] = getValueForTwo( triples, attributes.power, attributes.speed ); batting->vl_hr[0] = getValueForOne( home_runs, attributes.power ); batting->vl_bb[0] = getValueForOne( walks, attributes.hit_n_run ); batting->vl_so[0] = so; batting->real_runs[0] = batting->vl_hr[0] + getValueForOne( runs, attributes.speed ); batting->real_rbi[0] = batting->vl_hr[0] + getValueForOne( rbi, attributes.power ); batting->real_err[0] = err; batting->real_fa2[0] = (int)round( (10000.0 - (double)fa2) / 10.0 ); batting->color[0] = attributes.color; int2word( batting->vl_ab, ab ); int2word( batting->vl_hits, hits ); int2word( batting->real_po, po ); int2word( batting->real_as, as ); }
void main() { int i,j,ch; clrscr(); for(i=0;i<3;i++) { printf("\nName\tRoll no\tDepartment\tyear\tcourse\n"); scanf("%s \t%d\t %s\t %d\t %s",a[i].name,&a[i].no,&a[i].dept,&a[i].year,a[i].cour); } printf("Enter 1 for printing datas of students joined in aparticular yaer:"); printf("Enter 2 for printing datas of students you want to see:"); scanf("%d",&ch); if(ch==1) { year(a); } else if(ch==2) { roll(a); } else { printf("Invalid choice."); } getch(); }
// handles players landing on a utility void utility(struct player * players, struct location * board, const int multiplier, const int n, int * pvalue, char * plocation) { struct player * p = &players[n]; // if property is owned pay up if (board[p->location].owner > -1) { long long amt; amt = roll() * 4 * multiplier; p->money -= amt; players[board[p->location].owner].money += amt; board[p->location].profits += amt; } // otherwise buy it else if (board[p->location].owner == -2) { if (p->money > board[p->location].value) { #ifdef DEBUG fprintf(output[globalrank], "Player %d bought location %d\n", n, p->location); #endif *pvalue = board[p->location].value; *plocation = p->location; } } }
int main (void) { int first_roll; int result;// 0 mean continue,1 mean won, 2 mean lost int sum,restroll,i=1; srand(time(NULL)); sum=roll(); //while(i==1){ switch (sum) { case'7': case'11': result=1; //break; case'2': case'3': case'12': result=2; //break; default: result=0; //break; //} } if (result!=0) { if (result!=1) printf("You lost the game!\n"); else printf("You win the game!\n"); } else { first_roll=sum; printf("the first roll is %d\n ",first_roll); while(result==0) { restroll=roll(); if(restroll==7) { result=1; printf("You lost the game!\n"); } else if(restroll==first_roll) { result=2; printf("You win the game!\n"); } } } return 0; }
LogFile::LogFile(const std::string filename) : m_filename(filename), m_curFilename(""), m_fd(1), //标准输出 m_logHour(0) { roll(); }
/* * save_throw: * See if a creature save against something */ int save_throw(int which, const THING *tp) { int need; need = 14 + which - tp->t_stats.s_lvl / 2; return (roll(1, 20) >= need); }
void core_handle(string str, int n, int k) { cout << "for string " << str << endl; Stack<char> s = createStack(str); cout << s.toString() << endl; roll(s, n, k); cout << s.toString() << endl << endl; }
void View::orbit(float _x, float _y, float _radians) { glm::vec2 radial = { _x, _y }; glm::vec2 displacement = glm::rotate(radial, _radians) - radial; translate(-displacement.x, -displacement.y); roll(_radians); }
/** * Check if our children are unrolled and if so roll them back up. * * @param it :: iterator pointing to the item whose children will be rolled up. */ void HistoryView::rollChildren(std::vector<HistoryItem>::iterator it) { const size_t numChildren = it->numberOfChildren(); ++it; for (size_t i = 0; i < numChildren; ++i) { if (it->isUnrolled()) roll(it); } }
void SignalSpy::slot(QObject *caller, int index, void **) { if(entered.localData()) return; QScopedValueRollback<bool> roll(entered.localData(), true); if(spyCondition(caller)) { DBG << caller << callerNickname(caller) << " :: " << caller->metaObject()->method(index).methodSignature() << std::endl; } }
void detectLanding() { // if we are not trying to move by setting motor outputs if (isAlmostZero(goal_.roll()) && isAlmostZero(goal_.pitch()) && isAlmostZero(goal_.yaw()) && isGreaterThanMinThrottle(goal_.throttle())) { // and we are not currently moving (based on current velocities) auto angular = state_estimator_->getAngularVelocity(); auto velocity = state_estimator_->getLinearVelocity(); if (isAlmostZero(angular.roll()) && isAlmostZero(angular.pitch()) && isAlmostZero(angular.yaw()) && isAlmostZero(velocity.roll()) && isAlmostZero(velocity.pitch()) && isAlmostZero(velocity.yaw())) { // then we must be landed... landed_ = true; return; } } landed_ = false; }
void BowlingGame::roll(int p) { *cur_roll = p; cur_roll++; auto cur_index = (cur_roll - &this->pins[0]); if (p == 10 && cur_index % 2 != 0) { roll(0); } }
/// \brief Loads info from a property bag // // We get out of the bag the stat, modifier and roll settings. // /// \param propBag Bag containing properties to load // /// \sa LoadLegacy, Save /// \return true if stat was found // bool Value::Load( moPropBagRef& propBag ) { moPropStringRef stat ( f_statName ); moPropIntRef mod ( f_modName ); moPropIntRef roll ( f_rollName ); moPropStringRef notes ( f_notesName ); // stat.Link( propBag ); mod .Link( propBag ); roll.Link( propBag ); notes.Link( propBag ); if( stat.HasProp() ) { f_stat = StatManager::Instance().lock()->GetStat( static_cast<moName>(stat) ); if( !f_stat ) { return false; } } else { LoadLegacy( propBag ); } // assert(f_stat); // if( mod.HasProp() ) { f_mod = mod; } else { f_mod = 0; } // if( roll.HasProp() ) { f_roll = roll; } else { f_roll = 0; } // if( notes.HasProp() ) { f_notes = static_cast<moWCString>(notes).c_str(); } else { f_notes = ""; } return true; }
void YAC_LoggerRoll::flush() { YAC_ThreadQueue<pair<int, string> >::queue_type qt; _buffer.swap(qt); if (!qt.empty()) { roll(qt); } }
/** * Roll an unrolled algorithm history item and remove its children from the *view. * * This removes each of the child algorithm histories (if any) and marks * the parent as being "rolled up". Note that this will recursively "roll up" *any child * history objects that are also unrolled. This method does nothing if * the history object has no children. * * @param index :: index of the history object to unroll * @throws std::out_of_range if the index is larger than the number of history *items. */ void HistoryView::roll(size_t index) { if (index >= m_historyItems.size()) { throw std::out_of_range("HistoryView::roll() - Index out of range"); } // advance to the item at the index auto it = m_historyItems.begin(); std::advance(it, index); roll(it); }
/* * === FUNCTION ====================================================================== * Name: rollset * Description: return a set of random dice rolls of the passed size * ===================================================================================== */ static int * rollsetstandard(int size) { int * ret = (int*) safeMalloc(sizeof(int) * size); for(int i = 0 ; i < size ; i++) { ret[i] = roll(); } return ret; }
Image Image::fromNoise(int w, int h) //static { Image rval(w, h); std::mt19937 rng; std::uniform_int_distribution<int> roll(0,255); for (int i=0; i<w; ++i) { for (int j=0; j<h; ++j) { for (int k=0; k<4; ++k) { rval.at(j,i)[k] = roll(rng); } } } return rval; }
static void elevate_sea(void) { int x, y; for (y = 0; y < WORLD_Y; ++y) { for (x = y % 2; x < WORLD_X; x += 2) { if (elev[x][y] == -INFINITY) elev[x][y] = -roll(distance_to_land() * 20 + 27); } } }
void SimpleCamera::update() { int forwardAxis(-1); switch (m_data->m_cameraUpAxis) { case 1: forwardAxis = 2; m_data->m_cameraUp = b3MakeVector3(0,1,0); //gLightPos = b3MakeVector3(-50.f,100,30); break; case 2: forwardAxis = 1; m_data->m_cameraUp = b3MakeVector3(0,0,1); //gLightPos = b3MakeVector3(-50.f,30,100); break; default: { b3Assert(0); return; } }; b3Vector3 eyePos = b3MakeVector3(0,0,0); eyePos[forwardAxis] = -m_data->m_cameraDistance; m_data->m_cameraForward = b3MakeVector3(eyePos[0],eyePos[1],eyePos[2]); if (m_data->m_cameraForward.length2() < B3_EPSILON) { m_data->m_cameraForward.setValue(1.f,0.f,0.f); } else { m_data->m_cameraForward.normalize(); } // m_azi=m_azi+0.01; b3Scalar rele = m_data->m_yaw * b3Scalar(0.01745329251994329547);// rads per deg b3Scalar razi = m_data->m_pitch * b3Scalar(0.01745329251994329547);// rads per deg b3Quaternion rot(m_data->m_cameraUp,razi); b3Vector3 right = m_data->m_cameraUp.cross(m_data->m_cameraForward); b3Quaternion roll(right,-rele); eyePos = b3Matrix3x3(rot) * b3Matrix3x3(roll) * eyePos; m_data->m_cameraPosition = eyePos; m_data->m_cameraPosition+= m_data->m_cameraTargetPosition; }
/*! Tilts the eye() up or down by \a tiltAngle degrees, pans the eye() left or right by \a panAngle degrees, and rolls the eye() left or right by \a rollAngle degrees, all in a single fluid movement. The \a order parameter indicates the order in which to perform the rotations. This function is accessible to QML on the Camera item. It is provided as a convenience for navigation items that rotate the eye in multiple directions at the same time based on mouse movements. \sa tiltPanRollCenter() */ void QGLCamera::tiltPanRollEye (float tiltAngle, float panAngle, float rollAngle, QGLCamera::RotateOrder order) { switch (order) { case QGLCamera::TiltPanRoll: rotateEye(roll(rollAngle) * pan(panAngle) * tilt(tiltAngle)); break; case QGLCamera::TiltRollPan: rotateEye(pan(panAngle) * roll(rollAngle) * tilt(tiltAngle)); break; case QGLCamera::PanTiltRoll: rotateEye(roll(rollAngle) * tilt(tiltAngle) * pan(panAngle)); break; case QGLCamera::PanRollTilt: rotateEye(tilt(tiltAngle) * roll(rollAngle) * pan(panAngle)); break; case QGLCamera::RollTiltPan: rotateEye(pan(panAngle) * tilt(tiltAngle) * roll(rollAngle)); break; case QGLCamera::RollPanTilt: rotateEye(tilt(tiltAngle) * pan(panAngle) * roll(rollAngle)); break; } }
rollwand() { if (++between >= 4) { if (roll(1, 6) == 4) { wanderer(); kill_daemon(rollwand); fuse(swander, 0, WANDERTIME, BEFORE); } between = 0; } }
/* * === FUNCTION ====================================================================== * Name: rollweighted * Description: roll a set of random numbers + 1 weighed * ===================================================================================== */ static int * rollsetfixed(int size) { int * ret = (int*) safeMalloc(sizeof(int) * size); for(int i = 0 ; i < (size -1) ; i++) { ret[i] = roll(); } if(size > 0) ret[(size-1)] = rollweighted(); return ret; }
void main() { int n,i,ch,search; clrscr(); printf("\n Enter Number Of Student :"); scanf("%d",&n); for(i=0;i<n;i++) { printf("\n Enter Roll [%d]: ",i+1); scanf("%d",&s[i].roll); printf("\n Enter Name [%d] :",i+1); flushall(); gets(s[i].name); printf("\n Enter Yoj [%d] : ",i+1); scanf("%d",&s[i].yoj); printf("\n"); } do { clrscr(); printf("\n\n\t 1.Roll Search "); printf("\n\n\t 2.Yoj Search "); printf("\n\n\t 99. Exit"); printf("\n Enter Your Choice :"); scanf("%d",&ch); switch(ch) { case 1: printf("\n Enter Roll Number To Be Searched :"); scanf("%d",&search); roll(s,n,search); break; case 2: printf("\n Enter Yoj To Be Searched :"); scanf("%d",&search); yoj(s,n,search); break; case 99: exit(0); } getch(); }while(ch!=99); getch(); }
void RollingFileAppender::log(const LogEvent& logEvent) { MutexLockGuard lockBase(Appender::_mutex); MutexLockGuard lock(RollingFileAppender::_mutex); if (!roll()) { return; } _stream << _formatter->format(logEvent); if (_immediate) { _stream.flush(); } }
static struct digger * exit_location(struct digger *digger, struct area *chamber_or_room) { enum direction *directions; int score = roll("1d20", digger->generator->rnd); if (score <= 7) { // opposite wall directions = (enum direction[]){ digger->direction, direction_opposite(digger->direction), direction_90_degrees_right(digger->direction), direction_90_degrees_left(digger->direction), }; } else if (score <= 12) {
void DungeonLayer::_consumeMonsterRoomDatas() { for (auto data : _monsterRoomDatas) { auto dice = data->getMonsterDice(); auto room = data->getRoom(); dice->roll(); auto coordinate = Game::getInstance()->getDungeon()->getCoordinateForRoom(room); auto roomSprite = this->_getRoomSpriteForCoordinate(coordinate); roomSprite->addDice(dice); } _monsterRoomDatas.clear(); }
void ofxGamepadCamera::update(ofEventArgs& e) { if(pad == NULL) return; float curTime = ofGetElapsedTimef(); float mult = curTime - lastTime; pan(-pad->getAxisValue(PS3_STICK_R_X)*speedRotation*mult); tilt(-pad->getAxisValue(PS3_STICK_R_Y)*speedRotation*mult); truck(pad->getAxisValue(PS3_STICK_L_X)*speedMove*mult); boom(-pad->getAxisValue(PS3_STICK_L_Y)*speedMove*mult); if(useAnalogueDolly) { dolly(-(pad->getAxisValueU(PS3_THRUST_L2)-.5)*speedMove*mult); dolly((pad->getAxisValueU(PS3_THRUST_R2)-.5)*speedMove*mult); } else { if(pad->getButtonValue(PS3_BTN_L2)) { dolly(-speedMove*2*mult); } if(pad->getButtonValue(PS3_BTN_R2)) { dolly(speedMove*2*mult); } } if(pad->getButtonValue(PS3_BTN_L1)) { roll(-speedRotation*.7*mult); } if(pad->getButtonValue(PS3_BTN_R1)) { roll(speedRotation*.7*mult); } if(pad->getButtonValue(PS3_BTN_SELECT)) reset(); lastTime = curTime; }
void char_consumable_apply(struct character_t *pChar, struct object_t *pObj) { if(pObj->consumable.type == con_potion) { // apply a potion if(pObj->consumable.charge_qty == 0) { printf("%s tries to quaff a %s but it was empty.\n", pChar->name, pObj->name); } else { switch(pObj->consumable.charge_id) { case 0: // healing potion { printf("%s quaffs a %s and is \x1B[38;5;4mhealed\x1B[0m.\n", pChar->name, pObj->name); unsigned healQty = 5 * roll(); if(healQty > 15) { healQty = 15; } char_heal(pChar,healQty); --pObj->consumable.charge_qty; if(pObj->consumable.charge_qty == 0) { char_remove_inventory(pChar, pObj); } break; } case 1: // potion of dexterity { printf("%s quaffs a %s and is \x1B[38;5;4mgrows more wise\x1B[0m.\n", pChar->name, pObj->name); pChar->stats.bonus[ST_Dex] = 1; pChar->stats.value[ST_Dex] += pChar->stats.bonus[ST_Dex]; --pObj->consumable.charge_qty; if(pObj->consumable.charge_qty == 0) { char_remove_inventory(pChar, pObj); } break; } } } } }