void recommend(vector<IDinfor>& ID_len_table, priority_queue<IDinfor, vector<IDinfor>, Compare>& rID, char* ID) { int size = ID_len_table.size(); for (int i = 0; i < size; i++){ if (rID.size() < 10){ ID_len_table[i].score = calculateScore(ID, ID_len_table[i].str); rID.push(ID_len_table[i]); } else { ID_len_table[i].score = calculateScore(ID, ID_len_table[i].str); IDinfor temp = rID.top(); if (temp.score < ID_len_table[i].score) continue; else if (temp.score > ID_len_table[i].score){ rID.pop(); rID.push(ID_len_table[i]); } else { if (strcmp(temp.str, ID_len_table[i].str) > 0){ rID.pop(); rID.push(ID_len_table[i]); } } } } }
/** * Reference to the function declaration */ void BlackJackCardTable::processDealerTurn() { isSAce = false; // Get the current dealer 's score int dlrScre = calculateScore(crDCrds); //Dealer must hit on at least a soft 17 while (dlrScre < BJ_LOWER_WINNER_LIMIT) { crDCrds.push_back(dealsNewCard()); dlrScre = calculateScore(crDCrds); } //If the score of dealer is soft 17, //the dealer must then continue to hit until it has a hard 17 or higher if ((dlrScre == BJ_LOWER_WINNER_LIMIT) && (isSAce)) { crDCrds.push_back(dealsNewCard()); dlrScre = calculateScore(crDCrds); } while (dlrScre < BJ_LOWER_WINNER_LIMIT) { crDCrds.push_back(dealsNewCard()); dlrScre = calculateScore(crDCrds); } //Show all cards belonging to the dealer displayDealerCards(true); }
/** * Reference to the declaration * @return -1/0/1: /drawn/lose/win/ */ CardTableHelper::GAME_BOOL BlackJackCardTable::isPlayerWin() { //Getting the dealer 's and the player's BJ score int plyScre = calculateScore(crCards); int dlrScre = calculateScore(crDCrds); if (plyScre > BJ_UPPER_WINNER_LIMIT) { plyScre = BJ_BUST; } if ((dlrScre > BJ_UPPER_WINNER_LIMIT) && (plyScre != BJ_BUST)) { dlrScre = BJ_BUST; } if (plyScre > dlrScre) { cout << "You are the winner!!"; return CardTableHelper::WIN; } else if (plyScre < dlrScre) { cout << "You lose!!!"; return CardTableHelper::LOSE; } else { cout << "Drawn game!"; return CardTableHelper::DRAWN; } }
int main() { int maxScore = -1; std::string winnerName; std::string name; getline(std::cin, name); while (name != "stop") { std::string inputAge; getline(std::cin, inputAge); int age = std::stoi(inputAge); int currScore = calculateScore(name, age); if (currScore > maxScore) { maxScore = currScore; winnerName.assign(name); } getline(std::cin, name); } std::cout << "Highest Score: " << std::endl << winnerName << " -> " << maxScore << std::endl; return 0; }
//TODO:get reviewer pref void PaperForReview::algo(int paperID, int conferenceID) { std::vector<int> userIDs; //(7) fill userIDs with reviewers from conference userIDs = db->getReviewersForConf(conferenceID); int UserID; std::vector<int>::const_iterator it; for(it=userIDs.begin(); it!=userIDs.end(); it++) { UserID = *it; int score = 0; if (std::find(conflictingReviewersVec.begin(), conflictingReviewersVec.end(), UserID) != conflictingReviewersVec.end()) { int reviewersPreference = 0; // 1=yes //2=maybe //3=no //4=conflict //(8)GET PREF FROM DATABASE fetchreviewerPreference(userID, paperID); reviewersPreference = db->getReviewerPreference(UserID, conferenceID, paperID); if(reviewersPreference == 1) { score = calculateScore(UserID, paperID) * 1000000; checkNewReviewer(score, UserID); } else if(reviewersPreference == 2) { score = calculateScore(UserID, paperID) * 1000; checkNewReviewer(score, UserID); } else if(reviewersPreference != 3) { score = calculateScore(UserID, paperID); checkNewReviewer(score, UserID); } } } }
void ScrabbleWordFinder::updateMaxScore(string word) { unsigned long long int hashVal = 0; int wordScore; hashVal = getHash(word); bool codeExists = hashValWordMap.find(hashVal) != hashValWordMap.end(); if (codeExists) { wordScore = calculateScore(word); if (wordScore > maxScoreWord.score) { maxScoreWord.score = wordScore; maxScoreWord.words = hashValWordMap[hashVal]; } } }
/* pre : pointer to the structure post : 1. returns number of skaters n 2. allocates n elements of SKATER and assigns that pointer to the allocated array to ptr_skatersArray. */ int getData(SKATER** ptr_skatersArray, char* eventName) { FILE* fp; char line[LINE_LENGTH]; int num_of_skaters; int skater_index; int element_id; fp = fopen("data.txt", "r");// open file in read mode int i =0; while (!feof(fp))//calculates total number of skaters { fgets (line , LINE_LENGTH , fp); i++; } num_of_skaters = (i-1)/9;//total number of skaters fclose(fp);//close file *ptr_skatersArray=(SKATER*)calloc(num_of_skaters, sizeof(SKATER));// allocates momery fp = fopen("data.txt", "r");//open file again in read mode fgets(eventName , LINE_LENGTH , fp);//gets event name for(skater_index=0;skater_index<num_of_skaters;skater_index++) { SKATER* my_skater_struct_ptr; my_skater_struct_ptr = (*ptr_skatersArray)+skater_index; fgets(my_skater_struct_ptr->name, LINE_LENGTH, fp);//gets name of skaters for(element_id=0; element_id<8; element_id++) { int (*myscores)[12]; int throwaway; fgets(line, LINE_LENGTH, fp); //2 7.5 1 2 2 2 2 1 2 1 2 2 2 2 myscores = my_skater_struct_ptr->scores; sscanf(line, "%d %f %d %d %d %d %d %d %d %d %d %d %d %d", &throwaway, &((my_skater_struct_ptr->baseValue)[element_id])//reads element id , &(myscores[element_id][0]), &(myscores[element_id][1]), &(myscores[element_id][2]), &(myscores[element_id][3]) , &(myscores[element_id][4]), &(myscores[element_id][5]), &(myscores[element_id][6]), &(myscores[element_id][7]) , &(myscores[element_id][8]), &(myscores[element_id][9]), &(myscores[element_id][10]), &(myscores[element_id][11]) );//reads score for skaters //system("pause"); } calculateScore(my_skater_struct_ptr);//calculater total score for each skaters } return num_of_skaters; }
// Creates a new GameView to summarise the current state of the game GameView newGameView(char *pastPlays, PlayerMessage messages[]) { //Initialise GameView GameView gameView = malloc(sizeof(struct gameView)); assert(gameView != NULL); //Add messages to struct //gameView->messages = messages; //Establish struct fields gameView->currScore = calculateScore(pastPlays); gameView->currRound = calculateRound(pastPlays); gameView->currTurn = calculateTurn(pastPlays); gameView->currPlayer = calculatePlayer(pastPlays); gameView->currHealth[PLAYER_LORD_GODALMING] = calculateHunterHealth(pastPlays, PLAYER_LORD_GODALMING); gameView->currHealth[PLAYER_DR_SEWARD] = calculateHunterHealth(pastPlays, PLAYER_DR_SEWARD); gameView->currHealth[PLAYER_VAN_HELSING] = calculateHunterHealth(pastPlays, PLAYER_VAN_HELSING); gameView->currHealth[PLAYER_MINA_HARKER] = calculateHunterHealth(pastPlays, PLAYER_MINA_HARKER); gameView->currHealth[PLAYER_DRACULA] = calculateDraculaHealth(pastPlays); int trail[TRAIL_SIZE] = {}; int i = 0; calculateTrail(pastPlays, PLAYER_LORD_GODALMING, trail); for (i = 0; i < TRAIL_SIZE; i++) { gameView->trail[PLAYER_LORD_GODALMING][i] = trail[i]; } calculateTrail(pastPlays, PLAYER_DR_SEWARD, trail); for (i = 0; i < TRAIL_SIZE; i++) { gameView->trail[PLAYER_DR_SEWARD][i] = trail[i]; } calculateTrail(pastPlays, PLAYER_VAN_HELSING, trail); for (i = 0; i < TRAIL_SIZE; i++) { gameView->trail[PLAYER_VAN_HELSING][i] = trail[i]; } calculateTrail(pastPlays, PLAYER_MINA_HARKER, trail); for (i = 0; i < TRAIL_SIZE; i++) { gameView->trail[PLAYER_MINA_HARKER][i] = trail[i]; } calculateTrail(pastPlays, PLAYER_DRACULA, trail); for (i = 0; i < TRAIL_SIZE; i++) { gameView->trail[PLAYER_DRACULA][i] = trail[i]; } gameView->map = newMap(); return gameView; }
boolean findMoves(MatchingContext_t context, int currentTileIndex) { if(currentTileIndex >= NUM_TILES) { int moveScore = calculateScore(context); int scoreDiff = context->midPoint - moveScore; if(scoreDiff < 0) { scoreDiff *= -1; } boolean inRange = moveScore >= context->lowerBound && moveScore <= context->upperBound; if(inRange || scoreDiff < context->bestScoreDiff) { context->bestScoreDiff = scoreDiff; int i; int len = NUM_TILES * 2; for(i = 0; i < len; i++) { context->bestMove[i] = context->currentMove[i]; } context->bestScore = moveScore; } return inRange; } int row, col, dir; char *currentTile = context->tiles[currentTileIndex]; for(row = 0; row < BOARD_SIZE; row++) { for(col = 0; col < BOARD_SIZE; col++) { for(dir = 0; dir < 4; dir++) { if(checkAndPlaceTile(context, currentTile, row, col, dir)) { int index = 2 * currentTileIndex; context->currentMove[index] = row * BOARD_SIZE + col; context->currentMove[index + 1] = dir; if(findMoves(context, currentTileIndex + 1) == TRUE) { return TRUE; } removeTile(context, currentTile, row, col, dir); context->currentMove[index] = -1; context->currentMove[index + 1] = -1; } } } } return FALSE; }
void CderScorer::prepareStatsVector(size_t sid, const string& text, vector<ScoreStatsType>& stats) { sent_t cand; TokenizeAndEncode(text, cand); float max = -2; vector<ScoreStatsType> tmp; for (size_t rid = 0; rid < m_ref_sentences.size(); ++rid) { const sent_t& ref = m_ref_sentences[rid][sid]; tmp.clear(); computeCD(cand, ref, tmp); int score = calculateScore(tmp); if (rid == 0) { stats = tmp; max = score; } else if (score > max) { stats = tmp; max = score; } } }
void PlayerTracker::updateOdometry(const ros::TimerEvent&) { deleteOldUsers(); //update odometry for(unsigned int i = 0; i < potentialPlayers.size(); i++) if(potentialPlayers[i].valid) { potentialPlayers[i].playerFilter.updateOdometry(robotLinearSpeed, robotAngularSpeed); potentialPlayers[i].score = calculateScore(i); } //publish player info int bestPlayer = getBestPlayer(); if(bestPlayer>=0 && potentialPlayers[bestPlayer].score > threshold ) { if(currentPlayer == -1 || potentialPlayers[bestPlayer].score > potentialPlayers[currentPlayer].score) { currentPlayer=bestPlayer; ROS_INFO("tracking player %d",currentPlayer); } } publishPlayerInfo(currentPlayer); }
GameStatsMenu::GameStatsMenu(int level) : MenuClass() { calculateScore(level); // set up window SDL_Surface *surf; surf = pGFXManager->getUIGraphic(UI_GameStatsBackground); SetBackground(surf,false); Resize(surf->w,surf->h); SetWindowWidget(&WindowWidget); TextScore.SetTextColor(COLOR_WHITE, COLOR_BLACK); TextScore.SetText(strprintf(pTextManager->getDuneText(DuneText_Score).c_str(), totalScore)); WindowWidget.AddWidget(&TextScore, (GetSize()/2) + Point(-175, -173), TextScore.GetSize()); TextTime.SetTextColor(COLOR_WHITE, COLOR_BLACK); TextTime.SetText(strprintf(pTextManager->getDuneText(DuneText_Time).c_str(), totalTime/3600, (totalTime%3600)/60)); WindowWidget.AddWidget(&TextTime, (GetSize()/2) + Point(+180 - TextTime.GetSize().x, -173), TextTime.GetSize()); TextYourRank.SetAlignment(Alignment_HCenter); TextYourRank.SetTextColor(COLOR_WHITE, COLOR_BLACK); TextYourRank.SetText(pTextManager->getDuneText(DuneText_You_have_attained_the_rank)); WindowWidget.AddWidget(&TextYourRank, (GetSize()/2) + Point(-TextYourRank.GetSize().x/2, -127), TextYourRank.GetSize()); TextRank.SetAlignment(Alignment_HCenter); TextRank.SetText(rank); WindowWidget.AddWidget(&TextRank, (GetSize()/2) + Point(-TextRank.GetSize().x/2, -105), TextRank.GetSize()); TextSpiceHarvestedBy.SetTextColor(COLOR_WHITE, COLOR_BLACK, COLOR_THICKSPICE); TextSpiceHarvestedBy.SetAlignment(Alignment_HCenter); TextSpiceHarvestedBy.SetText(pTextManager->getDuneText(DuneText_SpiceHarvestedBy)); WindowWidget.AddWidget(&TextSpiceHarvestedBy, (GetSize()/2) + Point(-TextSpiceHarvestedBy.GetSize().x/2, -40), TextSpiceHarvestedBy.GetSize()); TextUnitsDestroyedBy.SetTextColor(COLOR_WHITE, COLOR_BLACK, COLOR_THICKSPICE); TextUnitsDestroyedBy.SetAlignment(Alignment_HCenter); TextUnitsDestroyedBy.SetText(pTextManager->getDuneText(DuneText_UnitsDestroyedBy)); WindowWidget.AddWidget(&TextUnitsDestroyedBy, (GetSize()/2) + Point(-TextUnitsDestroyedBy.GetSize().x/2, 34), TextUnitsDestroyedBy.GetSize()); TextBuildingsDestroyedBy.SetTextColor(COLOR_WHITE, COLOR_BLACK, COLOR_THICKSPICE); TextBuildingsDestroyedBy.SetAlignment(Alignment_HCenter); TextBuildingsDestroyedBy.SetText(pTextManager->getDuneText(DuneText_BuildingsDestroyedBy)); WindowWidget.AddWidget(&TextBuildingsDestroyedBy, (GetSize()/2) + Point(-TextBuildingsDestroyedBy.GetSize().x/2, 108), TextBuildingsDestroyedBy.GetSize()); // spice statistics TextYou1.SetTextColor(COLOR_WHITE, COLOR_BLACK); TextYou1.SetAlignment(Alignment_Right); TextYou1.SetText(pTextManager->getDuneText(DuneText_You)); WindowWidget.AddWidget(&TextYou1, (GetSize()/2) + Point(-229 - TextYou1.GetSize().x, -23), TextYou1.GetSize()); ProgressSpiceYouShadow.SetColor(COLOR_BLACK); ProgressSpiceYouShadow.SetProgress(0.0); WindowWidget.AddWidget(&ProgressSpiceYouShadow, (GetSize()/2) + Point(-228 + 2, -15 + 2), Point(440,12)); ProgressSpiceYou.SetColor(houseColor[pLocalHouse->getHouseID()] + 1); ProgressSpiceYou.SetProgress(0.0); WindowWidget.AddWidget(&ProgressSpiceYou, (GetSize()/2) + Point(-228, -15), Point(440,12)); TextSpiceYou.SetTextColor(COLOR_WHITE, COLOR_BLACK); TextSpiceYou.SetAlignment(Alignment_HCenter); TextSpiceYou.SetVisible(false); WindowWidget.AddWidget(&TextSpiceYou, (GetSize()/2) + Point(222, -21), Point(66,21)); TextEnemy1.SetTextColor(COLOR_WHITE, COLOR_BLACK); TextEnemy1.SetAlignment(Alignment_Right); TextEnemy1.SetText(pTextManager->getDuneText(DuneText_Enemy)); WindowWidget.AddWidget(&TextEnemy1, (GetSize()/2) + Point(-229 - TextEnemy1.GetSize().x, -5), TextEnemy1.GetSize()); ProgressSpiceEnemyShadow.SetColor(COLOR_BLACK); ProgressSpiceEnemyShadow.SetProgress(0.0); WindowWidget.AddWidget(&ProgressSpiceEnemyShadow, (GetSize()/2) + Point(-228 + 2, 3 + 2), Point(440,12)); ProgressSpiceEnemy.SetColor(COLOR_SARDAUKAR + 1); ProgressSpiceEnemy.SetProgress(0.0); WindowWidget.AddWidget(&ProgressSpiceEnemy, (GetSize()/2) + Point(-228, 3), Point(440,12)); TextSpiceEnemy.SetTextColor(COLOR_WHITE, COLOR_BLACK); TextSpiceEnemy.SetAlignment(Alignment_HCenter); TextSpiceEnemy.SetVisible(false); WindowWidget.AddWidget(&TextSpiceEnemy, (GetSize()/2) + Point(222, -3), Point(66,21)); // unit kill statistics TextYou2.SetTextColor(COLOR_WHITE, COLOR_BLACK); TextYou2.SetAlignment(Alignment_Right); TextYou2.SetText(pTextManager->getDuneText(DuneText_You)); WindowWidget.AddWidget(&TextYou2, (GetSize()/2) + Point(-229 - TextYou2.GetSize().x, 51), TextYou2.GetSize()); ProgressUnitsYouShadow.SetColor(COLOR_BLACK); ProgressUnitsYouShadow.SetProgress(0.0); WindowWidget.AddWidget(&ProgressUnitsYouShadow, (GetSize()/2) + Point(-228 + 2, 59 + 2), Point(440,12)); ProgressUnitsYou.SetColor(houseColor[pLocalHouse->getHouseID()] + 1); ProgressUnitsYou.SetProgress(0.0); WindowWidget.AddWidget(&ProgressUnitsYou, (GetSize()/2) + Point(-228, 59), Point(440,12)); TextUnitsYou.SetTextColor(COLOR_WHITE, COLOR_BLACK); TextUnitsYou.SetAlignment(Alignment_HCenter); TextUnitsYou.SetVisible(false); WindowWidget.AddWidget(&TextUnitsYou, (GetSize()/2) + Point(222, 53), Point(66,21)); TextEnemy2.SetTextColor(COLOR_WHITE, COLOR_BLACK); TextEnemy2.SetAlignment(Alignment_Right); TextEnemy2.SetText(pTextManager->getDuneText(DuneText_Enemy)); WindowWidget.AddWidget(&TextEnemy2, (GetSize()/2) + Point(-229 - TextEnemy2.GetSize().x, 69), TextEnemy2.GetSize()); ProgressUnitsEnemyShadow.SetColor(COLOR_BLACK); ProgressUnitsEnemyShadow.SetProgress(0.0); WindowWidget.AddWidget(&ProgressUnitsEnemyShadow, (GetSize()/2) + Point(-228 + 2, 77 + 2), Point(440,12)); ProgressUnitsEnemy.SetColor(COLOR_SARDAUKAR + 1); ProgressUnitsEnemy.SetProgress(0.0); WindowWidget.AddWidget(&ProgressUnitsEnemy, (GetSize()/2) + Point(-228, 77), Point(440,12)); TextUnitsEnemy.SetTextColor(COLOR_WHITE, COLOR_BLACK); TextUnitsEnemy.SetAlignment(Alignment_HCenter); TextUnitsEnemy.SetVisible(false); WindowWidget.AddWidget(&TextUnitsEnemy, (GetSize()/2) + Point(222, 71), Point(66,21)); // buildings kill statistics TextYou3.SetTextColor(COLOR_WHITE, COLOR_BLACK); TextYou3.SetAlignment(Alignment_Right); TextYou3.SetText(pTextManager->getDuneText(DuneText_You)); WindowWidget.AddWidget(&TextYou3, (GetSize()/2) + Point(-229 - TextYou3.GetSize().x, 125), TextYou3.GetSize()); ProgressBuildingsYouShadow.SetColor(COLOR_BLACK); ProgressBuildingsYouShadow.SetProgress(0.0); WindowWidget.AddWidget(&ProgressBuildingsYouShadow, (GetSize()/2) + Point(-228 + 2, 133 + 2), Point(440,12)); ProgressBuildingsYou.SetColor(houseColor[pLocalHouse->getHouseID()] + 1); ProgressBuildingsYou.SetProgress(0.0); WindowWidget.AddWidget(&ProgressBuildingsYou, (GetSize()/2) + Point(-228, 133), Point(440,12)); TextBuildingsYou.SetTextColor(COLOR_WHITE, COLOR_BLACK); TextBuildingsYou.SetAlignment(Alignment_HCenter); TextBuildingsYou.SetVisible(false); WindowWidget.AddWidget(&TextBuildingsYou, (GetSize()/2) + Point(222, 127), Point(66,21)); TextEnemy3.SetTextColor(COLOR_WHITE, COLOR_BLACK); TextEnemy3.SetAlignment(Alignment_Right); TextEnemy3.SetText(pTextManager->getDuneText(DuneText_Enemy)); WindowWidget.AddWidget(&TextEnemy3, (GetSize()/2) + Point(-229 - TextEnemy2.GetSize().x, 143), TextEnemy3.GetSize()); ProgressBuildingsEnemyShadow.SetColor(COLOR_BLACK); ProgressBuildingsEnemyShadow.SetProgress(0.0); WindowWidget.AddWidget(&ProgressBuildingsEnemyShadow, (GetSize()/2) + Point(-228 + 2, 151 + 2), Point(440,12)); ProgressBuildingsEnemy.SetColor(COLOR_SARDAUKAR + 1); ProgressBuildingsEnemy.SetProgress(0.0); WindowWidget.AddWidget(&ProgressBuildingsEnemy, (GetSize()/2) + Point(-228, 151), Point(440,12)); TextBuildingsEnemy.SetTextColor(COLOR_WHITE, COLOR_BLACK); TextBuildingsEnemy.SetAlignment(Alignment_HCenter); TextBuildingsEnemy.SetVisible(false); WindowWidget.AddWidget(&TextBuildingsEnemy, (GetSize()/2) + Point(222, 145), Point(66,21)); }
// # # ###### # # # # # # # # ##### ###### ##### // ## # # # # # # # # ## # # # # # // # # # ##### # # ####### # # # # # # ##### # # // # # # # # ## # # # # # # # # # # ##### // # ## # ## ## # # # # # ## # # # # // # # ###### # # # # #### # # # ###### # # //SPLIT STRING PLAY INTO 2D array with 7 chars. HunterView newHunterView( char *pastPlays, playerMessage messages[] ) { HunterView hunterView = malloc( sizeof( *hunterView ) ); hunterView->score = GAME_START_SCORE; int i; int counter; counter = 0; hunterView->totalTurns = (strlen(pastPlays)+1)/(PLAYLEN+1); // Initialise the 2D array of strings // http://stackoverflow.com/a/14583642 // Initialise an array of pointers for the amount of total turns hunterView->seperatedPP = malloc (hunterView->totalTurns * sizeof(char*)); assert(hunterView->seperatedPP != NULL); // Intialise a string for every turn for(i = 0; i < hunterView->totalTurns; i++) { hunterView->seperatedPP[i] = malloc(sizeof(char)); assert(hunterView->seperatedPP[i] != NULL); } for(i=0; i<hunterView->totalTurns; i++){ int j; for(j=0; j<PLAYLEN; j++){ hunterView->seperatedPP[i][j] = pastPlays[counter]; counter++; } //hunterView->seperatedPP[i][PLAYLEN] = '\0'; counter++; } for (i=0; i<hunterView->totalTurns; i++) { printf ("[%d]*%s*\n", i, hunterView->seperatedPP[i]); } // intialise all values to 0 (false) for (i = 0; i < NUM_PLAYERS; i++) { // MALLOC FOR PLAYERSTRUCT hunterView->playerStruct[i] = malloc(sizeof(struct _playerStruct)); hunterView->died[i] = FALSE; hunterView->playerStruct[i]->health = calculateHealth(hunterView, i); // initialise died to 0 hunterView->playerStruct[i]->numDied = 0; } // store latest score into struct hunterView->score = calculateScore(hunterView); makeMap(hunterView); return hunterView; }
void GameLayer::checkAndRemoveChain() { Monster *monster; // 1. reset ingnore flag for (int i = 0; i < m_height * m_width; i++) { monster = m_matrix[i]; if (!monster) { continue; } monster->setIgnoreCheck(false); } // 2. check chain for (int i = 0; i < m_height * m_width; i++) { monster = m_matrix[i]; if (!monster) { continue; } if (monster->getIsNeedRemove()) { continue;// 已标记过的跳过检查 } if (monster->getIgnoreCheck()) { continue;// 新变化的特殊monster,不消除 } // start count chain std::list<Monster *> colChainList; getColChain(monster, colChainList); std::list<Monster *> rowChainList; getRowChain(monster, rowChainList); std::list<Monster *> &longerList = colChainList.size() > rowChainList.size() ? colChainList : rowChainList; if (longerList.size() < 3) { continue;// 小于3个不消除 } countRemoveMonster = longerList.size(); std::list<Monster *>::iterator itList; bool isSetedIgnoreCheck = false; for (itList = longerList.begin(); itList != longerList.end(); itList++) { monster = (Monster *)*itList; if (!monster) { continue; } if (longerList.size() > 3) { if (monster == m_srcMonster || monster == m_destMonster) { isSetedIgnoreCheck = true; monster->setIgnoreCheck(true); //4消特殊元素先关闭 monster->setIsNeedRemove(true); //monster->setDisplayMode(m_movingVertical ? DISPLAY_MODE_VERTICAL : DISPLAY_MODE_HORIZONTAL); continue; } } markRemove(monster); } // 如何是自由掉落产生的4消, 取最后一个变化为特殊怪物 if (!isSetedIgnoreCheck && longerList.size() > 3) { monster->setIgnoreCheck(true); //4消特殊元素先关闭 monster->setIsNeedRemove(true); //monster->setDisplayMode(m_movingVertical ? DISPLAY_MODE_VERTICAL : DISPLAY_MODE_HORIZONTAL); } } // 3.消除标记了的怪物 removeMonster(); // 4.计算消除的分数 //计算消除得分 calculateScore(countRemoveMonster); }
void increaseScore() { score.bombs_caught++; calculateScore(); }
void decreaseScore() { score.bombs_missed++; calculateScore(); }
bool CColossNormal::hasBlockStarted(int _layer) { bool blocked = false; float fDistance; int red; int green; int blue; int alpha; for(unsigned int i = 0; i < getProjectileVector().size(); i++) { switch(_layer) { case TOP_COLOSS: if((m_vLayerCollision[0].Collides(getProjectileVector()[i]->getCollisionObject()) || getProjectileVector()[i]->getCollisionObject()->Collides(&m_vLayerCollision[0])) && !getProjectileVector()[i]->getDead() && !getProjectileVector()[i]->getBounced() && getProjectileVector()[i]->getBlocked() == -1) // Check if small object collides with big one and the other way round { // Play sound if(CLevelData::getCurrentLevelString() == "darkage") { glAudio->PlaySound(glDataBox->GetSoundBuffer(data->GetString("layer0")), 0); } else { glAudio->PlaySound(glDataBox->GetSoundBuffer(data->GetString("layer0_future")), 0); } // Calculate animation speed so block will be at correct position startBlockAnimation(m_vBlockCollision[0].getPosition().x, getProjectileVector()[i]->getPosition().x, getProjectileVector()[i]->GetStartVelocity().x, 0); m_bTopBlock_active = true; // Distance to center fDistance = pwHelper::math::sqrt(pow((getProjectileVector()[i]->getPosition().x - m_vLayerCollision[0].getPosition().x), 2) + pow((getProjectileVector()[i]->getPosition().y - m_vLayerCollision[0].getPosition().y), 2)); // Button color red = (int)((fDistance/50 * 255) > 255 ? 255 : (fDistance/50 * 255)); green = (int)(200 + (55 - (fDistance/150 * 55))); blue = 0; alpha = 200; m_vButton[0].setColor(sf::Color(red, green, blue, alpha)); m_vButton[0].SetCurrentAnimation(C_ANIM_BUTTON_NORMAL); m_vButton[0].RestartAnimation(); if(!getBoss()) { calculateScore(fDistance, 0); } else { if(m_vLayerCollision[0].getPosition().x > getProjectileVector()[i]->getPosition().x) { getProjectileVector()[i]->setBlockDistance(-fDistance); } else { getProjectileVector()[i]->setBlockDistance(fDistance); } } // Projectile blocked getProjectileVector()[i]->setBlocked(0); blocked = true; if(!getBoss()) { modBlocked(1); modSteps(1); } } break; case MIDDLE_HIGHER_COLOSS: if((m_vLayerCollision[1].Collides(getProjectileVector()[i]->getCollisionObject()) || getProjectileVector()[i]->getCollisionObject()->Collides(&m_vLayerCollision[1])) && !getProjectileVector()[i]->getDead() && !getProjectileVector()[i]->getBounced() && getProjectileVector()[i]->getBlocked() == -1) { if(CLevelData::getCurrentLevelString() == "darkage") { glAudio->PlaySound(glDataBox->GetSoundBuffer(data->GetString("layer1")), 1); } else { glAudio->PlaySound(glDataBox->GetSoundBuffer(data->GetString("layer1_future")), 1); } startBlockAnimation(m_vBlockCollision[1].getPosition().x, getProjectileVector()[i]->getPosition().x, getProjectileVector()[i]->GetStartVelocity().x, 1); m_bMiddleHigherBlock_active = true; fDistance = pwHelper::math::sqrt(pow((getProjectileVector()[i]->getPosition().x - m_vLayerCollision[1].getPosition().x), 2) + pow((getProjectileVector()[i]->getPosition().y - m_vLayerCollision[1].getPosition().y), 2)); red = (int)((fDistance/50 * 255) > 255 ? 255 : (fDistance/50 * 255)); green = (int)(200 + (55 - (fDistance/150 * 55))); blue = 0; alpha = 200; m_vButton[1].setColor(sf::Color(red, green, blue, alpha)); m_vButton[1].SetCurrentAnimation(C_ANIM_BUTTON_NORMAL); m_vButton[1].RestartAnimation(); if(!getBoss()) { calculateScore(fDistance, 1); } else { if(m_vLayerCollision[1].getPosition().x > getProjectileVector()[i]->getPosition().x) { getProjectileVector()[i]->setBlockDistance(-fDistance); } else { getProjectileVector()[i]->setBlockDistance(fDistance); } } getProjectileVector()[i]->setBlocked(1); blocked = true; if(!getBoss()) { modBlocked(1); modSteps(1); } } break; case MIDDLE_LOWER_COLOSS: if((m_vLayerCollision[2].Collides(getProjectileVector()[i]->getCollisionObject()) || getProjectileVector()[i]->getCollisionObject()->Collides(&m_vLayerCollision[2])) && !getProjectileVector()[i]->getDead() && !getProjectileVector()[i]->getBounced() && getProjectileVector()[i]->getBlocked() == -1) { if(CLevelData::getCurrentLevelString() == "darkage") { glAudio->PlaySound(glDataBox->GetSoundBuffer(data->GetString("layer2")), 2); } else { glAudio->PlaySound(glDataBox->GetSoundBuffer(data->GetString("layer2_future")), 2); } startBlockAnimation(m_vBlockCollision[2].getPosition().x, getProjectileVector()[i]->getPosition().x, getProjectileVector()[i]->GetStartVelocity().x, 2); m_bMiddleLowerBlock_active = true; fDistance = pwHelper::math::sqrt(pow((getProjectileVector()[i]->getPosition().x - m_vLayerCollision[2].getPosition().x), 2) + pow((getProjectileVector()[i]->getPosition().y - m_vLayerCollision[2].getPosition().y), 2)); red = (int)((fDistance/50 * 255) > 255 ? 255 : (fDistance/50 * 255)); green = (int)(200 + (55 - (fDistance/150 * 55))); blue = 0; alpha = 200; m_vButton[2].setColor(sf::Color(red, green, blue, alpha)); m_vButton[2].SetCurrentAnimation(C_ANIM_BUTTON_NORMAL); m_vButton[2].RestartAnimation(); if(!getBoss()) { calculateScore(fDistance, 2); } else { if(m_vLayerCollision[2].getPosition().x > getProjectileVector()[i]->getPosition().x) { getProjectileVector()[i]->setBlockDistance(-fDistance); } else { getProjectileVector()[i]->setBlockDistance(fDistance); } } getProjectileVector()[i]->setBlocked(2); blocked = true; if(!getBoss()) { modBlocked(1); modSteps(1); } } break; case BOTTOM_COLOSS: if((m_vLayerCollision[3].Collides(getProjectileVector()[i]->getCollisionObject()) || getProjectileVector()[i]->getCollisionObject()->Collides(&m_vLayerCollision[3])) && !getProjectileVector()[i]->getDead() && !getProjectileVector()[i]->getBounced() && getProjectileVector()[i]->getBlocked() == -1) { if(CLevelData::getCurrentLevelString() == "darkage") { glAudio->PlaySound(glDataBox->GetSoundBuffer(data->GetString("layer3")), 3); } else { glAudio->PlaySound(glDataBox->GetSoundBuffer(data->GetString("layer3_future")), 3); } startBlockAnimation(m_vBlockCollision[3].getPosition().x, getProjectileVector()[i]->getPosition().x, getProjectileVector()[i]->GetStartVelocity().x, 3); m_bBottomBlock_active = true; fDistance = pwHelper::math::sqrt(pow((getProjectileVector()[i]->getPosition().x - m_vLayerCollision[3].getPosition().x), 2) + pow((getProjectileVector()[i]->getPosition().y - m_vLayerCollision[3].getPosition().y), 2)); red = (int)((fDistance/50 * 255) > 255 ? 255 : (fDistance/50 * 255)); green = (int)(200 + (55 - (fDistance/150 * 55))); blue = 0; alpha = 200; m_vButton[3].setColor(sf::Color(red, green, blue, alpha)); m_vButton[3].SetCurrentAnimation(C_ANIM_BUTTON_NORMAL); m_vButton[3].RestartAnimation(); if(!getBoss()) { calculateScore(fDistance, 3); } else { if(m_vLayerCollision[3].getPosition().x > getProjectileVector()[i]->getPosition().x) { getProjectileVector()[i]->setBlockDistance(-fDistance); } else { getProjectileVector()[i]->setBlockDistance(fDistance); } } getProjectileVector()[i]->setBlocked(3); blocked = true; if(!getBoss()) { modBlocked(1); modSteps(1); } } break; } // Blocked 15 projectiles in a row? Earn a modifier! if(getBlocked() >= m_iMultiplierDuration) { modModifier(1); setBlocked(0); } } return blocked; }
void StatisticsBasedScorer::score(const candidates_t& candidates, const diffs_t& diffs, statscores_t& scores) const { if (!m_score_data) { throw runtime_error("Score data not loaded"); } // calculate the score for the candidates if (m_score_data->size() == 0) { throw runtime_error("Score data is empty"); } if (candidates.size() == 0) { throw runtime_error("No candidates supplied"); } int numCounts = m_score_data->get(0,candidates[0]).size(); vector<int> totals(numCounts); for (size_t i = 0; i < candidates.size(); ++i) { ScoreStats stats = m_score_data->get(i,candidates[i]); if (stats.size() != totals.size()) { stringstream msg; msg << "Statistics for (" << "," << candidates[i] << ") have incorrect " << "number of fields. Found: " << stats.size() << " Expected: " << totals.size(); throw runtime_error(msg.str()); } for (size_t k = 0; k < totals.size(); ++k) { totals[k] += stats.get(k); } } scores.push_back(calculateScore(totals)); candidates_t last_candidates(candidates); // apply each of the diffs, and get new scores for (size_t i = 0; i < diffs.size(); ++i) { for (size_t j = 0; j < diffs[i].size(); ++j) { size_t sid = diffs[i][j].first; size_t nid = diffs[i][j].second; size_t last_nid = last_candidates[sid]; for (size_t k = 0; k < totals.size(); ++k) { int diff = m_score_data->get(sid,nid).get(k) - m_score_data->get(sid,last_nid).get(k); totals[k] += diff; } last_candidates[sid] = nid; } scores.push_back(calculateScore(totals)); } // Regularisation. This can either be none, or the min or average as described in // Cer, Jurafsky and Manning at WMT08. if (m_regularization_type == NONE || m_regularization_window <= 0) { // no regularisation return; } // window size specifies the +/- in each direction statscores_t raw_scores(scores); // copy scores for (size_t i = 0; i < scores.size(); ++i) { size_t start = 0; if (i >= m_regularization_window) { start = i - m_regularization_window; } const size_t end = min(scores.size(), i + m_regularization_window + 1); if (m_regularization_type == AVERAGE) { scores[i] = score_average(raw_scores,start,end); } else { scores[i] = score_min(raw_scores,start,end); } } }
/* Suggest a move for the AI opponent given a board. Scores rows based on what has been played in them. */ vector2 prefferedMove(Board board) { // this will hold all of our moves, key // will be the rowscore, and the value // will be the row (array of vector2's) map<int, Row> moves; vector2 move; Row row; int rowScore; // calculate each row, horizontal first row = { {vector2{0, 0}, vector2{1, 0}, vector2{2, 0} } }; rowScore = calculateScore(board, row); moves[rowScore] = row; row = { { vector2{ 0, 1 }, vector2{ 1, 1 }, vector2{ 2, 1 } } }; rowScore = calculateScore(board, row); moves[rowScore] = row; row = { { vector2{ 0, 2 }, vector2{ 1, 2 }, vector2{ 2, 2 } } }; rowScore = calculateScore(board, row); moves[rowScore] = row; // vertical row = { { vector2{ 0, 0 }, vector2{ 0, 1 }, vector2{ 0, 2 } } }; rowScore = calculateScore(board, row); moves[rowScore] = row; row = { { vector2{ 1, 0 }, vector2{ 1, 1 }, vector2{ 1, 2 } } }; rowScore = calculateScore(board, row); moves[rowScore] = row; row = { { vector2{ 2, 0 }, vector2{ 2, 1 }, vector2{ 2, 2 } } }; rowScore = calculateScore(board, row); moves[rowScore] = row; // diagonals row = { { vector2{ 0, 0 }, vector2{ 1, 1 }, vector2{ 2, 2 } } }; rowScore = calculateScore(board, row); moves[rowScore] = row; row = { { vector2{ 0, 2 }, vector2{ 1, 1 }, vector2{ 2, 0 } } }; rowScore = calculateScore(board, row); moves[rowScore] = row; // get the highest score int highestRow = 0; Row bestRow; for (auto it = moves.begin(); it != moves.end(); ++it) { cout << it->first << endl; if (abs(it->first) >= highestRow) { highestRow = abs(it->first); bestRow = it->second; } } // get the first tile in this row that is empty for (int i = 0; i < 3; i++) { if (board.getTile(bestRow.tiles[i]) == EMPTY) { return bestRow.tiles[i]; } } return move; }
float TreeAIPlayer::buildTree(Gameboard board, int player, int I, int old, int opponentOld, int depth) { --depth; int n = 0; float advantage = 0; for(int x = 0; x < 8; ++x) { for(int y = 0; y < 8; ++y) { if(board.play(x,y,player,true)) { if(depth <= 0) { if(player == I) { advantage += _valueMove; } else { advantage -= _valueMove; } Gameboard newBoard = board; newBoard.play(x,y,player,false); advantage += calculateScore(newBoard, I,newBoard.points(I)-old, newBoard.points(opponent(I))-opponentOld); ++n; } else { if(player == I) { advantage += _valueMove; } else { advantage -= _valueMove; } Gameboard newBoard = board; newBoard.play(x,y,player,false); advantage += buildTree(newBoard,opponent(player),I,old,opponentOld,depth); ++n; } } } } if(n == 0) { if(board.points(I) > board.points(opponent(I))) { return _valueFullBoard; } else { return -_valueFullBoard; } } else { return advantage / n; } }
void MAPSJoin::ProcessData() { //Here I have the list of obstacles and the list of the obstacles in the gating window of each one //I have to compare all the parameters that I can to get the coincident level that the obstacles have //and select one nonone for each one //Useful parameters /* -Position -Size -Width -Speed -Direction vector -Relative speed of the vehicle -Kind of obstacle */ //I have to create 3 list //-List of asociated obstacles /* Format: 2 columns n rows; n = number of Laser obstacles */ //-List of non asociated Laser obstacles /* Format: 1 row n columns For each position we have the id of one Laser object */ //-List of non asociated Camera obstacles /* Format: 1 row n columns For each position we have the id of one Camera object */ joined.resize(Laser_Matched.number_objects); for (int i = 0; i < Laser_Matched.number_objects; i++) { //Clean list of joined joined.vector[i][0] = Laser_Matched.id[i]; joined.vector[i][1] = -1; joined.vector[i][2] = 0; for (int j = 0; j < Laser_Matched.number_matched[i]; j++) { score = 0; score = calculateScore(Laser_Matched.id[i], Laser_Matched.Matrix_matched[i][j][0]); if (score >= 0) { addAssociation(i, Laser_Matched.Matrix_matched[i][j][0], score); } } } selectAssociations(); //At the end of this for we will have a list of asociated objects cleanAssociatedList(); //Now we can find the non calculated Laser objects for (int j = 0; j < ArrayLaserObjects.number_of_objects; j++) { if (!findAssociatedLaser(ArrayLaserObjects.object[j].id)) { nonLaserJoined.push_back(ArrayLaserObjects.object[j].id); } } //Now we can find the non calculated Caemra objects for (int k = 0; k < ArrayCameraObjects.number_of_objects; k++) { if (!findAssociatedCamera(ArrayCameraObjects.object[k].id)) { nonCameraJoined.push_back(ArrayCameraObjects.object[k].id); } } }