//紀錄drift的值 bool MouseCtrl::updateTotalDrift(bool isMoved){ int udtCountTh = 20; if(!isMoved)//沒有移動 不需要更新 return false; if( DriftRecCounter > udtCountTh ){ for(int i=0; i<3 ; i++){ //更新Drift的值 DriftAccl[i] = getRound(TotalAccl[i] / (double)DriftRecCounter); DriftGyro[i] = getRound(TotalGyro[i] / (double)DriftRecCounter); //歸0 TotalAccl[i] = 0; TotalGyro[i] = 0; } //計數器歸零 DriftRecCounter = 0; return true; }else if(DriftRecCounter > 0) {//否則把觀測值歸零就好, 保留之前估測到的drift值 for(int i=0; i<3 ; i++){ TotalAccl[i] = 0; TotalGyro[i] = 0; } DriftRecCounter = 0; } return false; }
// What are my possible next moves (locations) LocationID *whereCanIgo(HunterView currentView, int *numLocations, int road, int rail, int sea) { assert(currentView != NULL); assert(numLocations != NULL); // return value LocationID *ret; // check if first round if(getRound(currentView->g) == FIRST_ROUND) { // everywhere! ret = (LocationID *)(malloc(sizeof(LocationID)*NUM_MAP_LOCATIONS)); (*numLocations) = 0; int i; for(i=0;i<NUM_MAP_LOCATIONS;i++) { ret[(*numLocations)] = i; (*numLocations)++; } } else { ret = connectedLocations(currentView->g, numLocations, getLocation(currentView->g, getCurrentPlayer(currentView->g)), getCurrentPlayer(currentView->g), getRound(currentView->g), road ,rail, sea); } return ret; }
void Game::update(Float32 elapsedTime) { if (getRound().isOver()) { if (!getRound().isLast()) { nextRound(); } } else { getRound().update(elapsedTime); } }
static void populateStruct(DracView dv, char *pastPlays, PlayerMessage messages[]) { dv->past = malloc(strlen(pastPlays)); strncpy(dv->past, pastPlays, strlen(pastPlays)); dv->pastPlaysLength = strlen(pastPlays); // Index of each player's information within pastPlays dv->pastPlaysIndex[PLAYER_LORD_GODALMING] = 0; dv->pastPlaysIndex[PLAYER_DR_SEWARD] = 8; dv->pastPlaysIndex[PLAYER_VAN_HELSING] = 16; dv->pastPlaysIndex[PLAYER_MINA_HARKER] = 24; dv->pastPlaysIndex[PLAYER_DRACULA] = 32; // Uncomment if needed in the future // dv->msgs = malloc(strlen(messages)); // strncpy(dv->msgs, messages, strlen(messages); //char *pastStr = malloc(strlen(pastPlays)); //strncpy(pastStr, pastPlays, strlen(pastPlays)); //dv->past = pastStr; //strncpy(dv->msgs, *messages, strlen(*messages)); dv->gv = newGameView(pastPlays, messages); dv->round = getRound(dv->gv); }
bool MouseCtrl::moveCursor(int *accl, int *gyro, double *velocity, int *AcclZeroC, int period, bool realMove){ //gyro的值 > 30 才會計算位移量 //若事gyroth過小(如:1), 則會產生drift問題 const int GyroMoveTh = 50; //如果一開始就對drift處理 //removeAcclDrift(accl, 0); //removeAcclDrift(accl, 1); //removeAcclDrift(accl, 2); //removeGyroDrift(gyro); //如果一開始就對drift處理 //濾掉 雜訊 gyro bool isGyroMoved = true; //如果只是假移 不需要管是否有drift的雜訊了(很可能是用在畫軌跡) if(realMove == true) {//真的移動才需要做gyro濾值得動作 isGyroMoved = gyroMoveFilter(gyro, GyroMoveTh); } if( isGyroMoved ){ //處理drift問題 //removeGyroDrift(gyro); double xdegree = (gyro[2]/1000.0 * period) / 131.0; double ydegree = (gyro[0]/1000.0 * period) / 131.0; //計算此次gyro產生的移動量 int gyroOneTimeDX = 0 - getRound(xdegree * gyroSensitivity); int gyroOneTimeDY = 0 - getRound(ydegree * gyroSensitivity); //計算加速度計部分影響的移動量 //目前只做X軸(因Z軸受到重力影響較嚴重 且 螢幕寬螢幕較常見) int displaceX, displaceZ; velocityGetDisplace(displaceX, displaceZ, accl, velocity, AcclZeroC, isGyroMoved, period, true , true); //更新滑鼠位移量(velocity + gyro) //updateDxDy(gyroOneTimeDX, gyroOneTimeDY, displaceX, displaceZ); updateDxDy(gyroOneTimeDX, gyroOneTimeDY); if(realMove){ cs.moveTo(cs.cX + dx, cs.cY + dy); } } return isGyroMoved; }
// Fills the trail array with the location ids of the last 6 turns void getHistory(GameView currentView, PlayerID player, LocationID trail[TRAIL_SIZE]) { assert(currentView != NULL); assert(0 <= player && player < NUM_PLAYERS); assert(trail != NULL); int i; // last round this player made a move in Round lastRoundPlayed; if(getCurrentPlayer(currentView) > player) { // moved this round already lastRoundPlayed = getRound(currentView); } else { // haven't yet made a move this round lastRoundPlayed = getRound(currentView) - 1; } // iterate over past moves for(i=0;i<TRAIL_SIZE;i++) { // round we're considering Round curRound = (Round)(lastRoundPlayed-i); if(curRound >= FIRST_ROUND) { // number of the turn (NOT type Round since it's a turn not a round) int turnNo = (curRound * NUM_PLAYERS) + player; // pointer to the start of the play; some pointer arithmetic char *startOfPlay = (currentView->pastPlays) + (turnNo * CHARS_PER_PLAY_BLOCK); // get id from the abbreviation (located in the first two characters of // start of play and store it in the trail trail[i] = (LocationID)(getNewLocation(startOfPlay + LOC_ABBREV_INDEX)); } else { // no previous location trail[i] = UNKNOWN_LOCATION; } // D("trail for player %d: %d rounds ago: %d [round %d]\n",player, i, trail[i], curRound); } }
int RankingMngr::getHighestRoundWithRankingEntryForPlayerPair(const Category& cat, const PlayerPair& pp) const { WhereClause wc; wc.addIntCol(RA_CAT_REF, cat.getId()); wc.addIntCol(RA_PAIR_REF, pp.getPairId()); wc.setOrderColumn_Desc(RA_ROUND); auto re = getSingleObjectByWhereClause<RankingEntry>(wc); if (re == nullptr) return -1; return re->getRound(); }
void SeasonScreen::nextRound() { unsigned int i = 0; for(i = 0; i < mSeason->getSchedule().size(); i++) { RoundTuple ct = getRound(i); assert(std::get<2>(ct)); assert(std::get<2>(ct)->getMatches().size()); if(!std::get<2>(ct)->getMatches()[std::get<2>(ct)->getMatches().size() - 1]->getResult().Played) { if(i > 15) mPlanPos = i - 10; else mPlanPos = 0; switch(std::get<0>(ct)) { case CompetitionType::League: { mScreenManager->addScreen(boost::shared_ptr<Screen>(new LeagueScreen(mScreenManager, mSeason->getLeague(), true))); } break; case CompetitionType::Cup: { mScreenManager->addScreen(boost::shared_ptr<Screen>(new CupScreen(mScreenManager, mSeason->getCup(), true))); } break; case CompetitionType::Tournament: { mScreenManager->addScreen(boost::shared_ptr<Screen>(new TournamentScreen(mScreenManager, mSeason->getTournament(), true))); } break; } break; } } if(i >= mSeason->getSchedule().size() - 1) { /* no more matches */ mNextRoundButton->hide(); if(mSeason->getLeagueSystem()) mFinishButton->show(); /* TODO: display season summary */ } }
int main(int argc, char * argv[]) { playerMessage messages[] = {}; printf("Test basic empty initialisation\n"); HunterView hv = newHunterView("", messages); assert(getCurrentPlayer(hv) == PLAYER_LORD_GODALMING); assert(getRound(hv) == 0); assert(getHealth(hv, PLAYER_DR_SEWARD) == GAME_START_HUNTER_LIFE_POINTS); assert(getHealth(hv, PLAYER_DRACULA) == GAME_START_BLOOD_POINTS); assert(getScore(hv) == GAME_START_SCORE); assert(getLocation(hv,PLAYER_LORD_GODALMING) == UNKNOWN_LOCATION); disposeHunterView(hv); printf("passed\n"); return 0; }
// For any player if the move does not exist yet (i.e, the start of the game), // the value should be UNKNOWN_LOCATION (-1) // For example after 2 turns the array may have the contents // {29, 182, -1, -1, -1, -1} // This would mean in the first move the player started on location 182 // then moved to the current location of 29 void getHistory (HunterView currentView, PlayerID player,LocationID trail[TRAIL_SIZE]) { int i; // array to store the 2 letter id pulled from pastplays char location[3]; location[2] = '\0'; // Fill array with -1 for (i=0; i<TRAIL_SIZE; i++) { trail[i] = -1; } // Round roundsPlayed = getRound(currentView); if (currentView->totalTurns%5 > player) { roundsPlayed++; } printf("totalround = %d\n", roundsPlayed); if (roundsPlayed > 0 && roundsPlayed <= 5) { for(i=0; i < roundsPlayed; i++) { printf("round = %d, playerid = %d weee = %d\n", i, player, (((roundsPlayed-1)*5)-(i*5))+player); location[0] = currentView->seperatedPP[(((roundsPlayed-1)*5)-(i*5))+player][1]; location[1] = currentView->seperatedPP[(((roundsPlayed-1)*5)-(i*5))+player][2]; trail[i] = translateLocationID(location); printf("location = **%s**\n", location); } } else if (roundsPlayed >= 6) { int start = roundsPlayed*5; for(i=TRAIL_SIZE; i > 0; i--) { printf("round = %d, playerid = %d weee = %d\n", i, player, (start-(i*5))); location[0] = currentView->seperatedPP[start-(i*5)][1]; location[1] = currentView->seperatedPP[start-(i*5)][2]; trail[i-1] = translateLocationID(location); printf("location = **%s**\n", location); } } for (i=0; i<TRAIL_SIZE; i++) { printf("history [%d] = %d\n", i, trail[i]); } }
// What are the specified player's next possible moves LocationID *whereCanTheyGo(HunterView currentView, int *numLocations, PlayerID player, int road, int rail, int sea) { int i, numValidLocations, index; LocationID forbidden; LocationID *validLocations; fprintf(stderr,"From:%d , player:%d\n",getLocation(currentView->g, player),player); LocationID *locations = connectedLocations(currentView->g, numLocations, getLocation(currentView->g, player), player, getRound(currentView->g), road, rail, sea); if(player == PLAYER_DRACULA){ forbidden = ST_JOSEPH_AND_ST_MARYS; } numValidLocations = 0; for(i = 0; i < (*numLocations); i++){ if(locations[i] != forbidden){ numValidLocations++; } } index = 0; validLocations = malloc(sizeof(LocationID) * numValidLocations); for(i = 0; i < numValidLocations; i++){ if(locations[i] != forbidden){ validLocations[index] = locations[i]; index++; } } free(locations); *numLocations = numValidLocations; return validLocations; }
static int calculateScore (HunterView currentView) { int score; score = GAME_START_SCORE - currentView->totalTurns/5; //FOR PLAYERS THAT HAVE DIED. int i; int totalDied = 0; for(i=0; i<NUM_PLAYERS; i++){ totalDied += currentView -> playerStruct[i] -> numDied; } totalDied *= SCORE_LOSS_HUNTER_HOSPITAL; score = score - totalDied; for (i=0; i<getRound(currentView); i++) { if (currentView->seperatedPP[(i*NUM_PLAYERS)+PLAYER_DRACULA][5]=='V') { score -= SCORE_LOSS_VAMPIRE_MATURES; } } return score; }
int gameControll(BITMAP * nave,BITMAP * buffer,BITMAP * alien,BITMAP * gun,BITMAP * bg,SAMPLE * sound,SAMPLE * music){ int x = 410,y=700,gameOver; while(!key[KEY_ESC]){ gameOver = printImg(nave,buffer,alien,gun,sound,music,bg,x,y); if((key[KEY_LEFT])&&(x > 0)){ x = x-3; }else if((key[KEY_RIGHT])&&(x < 950)){ x = x+3; } if(al>=75){ getRound(); textprintf_ex(screen,font,400,350,makecol(255,255,255),-1,"ROUND %d !!",r); rest(5000); velocidade = velocidade + 20; restartGame(); } if(gameOver == 1){ textprintf_ex(screen,font,400,350,makecol(255,255,255),-1,"GAME OVER!",0); rest(5000); break; } } }
// Get the current location id of a given player // May be UNKNOWN_LOCATION if the player has not had a turn yet // (ie at the beginning of the game when the round is 0) // otherwise for a hunter it should be an integer in the interval [0..70] // The given roundNumber is >= 0 and <= the current round number // 'whichHunter' specifies which hunter's location to return // and must be a value in the interval [0...3] (see 'player' type) // Or for dracula it should // gets the location of Dracula at the start of a particular round // Returns an integer: // in the interval [0...70] if Dracula was known to be in a city or sea // CITY_UNKNOWN if Dracula was in an unknown city // SEA_UNKNOWN if Dracula was in an unknown sea // HIDE if Dracula was known to have made a hide move // DOUBLE_BACK_N where N is [0...5], if Dracula was known to have // made a double back move N positions back in the trail // e.g. DOUBLE_BACK_1 is the last place place he visited // TELEPORT if Dracula apparated back to Castle Dracula // LOCATION_UNKNOWN if the round number is 0 LocationID getLocation(HunterView currentView, PlayerID player) { // check whether player has died within the turn, set location if died if (currentView->died[player] == TRUE) return ST_JOSEPH_AND_ST_MARYS; Round roundsPlayed = getRound(currentView); if (currentView->totalTurns % 5 > player) roundsPlayed++; // check that a move has been made otherwise return UNKNOWN_LOCATION if (roundsPlayed > 0) { char location[3]; location[2] = '\0'; location[0] = currentView->seperatedPP[((roundsPlayed-1)*5)+player][1]; location[1] = currentView->seperatedPP[((roundsPlayed-1)*5)+player][2]; return translateLocationID(location); } else { return UNKNOWN_LOCATION; } }
void Game::keyEvent(const KeyPressEvent &event) { if (event.getCode() == SDLK_ESCAPE && (isOver() || event.withShift())) { close(); return; } if (event.getCode() == SDLK_TAB && (!getRound().hasWinner())) { displayScoreTab = !displayScoreTab; } if (!getRound().isLast()) { if (event.getCode() == SDLK_F1 && (getRound().hasWinner() || event.withShift())) { nextRound(); return; } if (getRound().hasWinner() && ((D6_GAME_OVER_WAIT - getRound().getRemainingGameOverWait()) > 3.0f)) { nextRound(); return; } } getRound().keyEvent(event); }
// Get the current round Round giveMeTheRound(HunterView currentView) { assert(currentView != NULL); return getRound(currentView->g); }
// What are the specified player's next possible moves LocationID *whereCanTheyGo(DracView currentView, int *numLocations, PlayerID player, int road, int rail, int sea) { // This will get ALL the connected locations. LocationID *arrConnected = connectedLocations(currentView->g, numLocations, getLocation(currentView->g, player), player, getRound(currentView->g), road, rail, sea); // The only trick is that Dracula must remove his trail. if (player == PLAYER_DRACULA) { Set setConnected = copyArrayToSet(arrConnected, *numLocations); LocationID pastSix[TRAIL_SIZE] = {0}; giveMeTheTrail(currentView, player, pastSix); for (int i = 0; i < TRAIL_SIZE; i++) { if (isElem(setConnected, pastSix[i])) { setRemove(setConnected, pastSix[i]); *numLocations -= 1; } } free(arrConnected); arrConnected = copySetToArray(setConnected); } return arrConnected; }
// Get the current round Round giveMeTheRound(DracView currentView) { return getRound(currentView->g); }
int main() { int i; GameView gv; printf("Test basic empty initialisation\n"); PlayerMessage messages1[] = {}; gv = newGameView("", messages1); assert(getCurrentPlayer(gv) == PLAYER_LORD_GODALMING); assert(getRound(gv) == 0); assert(getHealth(gv,PLAYER_DR_SEWARD) == GAME_START_HUNTER_LIFE_POINTS); assert(getHealth(gv,PLAYER_DRACULA) == GAME_START_BLOOD_POINTS); assert(getScore(gv) == GAME_START_SCORE); assert(getLocation(gv,PLAYER_LORD_GODALMING) == UNKNOWN_LOCATION); printf("passed\n"); disposeGameView(gv); printf("Test for Dracula trail and basic functions\n"); PlayerMessage messages2[] = {"Hello","Rubbish","Stuff","","Mwahahah"}; gv = newGameView("GST.... SAO.... HZU.... MBB.... DC?....", messages2); assert(getCurrentPlayer(gv) == PLAYER_LORD_GODALMING); assert(getRound(gv) == 1); assert(getLocation(gv,PLAYER_LORD_GODALMING) == STRASBOURG); assert(getLocation(gv,PLAYER_DR_SEWARD) == ATLANTIC_OCEAN); assert(getLocation(gv,PLAYER_VAN_HELSING) == ZURICH); assert(getLocation(gv,PLAYER_MINA_HARKER) == BAY_OF_BISCAY); assert(getLocation(gv,PLAYER_DRACULA) == CITY_UNKNOWN); assert(getHealth(gv,PLAYER_DRACULA) == GAME_START_BLOOD_POINTS); printf("passed\n"); disposeGameView(gv); printf("Test for encountering Dracula and hunter history\n"); PlayerMessage messages3[] = {"Hello","Rubbish","Stuff","","Mwahahah","Aha!"}; gv = newGameView("GST.... SAO.... HCD.... MAO.... DGE.... GGED...", messages3); assert(getLocation(gv,PLAYER_DRACULA) == GENEVA); assert(getHealth(gv,PLAYER_LORD_GODALMING) == 5); assert(getHealth(gv,PLAYER_DRACULA) == 30); assert(getLocation(gv,PLAYER_LORD_GODALMING) == GENEVA); LocationID history[TRAIL_SIZE]; getHistory(gv,PLAYER_DRACULA,history); assert(history[0] == GENEVA); assert(history[1] == UNKNOWN_LOCATION); getHistory(gv,PLAYER_LORD_GODALMING,history); assert(history[0] == GENEVA); assert(history[1] == STRASBOURG); assert(history[2] == UNKNOWN_LOCATION); getHistory(gv,PLAYER_DR_SEWARD,history); assert(history[0] == ATLANTIC_OCEAN); assert(history[1] == UNKNOWN_LOCATION); printf("passed\n"); disposeGameView(gv); printf("Test for Dracula doubling back at sea, and losing blood points (Hunter View)\n"); PlayerMessage messages4[] = {"Hello","Rubbish","Stuff","","Mwahahah","Aha!","","","","Back I go"}; gv = newGameView("GGE.... SGE.... HGE.... MGE.... DS?.... " "GST.... SST.... HST.... MST.... DD1....", messages4); assert(getLocation(gv,PLAYER_DRACULA) == DOUBLE_BACK_1); getHistory(gv,PLAYER_DRACULA,history); assert(history[0] == DOUBLE_BACK_1); assert(history[1] == SEA_UNKNOWN); assert(getHealth(gv,PLAYER_DRACULA) == GAME_START_BLOOD_POINTS - 4); assert(getCurrentPlayer(gv) == 0); printf("passed\n"); disposeGameView(gv); printf("Test for Dracula doubling back at sea, and losing blood points (Drac View)\n"); PlayerMessage messages5[] = {"Hello","Rubbish","Stuff","","Mwahahah","Aha!","","","","Back I go"}; gv = newGameView("GGE.... SGE.... HGE.... MGE.... DEC.... " "GST.... SST.... HST.... MST.... DD1....", messages5); assert(getLocation(gv,PLAYER_DRACULA) == DOUBLE_BACK_1); getHistory(gv,PLAYER_DRACULA,history); assert(history[0] == DOUBLE_BACK_1); assert(history[1] == ENGLISH_CHANNEL); assert(getHealth(gv,PLAYER_DRACULA) == GAME_START_BLOOD_POINTS - 4); assert(getCurrentPlayer(gv) == 0); printf("passed\n"); disposeGameView(gv); printf("Test for connections\n"); int size, seen[NUM_MAP_LOCATIONS], *edges; gv = newGameView("", messages1); printf("Checking Galatz road connections\n"); edges = connectedLocations(gv,&size,GALATZ,PLAYER_LORD_GODALMING,0,1,0,0); memset(seen, 0, NUM_MAP_LOCATIONS*sizeof(int)); for (i = 0; i< size ; i++) seen[edges[i]] = 1; assert(size == 5); assert(seen[GALATZ]); assert(seen[CONSTANTA]); assert(seen[BUCHAREST]); assert(seen[KLAUSENBURG]); assert(seen[CASTLE_DRACULA]); free(edges); printf("Checking Ionian Sea sea connections\n"); edges = connectedLocations(gv,&size,IONIAN_SEA,PLAYER_LORD_GODALMING,0,0,0,1); memset(seen, 0, NUM_MAP_LOCATIONS*sizeof(int)); for (i = 0; i < size; i++) seen[edges[i]] = 1; assert(size == 7); assert(seen[IONIAN_SEA]); assert(seen[BLACK_SEA]); assert(seen[ADRIATIC_SEA]); assert(seen[TYRRHENIAN_SEA]); assert(seen[ATHENS]); assert(seen[VALONA]); assert(seen[SALONICA]); free(edges); printf("Checking Athens rail connections (none)\n"); edges = connectedLocations(gv,&size,ATHENS,PLAYER_LORD_GODALMING,0,0,1,0); assert(size == 1); assert(edges[0] == ATHENS); free(edges); printf("passed\n"); disposeGameView(gv); return 0; }
void Round::AddEnemy(Unit* t) { getRound()->UnitList.push_back(t); enemy_num++; }
// Get the current round int giveMeTheRound(HunterView currentView) { return getRound(currentView->g); }
void Server::checkGame() { qDebug() << "Server::checkGame()"; int highValueRoundOne; int highValueRoundTwo; int highValueRoundThree; int playerWinnerRoundOne; int playerWinnerRoundTwo; int playerWinnerRoundThree; bool team0Winner; bool team1Winner; highValueRoundOne = 0; highValueRoundTwo = 0; highValueRoundThree = 0; playerWinnerRoundOne = -1; playerWinnerRoundTwo = -1; playerWinnerRoundThree = -1; team0Winner = false; team1Winner = false; // round = [0,1,2] //qDebug() << "Card of player0:" << cardsOfRoundOne[0]; //qDebug() << "Card of player1:" << cardsOfRoundOne[1]; for (int i = 0; i < numberOfPlayers; i++) { if (cardsOfRoundOne[i] > highValueRoundOne) {//when round 0 qDebug() << "Cards round one: " << cardsOfRoundOne[i]; highValueRoundOne = cardsOfRoundOne[i]; playerWinnerRoundOne = i; } if (getRound() != 0) //when round 1 if (cardsOfRoundTwo[i] > highValueRoundTwo) { qDebug() << "Cards round two: " << cardsOfRoundTwo[i]; highValueRoundTwo = cardsOfRoundTwo[i]; playerWinnerRoundTwo = i; } if (getRound() == 2) { //when round 2 if (cardsOfRoundThree[i] > highValueRoundThree) { qDebug() << "Cards round three: " << cardsOfRoundThree[i]; highValueRoundThree = cardsOfRoundThree[i]; playerWinnerRoundThree = i; } } qDebug() << "High Value Card of Round[0]" <<highValueRoundOne; qDebug() << "High Value Card of Round[1]" <<highValueRoundTwo; qDebug() << "High Value Card of Round[2]" <<highValueRoundThree; } qDebug() << "Winner first round" << playerWinnerRoundOne; qDebug() << "Winner second round" << playerWinnerRoundTwo; qDebug() << "Winner third round" << playerWinnerRoundThree; if (round > 0) { qDebug() << "Round 2 tests"; if (playerWinnerRoundOne % 2 == 0) { if (playerWinnerRoundTwo % 2 == 0) { team0Winner = true; //ganhou 1 e 2 qDebug() << "Team0 Win round 1 and 2"; } else {//perdeu 2 if (round == 2) { if (playerWinnerRoundThree % 2 == 0) { team0Winner = true; // ganhou 1 e 3 qDebug() << "Team0 Win round 1 and 3"; } else { team1Winner = true; // perdeu 2 e 3 qDebug() << "Lost round 2 and 3"; } } } } else {//perdeu 1 if (playerWinnerRoundTwo %2 == 0) { if (round == 2) { if (playerWinnerRoundThree % 2 == 0) { team0Winner = true; // ganhou 2 e 3 qDebug() << "Team0 Win round 2 and 3"; } else { team1Winner = true; // perdeu 1 e 3 qDebug() << "Team0 Lost round 1 and 3"; } } } else { team1Winner = true; // perdeu 1 e 2 qDebug() << "Lost round 1 and 2"; } } } if (!team0Winner && !team1Winner) { // The player who win this round play again if (round == 0) { qDebug() << "No game's winner | round[0]"; setPlayerTurn(playerWinnerRoundOne); } if (round == 1) { qDebug() << "No game's winner | round[1]"; setPlayerTurn(playerWinnerRoundTwo); } } else { // faz algo pq alguem ganhou if (team0Winner) { qDebug() << "Team0 win this match!"; //restartGame(); } if (team1Winner) { qDebug() << "Team1 win this match!"; //restartGame(); } } nextRound(); }
void decideMove (HunterView gameState) { printf("at start of code\n"); fflush(stdout); Graph g = newGraph(); char *locations[] = { "AL", "AM", "AT", "BA", "BI", "BE", "BR", "BO", "BU", "BC", "BD", "CA", "CG", "CD", "CF", "CO", "CN", "DU", "ED", "FL", "FR", "GA", "GW", "GE", "GO", "GR", "HA", "JM", "KL", "LE", "LI", "LS", "LV", "LO", "MA", "MN", "MR", "MI", "MU", "NA", "NP", "NU", "PA", "PL", "PR", "RO", "SA", "SN", "SR", "SJ", "SO", "ST", "SW", "SZ", "TO", "VA", "VR", "VE", "VI", "ZA", "ZU", "NS", "EC", "IS", "AO", "BB", "MS", "TS", "IO", "AS", "BS", "C?", "S?", "HI", "D1", "D2", "D3", "D4", "D5", "TP" }; int round = getRound(gameState); PlayerID id = getCurrentPlayer(gameState); LocationID move = getLocation(gameState, id); printf("the original loc is %d and health %d\n",move,getHealth(gameState,id)); char * msg = ""; printf("initialised all variables\n"); fflush(stdout); //set initial locations if (round - id == 0) { if (id == PLAYER_LORD_GODALMING) {move = CASTLE_DRACULA; msg = "camping";} else if (id == PLAYER_DR_SEWARD) move = BELGRADE; else if (id == PLAYER_VAN_HELSING) move = STRASBOURG; else if (id == PLAYER_MINA_HARKER) move = MADRID; registerBestPlay(locations[move], msg); destroyGraph(g); return; } printf("done initial moves\n"); fflush(stdout); //below code will throw errors if LG is killed //if (id == PLAYER_LORD_GODALMING) { registerBestPlay("CD","I'm camping MAN!!!"); return; } srand (time(NULL)); int path[NUM_MAP_LOCATIONS]; int amtLocs = 0; LocationID * adj = connectedLocations(&amtLocs, getLocation(gameState, id), id, round, ANY, g); LocationID target = UNKNOWN_LOCATION; int camper = 0, i, j; printf("setting up connected locs etc\n"); fflush(stdout); // check for campers // if the current player is camping, then the player // will stay camping and ai will return for (i = 0; i < NUM_HUNTERS; i++) { if (getLocation(gameState, i) == CASTLE_DRACULA) { camper = 1; if (id == i) { registerBestPlay("CD", "Staying camping"); destroyGraph(g); free(adj); return; } } } if (!camper) { //if no camper and hunter is shortest dist to castle dracula, move towards castle dracula int hunterDist[NUM_HUNTERS] = {UNKNOWN_LOCATION,UNKNOWN_LOCATION,UNKNOWN_LOCATION,UNKNOWN_LOCATION}; int closestHunter = PLAYER_LORD_GODALMING; for (i = PLAYER_LORD_GODALMING; i < NUM_HUNTERS; i++) { hunterDist[i] = findShortestPath(getLocation(gameState, i), CASTLE_DRACULA, path, ANY, round); if (hunterDist[i] == -1) hunterDist[i] = 1000; //-1 is when there is no path, so don't want him to be shortest if ((hunterDist[closestHunter] > hunterDist[i]) || (hunterDist[closestHunter] == UNKNOWN_LOCATION)) closestHunter = i; } if (closestHunter == id) move = path[1]; } else { LocationID draculaLoc[TRAIL_SIZE]; getHistory (gameState, PLAYER_DRACULA, draculaLoc); //updates Dracula trail for (i = TRAIL_SIZE - 1; i >= 0 ; i--) //locations newer in trail will override older ones target = dracTarget(draculaLoc, i); //we have any useful info on his location... if (target != UNKNOWN_LOCATION) { //Note: Dracula cannot visit any location currently in his trail - hunters should not visit target itself! int pathLen = findShortestPath(getLocation(gameState, id), target, path, ANY, round); //success is any number not -1 if (getLocation(gameState, id) != target && pathLen != -1) { //path found, and not at rest on target (Drac's trail) if (path[1] != target) move = path[1]; //don't move into Dracula's trail (see note above) else move = adj[rand() % amtLocs]; for (i = 0; i < TRAIL_SIZE ; i++) if (path[1] == dracTarget(draculaLoc, i)) move = adj[rand() % amtLocs]; } else move = adj[rand() % amtLocs]; } else { //prevents doubling up of hunters when making a random move, since Dracula 404 int occupied = 0, newLoc = UNKNOWN_LOCATION; move = adj[rand() % amtLocs]; for (j = 0; j < NUM_HUNTERS; j++) if (move == getLocation(gameState, j)) occupied = 1; if (occupied) { for (i = 0; i < amtLocs; i++) { occupied = 0; for (j = 0; j < NUM_HUNTERS; j++) if (adj[i] == getLocation(gameState, j)) occupied = 1; if (!occupied) {newLoc = i; break;} } } if (newLoc != UNKNOWN_LOCATION) move = adj[newLoc]; } } if (target != UNKNOWN_LOCATION) printf("*Moving from %s (%d) to target %s (%d) via %s (%d)*\n", locations[getLocation(gameState, id)], getLocation(gameState, id), locations[target], target, locations[move], move); else printf("*No target - moving from %s (%d) to %s (%d)*\n", locations[getLocation(gameState, id)], getLocation(gameState, id), locations[move], move); if (isLegalMove(gameState, id, move, round, g)) registerBestPlay(locations[move], ""); else { printf("ERROR: Location is invalid! Registering default rest move..."); registerBestPlay(locations[getLocation(gameState, id)], ""); } destroyGraph(g); free(adj); }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { double *input, *bm, *env, *filter; double lowerERB, upperERB; double dt, twoPiT, gain, z; double f1Down, f2Down, f1Up, f2Up, data; double x[4], y[4]; int nSamples, nChannels, lowerFreq, upperFreq, nFilter; int ii, nn, chan, fs, bExit = false, bUseMidEar = false; int chanIdx, nFilter2Process, *processFilter, infoFlag; int bTimeAlign = false, tc; // Define field names for gammatone structure //const char *field_names[] = {"fs","nFilter","lowerFreq","upperFreq","cf","bw","gain","delay"}; // Check for proper number of arguments if ((nrhs < 2) || (nlhs > 2)){ usage(); // Set exit flag to true because of incorrect function call bExit = true; } // Check if input arguments are valid else{ // Get dimension of input signal nSamples = (int)mxGetM(INPUT); nChannels = (int)mxGetN(INPUT); // Sampling frequency fs = (int) mxGetScalar(FS); // Input signal must be mono if(nChannels != 1){ mexPrintf("\n--------------------------------------------------------------------------------" ); mexPrintf("\n ERROR: gammatone.dll is just supporting mono signals." ); mexPrintf("\n--------------------------------------------------------------------------------\n"); // Set exit flag to true bExit = true; } // Set defaults ... if (nrhs < 3) lowerFreq = 80; else lowerFreq = (int)mxGetScalar(LOWERFREQ); if (nrhs < 4) upperFreq = 5000; else upperFreq = (int)mxGetScalar(UPPERFREQ); if (nrhs < 5){ // Round the number of auditory filter to the next integer value nFilter = getRound(HzToERBRate(fs/2)); // Total number of filters to process within this function call nFilter2Process = nFilter; // Create index vector for auditory filter processing processFilter = (int *) mxCalloc(nFilter2Process, sizeof(int)); // Create vector which indicates the indicees of the processed auditory filters for (chan=0; chan<nFilter; chan++){ processFilter[chan] = chan; } } else{ // Figure out how may auditory filters should be processed ... filter = mxGetPr(NFILTER); // Assume the first value to be the total number of auditory filters nFilter = (int) filter[0]; // Determine number of auditory filters which should be processed nFilter2Process = max((int)mxGetM(NFILTER),(int)mxGetN(NFILTER))-1; // In case just the total number of auditory filters was specified, process all filters if (nFilter2Process == 0){ nFilter2Process = nFilter; // Create index vector for auditory filter processing processFilter = (int *) mxCalloc(nFilter2Process, sizeof(int)); // Create vector which indicates the indicees of the processed auditory filters for (chan=0; chan<nFilter2Process; chan++){ processFilter[chan] = chan; } } else{ // Create index vector for auditory filter processing processFilter = (int *) mxCalloc(nFilter2Process, sizeof(int)); // Create vector which indicates the indicees of the processed auditory filters for (chan=0; chan<nFilter2Process; chan++){ processFilter[chan] = (int) filter[chan + 1] - 1; } } } if (nrhs < 6) bUseMidEar = false; else{ bUseMidEar = (int)mxGetScalar(USEMIDDLEEAR); } if (nrhs < 7) bTimeAlign = false; else{ bTimeAlign = (int)mxGetScalar(TIMEALIGN); } // Check if lower and upper frequency limit fall within the valid range // of the outer/middle ear filter ... if (bUseMidEar && (lowerFreq <= 20 || upperFreq >= 12500 )){ // Display error message mexPrintf("\n--------------------------------------------------------------------------------" ); mexPrintf("\n ERROR using gammatone.dll: " ); mexPrintf("\n The lower and upper frequency limit must be within 20 and 12500 Hz if the " ); mexPrintf("\n outer/middle ear gain is used. " ); mexPrintf("\n--------------------------------------------------------------------------------\n"); // Set exit flag to true because of incorrect function call bExit = true; } else if(bUseMidEar){ /* parameters of equal-loudness functions from BS3383, "Normal equal-loudness level contours for pure tones under free-field listening conditions", table 1. f is the tone frequency af and bf are frequency-dependent coefficients tf is the threshold sound pressure level of the tone, in dBs */ f[0]=20.0; af[0]=2.347; bf[0]=0.00561; tf[0]=74.3; f[1]=25.0; af[1]=2.190; bf[1]=0.00527; tf[1]=65.0; f[2]=31.5; af[2]=2.050; bf[2]=0.00481; tf[2]=56.3; f[3]=40.0; af[3]=1.879; bf[3]=0.00404; tf[3]=48.4; f[4]=50.0; af[4]=1.724; bf[4]=0.00383; tf[4]=41.7; f[5]=63.0; af[5]=1.579; bf[5]=0.00286; tf[5]=35.5; f[6]=80.0; af[6]=1.512; bf[6]=0.00259; tf[6]=29.8; f[7]=100.0; af[7]=1.466; bf[7]=0.00257; tf[7]=25.1; f[8]=125.0; af[8]=1.426; bf[8]=0.00256; tf[8]=20.7; f[9]=160.0; af[9]=1.394; bf[9]=0.00255; tf[9]=16.8; f[10]=200.0; af[10]=1.372; bf[10]=0.00254; tf[10]=13.8; f[11]=250.0; af[11]=1.344; bf[11]=0.00248; tf[11]=11.2; f[12]=315.0; af[12]=1.304; bf[12]=0.00229; tf[12]=8.9; f[13]=400.0; af[13]=1.256; bf[13]=0.00201; tf[13]=7.2; f[14]=500.0; af[14]=1.203; bf[14]=0.00162; tf[14]=6.0; f[15]=630.0; af[15]=1.135; bf[15]=0.00111; tf[15]=5.0; f[16]=800.0; af[16]=1.062; bf[16]=0.00052; tf[16]=4.4; f[17]=1000.0; af[17]=1.000; bf[17]=0.00000; tf[17]=4.2; f[18]=1250.0; af[18]=0.967; bf[18]=-0.00039; tf[18]=3.7; f[19]=1600.0; af[19]=0.943; bf[19]=-0.00067; tf[19]=2.6; f[20]=2000.0; af[20]=0.932; bf[20]=-0.00092; tf[20]=1.0; f[21]=2500.0; af[21]=0.933; bf[21]=-0.00105; tf[21]=-1.2; f[22]=3150.0; af[22]=0.937; bf[22]=-0.00104; tf[22]=-3.6; f[23]=4000.0; af[23]=0.952; bf[23]=-0.00088; tf[23]=-3.9; f[24]=5000.0; af[24]=0.974; bf[24]=-0.00055; tf[24]=-1.1; f[25]=6300.0; af[25]=1.027; bf[25]=0.00000; tf[25]=6.6; f[26]=8000.0; af[26]=1.135; bf[26]=0.00089; tf[26]=15.3; f[27]=10000.0; af[27]=1.266; bf[27]=0.00211; tf[27]=16.4; f[28]=12500.0; af[28]=1.501; bf[28]=0.00488; tf[28]=11.6; } if (nrhs < 8) infoFlag = false; else infoFlag = (int)mxGetScalar(INFOFLAG); } if(!bExit){ // Asign pointers input = mxGetPr(INPUT); // Create a matrix for the return argument BM = mxCreateDoubleMatrix(nSamples, nFilter2Process, mxREAL); // Asign pointer bm = mxGetPr(BM); // Envelope output if (nlhs>1){ // Create a matrix for second return argument ENV = mxCreateDoubleMatrix(nSamples, nFilter2Process, mxREAL); // Asign pointer env = mxGetPr(ENV); } // Initialize gammatone filter structure gammaTone* fChan; // Da der Kompiler meckert wenn nFilter keine Konstante ist, muss die // Gammatone-Struktur zur Laufzeit mit new initialisiert werden ... fChan = new gammaTone[nFilter]; // Map frequency to erb domain lowerERB = HzToERBRate(lowerFreq); upperERB = HzToERBRate(upperFreq); // Calculate center frequencies fChan[0].cf = ERBRateToHz(lowerERB); for (chan = 1; chan<nFilter-1; chan++) { // Linear space the gammatone center frequency in the ERB domain fChan[chan].cf = ERBRateToHz(lowerERB + chan * (upperERB-lowerERB)/((double)nFilter-1.0)); } fChan[nFilter-1].cf = ERBRateToHz(upperERB); // Report parameter if (infoFlag){ mexPrintf("\n \t |-------------------------------------| "); mexPrintf("\n \t | GAMMATONE PARAMETER | "); mexPrintf("\n \t |-------------------------------------| "); mexPrintf("\n \t | filter | cf [Hz] | bw | delay | "); mexPrintf("\n \t |-------------------------------------| "); } // Loop over number of auditory filters for (chan=0; chan<nFilter; chan++) { // Bandwidth fChan[chan].bw = erb(fChan[chan].cf) * bandwidthCorrection; // Compute gammatone envelope delay in samples (for 4th order) fChan[chan].delay = (3.0 * fs) / (fChan[chan].bw * 2.0 * PI); // Compute phase correction to align peak in temporal fine structure fChan[chan].phaseCorrection = -fChan[chan].cf * 3.0/fChan[chan].bw; // Report parameters ... if (infoFlag){ mexPrintf("\n \t |%5.0f |%9.2f |%7.2f |%7.2f |",(double)chan+1.0,fChan[chan].cf,fChan[chan].bw,fChan[chan].delay); } } if (infoFlag){ mexPrintf("\n \t |-------------------------------------|\n"); } // Time resolution dt = 1/double(fs); twoPiT = 2 * PI * dt; // Loop over number of auditory filters for (chan = 0; chan < nFilter2Process; chan++) { // Get index of current filter chanIdx = processFilter[chan]; // Calculate gain depending on middle ear filter if (bUseMidEar){ // Calculate middle ear coefficient fChan[chanIdx].midEarCoeff = DBtoAmplitude(loudnessLevelInPhons(DB,fChan[chanIdx].cf)-DB); // Calculate overall channel gain gain = fChan[chanIdx].midEarCoeff * pow(twoPiT * fChan[chanIdx].bw, 4) / 3.0; } else{ gain = pow(twoPiT * fChan[chanIdx].bw, 4) / 3.0; } z = exp(-twoPiT * fChan[chanIdx].bw); if (bTimeAlign){ // Integrate phase correction f1Down = cos(fChan[chanIdx].cf * twoPiT + fChan[chanIdx].phaseCorrection) * z; f2Down = sin(fChan[chanIdx].cf * twoPiT + fChan[chanIdx].phaseCorrection) * z; // Delay tc = getRound(fChan[chan].delay); } else{ f1Down = cos(fChan[chanIdx].cf * twoPiT) * z; f2Down = sin(fChan[chanIdx].cf * twoPiT) * z; // Delay tc = 0; } // Without phase correction f1Up = cos(fChan[chanIdx].cf * twoPiT) * z; f2Up = sin(fChan[chanIdx].cf * twoPiT) * z; // Initialize gammatone filter states for (ii = 0; ii < 4; ii++) { fChan[chanIdx].p[ii] = 0; fChan[chanIdx].q[ii] = 0; } // Loop over length of input signal for (nn = 0; nn < (nSamples + tc); nn++) { // *========================================== // * Basilar membrane displacement // *========================================== if (nn >= tc){ // % Basilar membrane displacement bm[(nn-tc)+chan*nSamples] = fChan[chanIdx].p[3] * gain; } // *========================================== // * Envelope // *========================================== if (nlhs>1){ if (nn >= tc){ // % Basilar membrane displacement env[(nn-tc)+chan*nSamples] = sqrt(fChan[chanIdx].p[3] * fChan[chanIdx].p[3] + fChan[chanIdx].q[3] * fChan[chanIdx].q[3]) * gain; } } // Loop over the order of the gammatone filterbank for (ii = 0; ii < 4; ii++) { x[ii] = f1Up * fChan[chanIdx].p[ii] - f2Up * fChan[chanIdx].q[ii]; y[ii] = f2Up * fChan[chanIdx].p[ii] + f1Up * fChan[chanIdx].q[ii]; } // Zero-padding data = (nn < nSamples) ? input[nn] : 0.0; fChan[chanIdx].p[0] = data * f1Down + x[0]; fChan[chanIdx].q[0] = data * f2Down + y[0]; fChan[chanIdx].p[1] = fChan[chanIdx].p[0] + x[1]; fChan[chanIdx].q[1] = fChan[chanIdx].q[0] + y[1]; fChan[chanIdx].p[2] = fChan[chanIdx].p[1] + x[1] + x[2]; fChan[chanIdx].q[2] = fChan[chanIdx].q[1] + y[1] + y[2]; fChan[chanIdx].p[3] = fChan[chanIdx].p[2] + x[1] + 2*x[2] + x[3]; fChan[chanIdx].q[3] = fChan[chanIdx].q[2] + y[1] + 2*y[2] + y[3]; } } // Free the memory used for the gammatone structure delete fChan; } // end of if(!bExit) } /* end mexFunction() */
void Chicken::start() { sf::Music music; if (!music.openFromFile("music/outlaw.ogg")) { return; // error } music.play(); music.setLoop(true); sf::RenderWindow window(sf::VideoMode(C_X, C_Y), "I WANNA", sf::Style::Close); image.loadFromFile("textures/upIco.png"); window.setIcon(179, 179, image.getPixelsPtr()); sf::RenderWindow windowGuide(sf::VideoMode(500, 700), "Guide", sf::Style::Titlebar); windowGuide.setVisible(false); if (guide==true) { window.setPosition(sf::Vector2i(30, 30)); windowGuide.setVisible(true); windowGuide.setPosition(sf::Vector2i(1370, 170)); if (language == 1) { backgroundGuide.loadFromFile("textures/chickenRules.png"); } else { backgroundGuide.loadFromFile("textures/engUpRules.png"); } backgroundsprGuide.setTexture(backgroundGuide); windowGuide.draw(backgroundsprGuide); windowGuide.display(); } ChickenDeck * myDeck = new ChickenDeck(); myDeck->randomize(); ChickenDeck * aiDeck = new ChickenDeck(); aiDeck->randomizeNew(); ChickenCard * middleCard = new ChickenCard(); ChickenCard * myCard = new ChickenCard(); ChickenCard * aiCard = new ChickenCard(); ChickenNext * nextBtn = new ChickenNext(); nextBtn->next(); ChickenNext * message = new ChickenNext(); ChickenBackCard * myDeckSkin = new ChickenBackCard(); ChickenBackCard * aiDeckSkin = new ChickenBackCard(); aiDeckSkin->sprite.setPosition(30, 30); myDeckSkin->sprite.setPosition(C_X-30-139, C_Y-30-216); aiDeckSkin->setTexture(); myDeckSkin->setTexture(); std::queue<ChickenCard> myQueue; std::queue<ChickenCard> aiQueue; int strokeman = getStrokeman(); fonts(strokeman); for (int i=0; i<52; i++) { myQueue.push(myDeck->getCard()); aiQueue.push(aiDeck->getCard()); } bool compareB = false; bool start = true; bool middleVisible = false; int myPoints = 0, aiPoints = 0, wannaPoints = 1; char text[C_BUFFER] = ""; int round = 1; int myQueueSize, aiQueueSize; bool finish = false; while(window.isOpen()) { sf::Event event; while(window.pollEvent(event)) { if(event.type == sf::Event::Closed) { window.close(); } if ((event.type == sf::Event::MouseButtonPressed)&&(event.mouseButton.button == sf::Mouse::Left)) { if (nextBtn->isPressed(event.mouseButton.x, event.mouseButton.y) && (!finish)) { if (!start) { if (myPoints == wannaPoints && aiPoints == wannaPoints) { if (strokeman == PLAYER) { *middleCard = *myCard; myQueue.pop(); aiQueue.push(aiQueue.front()); aiQueue.pop(); wannaPoints++; } else { *middleCard = *aiCard; aiQueue.pop(); myQueue.push(myQueue.front()); myQueue.pop(); wannaPoints++; } middleVisible = true; } else if(myPoints == wannaPoints) { *middleCard = *myCard; myQueue.pop(); aiQueue.push(aiQueue.front()); aiQueue.pop(); wannaPoints++; middleVisible = true; } else if (aiPoints == wannaPoints) { *middleCard = *aiCard; aiQueue.pop(); myQueue.push(myQueue.front()); myQueue.pop(); wannaPoints++; middleVisible = true; } else { myQueue.push(myQueue.front()); myQueue.pop(); aiQueue.push(aiQueue.front()); aiQueue.pop(); } if (middleVisible) { middleCard->setTexture(); middleCard->sprite.setPosition(430.5, C_Y-550); } if (wannaPoints==14) { round++; wannaPoints = 1; getRound(round); } sprintf(text, WANNACONST, getWannaText(wannaPoints)); wannaText.setString(text); myQueueSize = myQueue.size(); sprintf(text, "%i", myQueueSize); mySize.setString(text); aiQueueSize = aiQueue.size(); sprintf(text, "%i", aiQueueSize); aiSize.setString(text); if (myQueueSize == 0 || aiQueueSize == 0) { finish = true; if (myQueueSize == 0) { message->win(); } else { message->lose(); } break; } } compareB = true; start = false; *myCard = myQueue.front(); *aiCard = aiQueue.front(); myCard->setTexture(); aiCard->setTexture(); myCard->sprite.setPosition(30, 30+216+30); aiCard->sprite.setPosition(C_X-139-30, C_Y-30-216-216-30); myPoints = myCard->getPoints(); aiPoints = aiCard->getPoints(); if (strokeman == PLAYER) { strokeman = AI; strokeText.setString("Enemy stroke..."); } else { strokeman = PLAYER; strokeText.setString("Your stroke..."); } } } } window.clear(sf::Color(0,115,0)); if (finish == true) { window.draw(message->sprite); } else { window.draw(backgroundspr); window.draw(myDeckSkin->sprite); window.draw(aiDeckSkin->sprite); if (compareB == true) { window.draw(myCard->sprite); window.draw(aiCard->sprite); } if (middleVisible) { window.draw(middleCard->sprite); } window.draw(nextBtn->sprite); window.draw(mySize); window.draw(aiSize); window.draw(wannaText); window.draw(strokeText); window.draw(myName); window.draw(aiName); } window.display(); } return; }
int BaseAI::round() { return getRound(c); }
void Server::playedCard(QString message, Player *pl) { qDebug() << "Server::playedCard"; QString num; QString suit; int value; if (message == "0") { num = pl->card(0)->number(); suit = pl->card(0)->suit(); value = pl->card(0)->value(); } else if (message == "1") { num = pl->card(1)->number(); suit = pl->card(1)->suit(); value = pl->card(1)->value(); } else { num = pl->card(2)->number(); suit = pl->card(2)->suit(); value = pl->card(2)->value(); } QString newMessage; QString code; code = "04"; //code for played card. newMessage = num + suit; qDebug() << newMessage; if (numberOfPlayers == 4) { if (players[0] == pl) { players[1]->sendMessage(code + "03" + newMessage); players[2]->sendMessage(code + "02" + newMessage); players[3]->sendMessage(code + "01" + newMessage); players[0]->setPlayed(true); players[0]->setPlayedCardValue(value); if (getRound() == 0) cardsOfRoundOne[0] = value; if (getRound() == 1) cardsOfRoundTwo[0] = value; if (getRound() == 2) cardsOfRoundThree[0] = value; } else if (players[1] == pl) { players[0]->sendMessage(code + "01" + newMessage); players[2]->sendMessage(code + "03" + newMessage); players[3]->sendMessage(code + "02" + newMessage); players[1]->setPlayed(true); players[1]->setPlayedCardValue(value); if (getRound() == 0) cardsOfRoundOne[1] = value; if (getRound() == 1) cardsOfRoundTwo[1] = value; if (getRound() == 2) cardsOfRoundThree[1] = value; } else if (players[2] == pl) { players[0]->sendMessage(code + "02" + newMessage); players[1]->sendMessage(code + "01" + newMessage); players[3]->sendMessage(code + "03" + newMessage); players[2]->setPlayed(true); players[2]->setPlayedCardValue(value); if (getRound() == 0) cardsOfRoundOne[2] = value; if (getRound() == 1) cardsOfRoundTwo[2] = value; if (getRound() == 2) cardsOfRoundThree[2] = value; } else { players[0]->sendMessage(code + "03" + newMessage); players[1]->sendMessage(code + "02" + newMessage); players[2]->sendMessage(code + "01" + newMessage); players[3]->setPlayed(true); players[3]->setPlayedCardValue(value); if (getRound() == 0) cardsOfRoundOne[3] = value; if (getRound() == 1) cardsOfRoundTwo[3] = value; if (getRound() == 2) cardsOfRoundThree[3] = value; } if (players[0]->hasPlayed() && players[1]->hasPlayed() && players[2]->hasPlayed() && players[3]->hasPlayed()) { checkGame(); } else { nextPlayer(); } } else { if (players[0] == pl) { players[1]->sendMessage(code + "02" + newMessage); players[1]->setPlayed(true); players[1]->setPlayedCardValue(value); if (getRound() == 0) cardsOfRoundOne[0] = value; if (getRound() == 1) cardsOfRoundTwo[0] = value; if (getRound() == 2) cardsOfRoundThree[0] = value; } else { players[0]->sendMessage(code + "02" + newMessage); players[0]->setPlayed(true); players[0]->setPlayedCardValue(value); if (getRound() == 0) cardsOfRoundOne[1] = value; if (getRound() == 1) cardsOfRoundTwo[1] = value; if (getRound() == 2) cardsOfRoundThree[1] = value; } if (players[0]->hasPlayed() && players[1]->hasPlayed()) { qDebug() << "All players have played!"; checkGame(); } else { qDebug() << "Someone not have played yet, going to next player"; nextPlayer(); } } }
int calculateHealth(HunterView currentView, PlayerID player) { int i,k; int health; char encounter; char location[3]; char pastLocation[3] = ""; location[2] = '\0'; Round roundsPlayed = getRound(currentView); if (currentView->totalTurns % 5 > player) roundsPlayed++; // ================================================ // HUNTERS // ================================================ if (player >= 0 && player <= 3) { health = GAME_START_HUNTER_LIFE_POINTS; // loop through all the plays for the specified player for (i = 0; i < roundsPlayed; i++) { // store the previous location of the hunter if (roundsPlayed >= 2) strcpy(pastLocation, location); location[0] = currentView->seperatedPP[(i*5)+player][1]; location[1] = currentView->seperatedPP[(i*5)+player][2]; // if the hunter hasn't moved, health += 3 if (strcmp(location, pastLocation) == 0) { // hunters can't exceed 9 health if (health <= 6) { health += 3; } else { health = GAME_START_HUNTER_LIFE_POINTS; } } // loop through all four characters at the end of the playstring for (k = 3; k <= 6; k++) { encounter = currentView->seperatedPP[(i*5)+player][k]; if (encounter == 'T') health -= LIFE_LOSS_TRAP_ENCOUNTER; if (encounter == 'D') health -= LIFE_LOSS_DRACULA_ENCOUNTER; } // check if hunter is in the hospital and reset hp if true if (health < 1) { currentView->died[player] = TRUE; currentView->playerStruct[player]->numDied++; health = GAME_START_HUNTER_LIFE_POINTS; } else { currentView->died[player] = FALSE; } } // ================================================ // DRACULA // ================================================ } else {//(player == PLAYER_DRACULA) { health = GAME_START_BLOOD_POINTS; // loop through all the plays for the specified player for (i = 0; i < roundsPlayed; i++) { // store the location location[0] = currentView->seperatedPP[(i*5)+player][1]; location[1] = currentView->seperatedPP[(i*5)+player][2]; LocationID locDracula = translateLocationID(location); // handle doubleback if (locDracula >= 74 && locDracula <= 78) { LocationID history[TRAIL_SIZE]; getHistory(currentView, PLAYER_DRACULA, history); locDracula = history[location[1] - '0']; } // Reduce health by 10 if a hunter was encountered if (locDracula >= 0 && locDracula <= 70 && locDracula != CASTLE_DRACULA) { health -= LIFE_LOSS_HUNTER_ENCOUNTER; } // Reduce health by 2 if at sea if ((locDracula >= 61 && locDracula <= 70) || (locDracula == 72)) { health -= LIFE_LOSS_SEA; } // Increase health by 10 if Dracula is at castle if (locDracula == CASTLE_DRACULA) { health += LIFE_GAIN_CASTLE_DRACULA; } } } return health; }
// What are the specified player's next possible moves LocationID *whereCanTheyGo(HunterView currentView, int *numLocations, PlayerID player, int road, int rail, int sea) { assert(currentView != NULL); assert(0 <= player && player < NUM_PLAYERS); assert(numLocations != NULL); Round theirNextRound; // check if they're before or after me if(player >= getCurrentPlayer(currentView->g)) { theirNextRound = getRound(currentView->g); } else { theirNextRound = getRound(currentView->g) + 1; } // return value LocationID *ret; // check if first round if(theirNextRound == FIRST_ROUND) { ret = (LocationID *)(malloc(sizeof(LocationID)*NUM_MAP_LOCATIONS)); (*numLocations) = 0; // everywhere! int i; for(i=0;i<NUM_MAP_LOCATIONS;i++) { // dracula can go everywhere except ST_JOSEPH_AND_ST_MARYS if(player != PLAYER_DRACULA || i != ST_JOSEPH_AND_ST_MARYS) { ret[(*numLocations)] = i; (*numLocations)++; } } } else { if(player == PLAYER_DRACULA) { // dracula // dracula's current location LocationID dracLoc = whereIs(currentView, PLAYER_DRACULA); // see if we can infer dracula's location // if valid, do the usual if(validPlace(dracLoc)) { // dracula can't travel by rail even if he wants to ret = connectedLocations(currentView->g, numLocations, whereIs(currentView, PLAYER_DRACULA), theirNextRound, player, road, FALSE, sea); } else { (*numLocations) = 0; // FIXME not sure what to return; probably doesn't matter ret = NULL; } } else { // a hunter ret = connectedLocations(currentView->g, numLocations, getLocation(currentView->g, player), theirNextRound, player, road, rail, sea); } } return ret; }
void Round::AddRole(Unit* t) { getRound()->UnitList.push_back(t); role_num++; }