std::vector<double> calcSRS(std::unordered_map<std::string, double>* srsHash, std::string teamName, boost::gregorian::date date){ Team *team = Team::findTeam(teamName); double opp_srs = 0; int num_opps = 0, pt_diff = 0; typedef std::unordered_map<std::string, TeamGame*> gamesHashType; gamesHashType gamesHash = team->getGamesByDate(); for (auto &game : gamesHash){ if (game.second->getDate() >= date) continue; //only use games before date if (srsHash->find(game.second->getOpp()) == srsHash->end()) continue; //exclude non-Division-I schools opp_srs += srsHash->at(game.second->getOpp()); pt_diff += game.second->getOpts() - game.second->getDpts(); num_opps++; } double srs = 0, sos = 0; if (num_opps > 0) { if (opp_srs != opp_srs){ //check for nan srs = pt_diff/num_opps; sos = 0; } else { srs = (pt_diff + opp_srs) / num_opps; sos = opp_srs / num_opps; } } std::vector<double> result = {srs,sos}; return result; }
void Game :: add_team (char * source_filename, int tanks_n) { Team * team; int x; int y; int tank_i; team = new Team(this, source_filename, this->teams.size()); this->teams.push_back(team); for (tank_i = 0; tank_i < tanks_n; tank_i++) { x = rand() % GAME_WIDTH; y = rand() % GAME_HEIGHT; while (this->location_free(x, y, true) == false) { x = rand() % GAME_WIDTH; y = rand() % GAME_HEIGHT; } team->add_tank(x, y); } team->place_flag_randomly(); }
void World::restoreUnits( Sqlite3 & db, GoalMap & goal_map ) { Statement teamdata( db, "SELECT x, y, faction_id, goal_id FROM TEAM" ); int count = 0; for (;;) { const int rc = teamdata.step(); if ( rc == SQLITE_DONE ) break; int x, y, faction, goal_id; teamdata.column( 0, x ); teamdata.column( 1, y ); teamdata.column( 2, faction ); teamdata.column( 3, goal_id ); auto goal_it = goal_map.find( goal_id ); Hex * hex = this->tryFind( x, y ); if ( hex == nullptr ) { cerr << "Cannot place team at: (" << x << "," << y << ")" << endl; } else { Team * team = new Team( hex, faction ); this->units.push_back( team ); if ( goal_it != goal_map.end() ) { team->setGoal( goal_it->second ); } count += 1; } } cout << "Read " << count << " team records." << endl; }
// // Process the recycler // void Base::Recycler::Process() { // Work out how much resource is pending from refunds U32 refund = 0; for (UnitObjList::Iterator u(&state.GetBase().GetManager().GetRefunds()); *u; ++u) { refund += U32(F32((**u)->GetResourceValue() * (**u)->UnitType()->GetRecyclePercentage())); } Object &object = state.GetBase().GetObject(); Team *team = object.GetTeam(); U32 resource = team->GetResourceStore(); // Do we have less cash now than the limit ? if ((resource + refund) < cash) { for (NList<Type>::Iterator t(&types); *t; ++t) { const NList<UnitObj> *units = team->GetUnitObjects((*t)->type->GetNameCrc()); if (units && units->GetCount() > (*t)->minimum) { // Order this unit to be recycled UnitObj *unit = units->GetHead(); Orders::Game::ClearSelected::Generate(object); Orders::Game::AddSelected::Generate(object, unit); Orders::Game::Recycle::Generate(object); state.GetBase().GetManager().AddRefund(unit); break; } } } }
Model::Thread* Model::AddThread(const system_profiler_thread_added* event, nanotime_t time) { // check whether we do already know the thread Thread* thread = ThreadByID(event->thread); if (thread != NULL) { fprintf(stderr, "Duplicate thread: %ld\n", event->thread); // TODO: User feedback! return thread; } // get its team Team* team = TeamByID(event->team); if (team == NULL) { fprintf(stderr, "No team for thread: %ld\n", event->thread); return NULL; } // create the thread and add it thread = new(std::nothrow) Thread(team, event, time); if (thread == NULL) return NULL; ObjectDeleter<Thread> threadDeleter(thread); if (!fThreads.BinaryInsert(thread, &Thread::CompareByID)) return NULL; if (!team->AddThread(thread)) { fThreads.RemoveItem(thread); return NULL; } threadDeleter.Detach(); return thread; }
/********************** Wicket Fallen ************************/ void myscore::wicket(void) { int o_type,new_player; cout<<"\n\n*********************************\n"; cout<<" Wicket\n"; cout<<"*********************************\n"; cout<<"\nOut type? (Bold-1:Caught-2:Run_out:3)......."; cin>>o_type; Out++; Ball_count++; team1.Set_Ball(player1); if(Out>=Max_out){cout<<"\n\n*********************************\n"; cout<<" Innings Complete\n"; cout<<"*********************************\n"; team1.Set_Status(player1,o_type+1); getch(); return; } cout<<"\nNew Batsmans no: "; cin>>new_player; team1.Set_Out(player1,o_type+1,new_player); player1=new_player; if(Ball_count==6){over_complete();return;} getch(); show(); }
void tstTeamMngr::testGetAllTeams() { printStartMsg("tstTeamMngr::testGetAllTeams"); TournamentDB* db = getScenario01(true); TeamMngr tmngr(db); // run on empty table QList<Team> result = tmngr.getAllTeams(); CPPUNIT_ASSERT(result.length() == 0); // actually create a valid team CPPUNIT_ASSERT(tmngr.createNewTeam("t1") == OK); CPPUNIT_ASSERT(tmngr.createNewTeam("t2") == OK); // run on filled table result = tmngr.getAllTeams(); CPPUNIT_ASSERT(result.length() == 2); Team t = result.at(0); CPPUNIT_ASSERT(t.getId() == 1); CPPUNIT_ASSERT(t.getName() == "t1"); t = result.at(1); CPPUNIT_ASSERT(t.getId() == 2); CPPUNIT_ASSERT(t.getName() == "t2"); delete db; printEndMsg(); }
void UserInput::outputTeamPoints(Team user, Team computer) { cout << "User's team points: " << user.getPoints() << endl;; // prints the team points for user cout << "Computer's team points: " << computer.getPoints() << endl; // prints the team points for the computer outputWinner(user.getPoints(), computer.getPoints()); }
void Logistics::initializeLogData() { LogisticsData::instance->removeMechsInForceGroup(); LogisticsData::instance->init(); Team* pTeam = Team::home; if ( pTeam ) { for ( int i = pTeam->getRosterSize() - 1; i > -1; i-- ) { Mover* pMover = (Mover*)pTeam->getMover( i ); LogisticsPilot* pPilot = LogisticsData::instance->getPilot(pMover->getPilot()->getName()); unsigned long base, highlight1, highlight2; ((Mech3DAppearance*)pMover->getAppearance())->getPaintScheme( highlight1, highlight2, base ); if ( pMover->getObjectType()->getObjectTypeClass() == BATTLEMECH_TYPE ) { LogisticsVariant* pVar = LogisticsData::instance->getVariant( ((BattleMech*)pMover)->variantName ); LogisticsData::instance->addMechToInventory( pVar, 1, pPilot, base, highlight1, highlight2 ); } } } }
int exec(const char path[]) { Image image; if (image.Open(path) != E_NO_ERROR) return E_NO_SUCH_FILE; Team *newTeam = new Team(path); if (newTeam == 0) return E_NO_MEMORY; if (image.Load(*newTeam) != E_NO_ERROR) { printf("error loading image\n"); newTeam->ReleaseRef(); return E_NOT_IMAGE; } const char *filename = path + strlen(path); while (filename > path && *filename != '/') filename--; char appName[OS_NAME_LENGTH]; snprintf(appName, OS_NAME_LENGTH, "%.12s thread", filename + 1); thread_start_t entry = reinterpret_cast<thread_start_t>(image.GetEntryAddress()); Thread *child = new Thread(appName, newTeam, entry, 0); if (child == 0) { newTeam->ReleaseRef(); return E_NO_MEMORY; } return E_NO_ERROR; // Maybe return a handle to the team, but then it would // have to be explicitly closed }
DeathMatch::DeathMatch(): Game(games::gDeathMatch) { settings::C_EnabledWeapons = settings::C_EnabledWeaponsByUser; settings::C_EnabledSpecials = settings::C_EnabledSpecialsByUser; music::play(); if (settings::C_playerIteamL | settings::C_playerIteamR) players::addPlayer (teams::addTeam(new DMTeam(settings::C_playerITeamColor)), controllers::cPlayer1); if (settings::C_playerIIteamL | settings::C_playerIIteamR) players::addPlayer (teams::addTeam(new DMTeam(settings::C_playerIITeamColor)), controllers::cPlayer2); for (int i=0; i<settings::C_botsDeath; ++i) { Team* newTeam = teams::addTeam(new DMTeam()); Color3f color(newTeam->color()); color.h(newTeam->color().h()+10*randomizer::random(-5, 5)); color.v(newTeam->color().v()+randomizer::random(-0.5f, 0.5f)); players::addPlayer(newTeam, controllers::cBot, color); } teams::assignHomes(spaceObjects::addHome(HOME_MIDDLE, 100, Color3f(0.9f, 0.7f, 1.0f))); players::createShips(); spaceObjects::populateSpace(5.f, 10.f, 4); zones::createRaster(4,3); }
void Role::synthetize() { int gem,crystal; Team* team; team=dataInterface->getMyTeam(); gem=team->getGem(); crystal=team->getCrystal(); state=5; decisionArea->enable(0); decisionArea->enable(1); tipArea->reset(); handArea->reset(); playerArea->reset(); tipArea->setMsg(tr("请选择用来合成的星石:")); if(crystal>=3) tipArea->addBoxItem(tr("1.三个水晶")); if(crystal>=2&&gem>=1) tipArea->addBoxItem(tr("2.两个水晶和一个宝石")); if(crystal>=1&&gem>=2) tipArea->addBoxItem(tr("3.一个水晶和两个宝石")); if(gem>=3) tipArea->addBoxItem(tr("4.三个宝石")); tipArea->showBox(); }
// Makes sure that the mTeams[] structure has the proper player counts // Needs to be called manually before accessing the structure // Bot counts do work on client. Yay! // Rating may only work on server... not tested on client void Game::countTeamPlayers() const { for(S32 i = 0; i < getTeamCount(); i++) { TNLAssert(dynamic_cast<Team *>(getTeam(i)), "Invalid team"); // Assert for safety static_cast<Team *>(getTeam(i))->clearStats(); // static_cast for speed } for(S32 i = 0; i < getClientCount(); i++) { ClientInfo *clientInfo = getClientInfo(i); S32 teamIndex = clientInfo->getTeamIndex(); if(teamIndex >= 0 && teamIndex < getTeamCount()) { // Robot could be neutral or hostile, skip out-of-range team numbers TNLAssert(dynamic_cast<Team *>(getTeam(teamIndex)), "Invalid team"); Team *team = static_cast<Team *>(getTeam(teamIndex)); if(clientInfo->isRobot()) team->incrementBotCount(); else team->incrementPlayerCount(); // The following bit won't work on the client... if(isServer()) { const F32 BASE_RATING = .1f; team->addRating(max(clientInfo->getCalculatedRating(), BASE_RATING)); } } } }
/** * \brief 增加成员 * \param leaderid 队长id * \param userid 队员ID * \return true 成功 false 失败 */ bool GlobalTeamIndex::addMember(const DWORD leaderid , const DWORD userid) { bool bret = false; mlock.lock(); if(leaderid == userid) { Team t; t.setLeader(leaderid); bret = team.insert(TeamMap_value_type(leaderid , t)).second; } else { TeamMap_iterator iter = team.find(leaderid); if(iter != team.end()) { bret = iter->second.addMember(userid); } else { bret = false; } } mlock.unlock(); return bret; }
Rally::Rally(): Game(games::gRally) { settings::C_EnabledWeapons = settings::C_EnabledWeaponsByUser; settings::C_EnabledSpecials = settings::C_EnabledSpecialsByUser; music::play(); if (settings::C_playerIteamL | settings::C_playerIteamR) players::addPlayer (teams::addTeam(new DMTeam(settings::C_playerITeamColor)), controllers::cPlayer1); if (settings::C_playerIIteamL | settings::C_playerIIteamR) players::addPlayer (teams::addTeam(new DMTeam(settings::C_playerIITeamColor)), controllers::cPlayer2); for (int i=0; i<settings::C_botsDeath; ++i) { Team* newTeam = teams::addTeam(new DMTeam()); Color3f color(newTeam->color()); color.h(newTeam->color().h()+10*randomizer::random(-5, 5)); color.v(newTeam->color().v()+randomizer::random(-0.5f, 0.5f)); players::addPlayer(newTeam, controllers::cBot, color); } Home* home = spaceObjects::addHome(HOME_RALLY, 100, Color3f(1.f, 1.f, 1.f)); teams::assignHomes(home); players::createShips(); //spaceObjects::populateSpace(5.f, 10.f, 4); zones::createRaster(4,3); track_ = new Track(home); }
Officer::~Officer() { if( m_id.GetTeamId() != 255 ) { Team *team = &g_app->m_location->m_teams[ m_id.GetTeamId() ]; team->UnRegisterSpecial( m_id ); } }
status_t user_timer_get_clock(clockid_t clockID, bigtime_t& _time) { switch (clockID) { case CLOCK_MONOTONIC: _time = system_time(); return B_OK; case CLOCK_REALTIME: _time = real_time_clock_usecs(); return B_OK; case CLOCK_THREAD_CPUTIME_ID: { Thread* thread = thread_get_current_thread(); InterruptsSpinLocker timeLocker(thread->time_lock); _time = thread->CPUTime(false); return B_OK; } case CLOCK_PROCESS_USER_CPUTIME_ID: { Team* team = thread_get_current_thread()->team; InterruptsSpinLocker timeLocker(team->time_lock); _time = team->UserCPUTime(); return B_OK; } case CLOCK_PROCESS_CPUTIME_ID: default: { // get the ID of the target team (or the respective placeholder) team_id teamID; if (clockID == CLOCK_PROCESS_CPUTIME_ID) { teamID = B_CURRENT_TEAM; } else { if (clockID < 0) return B_BAD_VALUE; if (clockID == team_get_kernel_team_id()) return B_NOT_ALLOWED; teamID = clockID; } // get the team Team* team = Team::Get(teamID); if (team == NULL) return B_BAD_VALUE; BReference<Team> teamReference(team, true); // get the time InterruptsSpinLocker timeLocker(team->time_lock); _time = team->CPUTime(false); return B_OK; } } }
Team* TeamLinkedList::Search(const string& teamName) const { Team* teamptr = head; while (teamptr != NULL && teamptr->Name() != teamName) { teamptr = teamptr->next; } return teamptr; }
//------------------------------------------------------------------------------ void GameLogicClientSoccer::onTeamAssignmentChanged(Player * player) { if (player == puppet_master_->getLocalPlayer()) { TEAM_ID team_id = score_.getTeamId(puppet_master_->getLocalPlayer()->getId()); // also update mine warning billboards TankMineVisual::setLocalPlayerTeam(team_id); if (team_id != INVALID_TEAM_ID) { } else { setInputMode(IM_CONTROL_CAMERA); } } Team * team = score_.getTeam(player->getId()); if (player == puppet_master_->getLocalPlayer()) { if (team == NULL) { puppet_master_->getHud()->addMessage("You have been assigned to no team."); // Hide respawn counter show_respawn_text_ = false; handleRespawnCounter(0.0f); } else { show_respawn_text_ = true; puppet_master_->getHud()->addMessage(std::string("You have been assigned to ") + team->getName() + ".", team->getColor()); sendRespawnRequest(0); } } else if (puppet_master_->getLocalPlayer()->isLevelDataSet()) { // Notification if other player changes team if (team) { puppet_master_->getHud()->addMessage(player->getName() + " has been assigned to " + team->getName() + ".", team->getColor()); } else { puppet_master_->getHud()->addMessage(player->getName() + " has been assigned to no team."); } } }
void TeamLine::setTeamTier(const Team &team, const QString &tier) { ui->teamName->setText(tr("%1 (%2)", "Team and tier in find battle").arg(team.name(), tier)); QLabel *pokes[] = {ui->poke1, ui->poke2, ui->poke3, ui->poke4, ui->poke5, ui->poke6}; for (int i = 0; i < 6; i++) { pokes[i]->setPixmap(PokemonInfo::Icon(team.poke(i).num())); } }
static Unit *GetSelectedUnit() { Team *team = NULL; if (g_app->m_location && (team = g_app->m_location->GetMyTeam())) return team->GetMyUnit(); else return NULL; }
bool MatchHelpers::attacksUp(const Team& t) { auto mh = t.getMatch()->getMatchHalf(); if(mh == MatchHalf::PenaltyShootout) { return t.isFirst() == t.getMatch()->getPenaltyShootout().firstTeamKicksNext(); } return t.isFirst() == (mh <= MatchHalf::FirstHalf || (mh <= MatchHalf::ExtraTimeFirstHalf && mh >= MatchHalf::FullTimePauseEnd)); }
std::vector<Robot*> TeamSelector::getSelectedRobots() const { Team* selectedTeam = getSelectedTeam(); if(selectedTeam) return selectedTeam->getSelectedPlayers(); else { Session::getInstance().log(CRITICAL, "TeamSelector: No team selected."); return std::vector<Robot*>(); } }
static bool ArmourSelected() { Team *team = NULL; Entity *entity = NULL; return g_app->m_location && (team = g_app->m_location->GetMyTeam()) && (entity = team->GetMyEntity()) && (entity->m_type == Entity::TypeArmour); }
void gameLoop( Game &game ) { game.dealCards(); if( game.isBotsOnly() ) game.showPlayersCards(); if( !game.takeBiddings() ) { cout << "All players passed." << endl; return; } if( game.getNumberPlayers() == 5 ) game.chooseKing(); game.takeDog(); cout << "Taker: " << game.getTakers() << endl; if( game.getNumberPlayers() <= 5 ) cout << "Defenders: " << game.getDefenders() << endl; if( game.isBotsOnly() ) game.showPlayersCards(); for( int round = 0; round < game.getCardsPerPlayer(); ++round ) { string roundString("Round "); roundString += to_string( round + 1 ); printRound( roundString ); auto trick = game.playTrick(); cout << "Trick: "; trick->showAllCards(); cout << "=> Won by " << trick->getLeader()->name << endl; } Team winners = game.endGame(); cout << "Won cards:" << endl; for( auto player : game.getPlayers() ) { cout << player->name << ": "; for( auto card : game.getPlayerWonCards( player ) ) cout << *card << " "; cout << endl; } if( !winners.isEmpty() ) { game.printScores(); cout << "Winners: " << winners << endl; } }
int Hex::GetPinnage(const Team& team) const { int nPinnage = 0; for (auto& fleet : m_fleets) { if (fleet.FindSquadron(ShipType::GCDS)) return 1000; if (!(Race(team.GetRace()).IsAncientsAlly() && fleet.GetColour() == Colour::None)) nPinnage += (fleet.GetColour() == team.GetColour() ? -1 : 1) * fleet.GetShipCount(); } return nPinnage; }
Player* Match::getTeammate(Player* p) { vector<Player *> teammates; vector<int> teammateProbs; int teamNum = p->getTeam(); Team* team ; int total = 0; if(teamNum == 1) { team = teamOne; } else if(teamNum == 2) { team = teamTwo; } for(int i = 0; i < 5; i++) { Player* currentPlayer = team->getPlayer(i); if(currentPlayer->getNumber() != p->getNumber()) { teammates.push_back(currentPlayer); if(currentPlayer->getRole() == 1) { teammateProbs.push_back(20); total+=20; } else if(currentPlayer->getRole() == 2) { teammateProbs.push_back(10); total+=10; } else if(currentPlayer->getRole() == 3) { teammateProbs.push_back(5); total+=5; } } } int teammatePick = rand()%total; int currentTotal = 0; for(int i = 0; i < 4; i++) { currentTotal+=teammateProbs[i]; if(teammatePick < currentTotal) { return teammates[i]; } } return NULL; }
// // TeamListBox::BuildTeamList // void TeamListBox::BuildTeamList() { DeleteAllItems(); for (U32 i = 0; i < Game::MAX_TEAMS; i++) { Team *team = Team::Id2Team(i); if (team) { AddTextItem(team->GetName(), NULL); } } }
bool operator<(const Team& b)const { if(point()<b.point()) return false; if(point()>b.point()) return true; if(win<b.win) return false; if(win>b.win) return true; if(goalDiff()<b.goalDiff()) return false; if(goalDiff()>b.goalDiff()) return true; if(goalScored<b.goalScored) return false; if(goalScored>b.goalScored) return true; if(total()>b.total()) return false; if(total()<b.total()) return true; return ilt(name,b.name); }
void SocReg::displayTeam(string teamName) { Team *tPtr; // Search for the team with given name tPtr=searchTeam(teamName); // If any team with given name does not exist, print failure message // otherwise print detailed team information if(tPtr==NULL) cout<<"The team does not exist"<<endl; else tPtr->displayDetailed(); }