void UpdateHighscore(const unsigned int score, ResourceManager &resourceManager) { std::vector<Scores> scoreVec; if(GetScores(scoreVec)) { bool highscore(false); auto where(scoreVec.begin()); for(; where != scoreVec.end() && !highscore; ++where) { if(score > (*where).score) { highscore = true; } } if(highscore) { Scores scores; scores.name = GetName(resourceManager); scores.score = score; scoreVec.push_back(scores); std::sort(scoreVec.begin(), scoreVec.end(), SortByScore); scoreVec.erase(scoreVec.end() - 1); WriteHighscore(scoreVec); } scoreVec.clear(); } }
int main() { Vector<int> scores; for (int i = 0; i < 10; i++) { scores.add(0); } GetScores(scores); DrawHistogram(scores); return 0; }
//移进-规约搜索 void CDecoder::Search(string &result, float &maxscore) { m_vState.clear(); //初始化状态栈 CState ini; InitState(ini); m_vState.push_back(ini); //移进规约2N-1步 int steps = 2 * int(m_vToken.size()) - 1; for (int i = 0; i < steps; ++i) { vector<CState> buf; for (size_t j = 0; j < m_vState.size(); ++j) { map<string, double> scores; GetScores(m_vState[j], scores); vector<string> ops; GetOps(m_vState[j], ops); for (size_t k = 0; k < ops.size(); ++k) { CState next; Transition(m_vState[j], scores, ops[k], next); buf.push_back(next); } } sort(buf.begin(), buf.end()); //选出最好的N个状态 m_vState.clear(); int p = int(buf.size()) - 1; int cnt = 0; while (p >= 0 && cnt < m_nBeam) { m_vState.push_back(buf[p]); --p; ++cnt; } } maxscore = m_vState[0].score; GetResult(m_vState[0], result); }
std::string TargetPhraseImpl::Debug(const System &system) const { stringstream out; out << lhs.Debug(system); out << " -> "; for (size_t i = 0; i < GetSize(); ++i) { const SCFG::Word &word = (*this)[i]; out << word.Debug(system) << " "; } out << "pt=" << pt.GetName(); out << " SCORES:" << GetScores().Debug(system); out << " ALIGN-T:"; out << GetAlignTerm().Debug(system); out << " ALIGN-NT:"; out << GetAlignNonTerm().Debug(system); return out.str(); }
void Player::Draw() const { // wypisz informację o liczbie punktów zdobytych przez gracza Text scores_text; scores_text.SetSize(0.05, 0.05); scores_text.DrawText("Punkty " + IntToStr(GetScores()), .01, .9); scores_text.DrawText("Zycia " + IntToStr(GetLifesCount()), .65, .9); // jeżeli bohater jest nieśmiertelny, to miga (rysuj - nie rysuj) if (IsImmortal() && int(m_immortal_duration * 10) % 2 == 1) { return; } // pobierz szerokość i wysokość kafla na ekranie RendererPtr renderer = Engine::Get().GetRenderer(); const double tile_width = renderer->GetTileWidth(); const double tile_height = renderer->GetTileHeight(); // wylicz pozycję gracza na ekranie const double pos_x = m_x * tile_width; const double pos_y = m_y * tile_height; switch (m_state) { case PS::Stand: m_stop->DrawCurrentFrame(pos_x, pos_y, tile_width, tile_height); break; case PS::GoLeft: m_left->DrawCurrentFrame(pos_x, pos_y, tile_width, tile_height); break; case PS::GoRight: m_right->DrawCurrentFrame(pos_x, pos_y, tile_width, tile_height); break; case PS::TurnLeft: m_left->SetCurrentFrame(0); m_left->DrawCurrentFrame(pos_x, pos_y, tile_width, tile_height); break; case PS::TurnRight: m_right->SetCurrentFrame(0); m_right->DrawCurrentFrame(pos_x, pos_y, tile_width, tile_height); break; } }
bool AddAllTextToHighscores(std::vector<std::string> &strVec) { std::vector<Scores> scoreVec; if(GetScores(scoreVec)) { std::size_t smallestSize(20); for(auto & scores : scoreVec) { std::string name(scores.name), score(std::to_string(scores.score)); do { name += " "; }while(name.size() + score.size() < smallestSize); name += score; strVec.push_back(name); } scoreVec.clear(); return true; } return false; }