GreatPeopleDirectiveTypes CvPlayerAI::GetDirectiveScientist (CvUnit* pGreatScientist) { GreatPeopleDirectiveTypes eDirective = NO_GREAT_PEOPLE_DIRECTIVE_TYPE; if (eDirective == NO_GREAT_PEOPLE_DIRECTIVE_TYPE && PreparingForWar(this) && !isGoldenAge()) { eDirective = GREAT_PEOPLE_DIRECTIVE_GOLDEN_AGE; } // If I'm in danger, use great person to get a tech if (eDirective == NO_GREAT_PEOPLE_DIRECTIVE_TYPE && !IsSafe(this)) { eDirective = GREAT_PEOPLE_DIRECTIVE_USE_POWER; } if (eDirective == NO_GREAT_PEOPLE_DIRECTIVE_TYPE && GC.getGame().getGameTurn() <= ((GC.getGame().getEstimateEndTurn() * 1) / 4)) { if (GetDiplomacyAI()->IsGoingForSpaceshipVictory()) { eDirective = GREAT_PEOPLE_DIRECTIVE_CONSTRUCT_IMPROVEMENT; } } if (eDirective == NO_GREAT_PEOPLE_DIRECTIVE_TYPE && (GC.getGame().getGameTurn() - pGreatScientist->getGameTurnCreated()) >= GC.getAI_HOMELAND_GREAT_PERSON_TURNS_TO_WAIT()) { // a free tech is not bad eDirective = GREAT_PEOPLE_DIRECTIVE_USE_POWER; } return eDirective; }
// AMS: AI will build academy more consistently. GreatPeopleDirectiveTypes CvPlayerAI::GetDirectiveScientist(CvUnit* /*pGreatScientist*/) { GreatPeopleDirectiveTypes eDirective = NO_GREAT_PEOPLE_DIRECTIVE_TYPE; // If I'm in danger, use great person to get a tech boost if(eDirective == NO_GREAT_PEOPLE_DIRECTIVE_TYPE && !IsSafe(this)) { eDirective = GREAT_PEOPLE_DIRECTIVE_USE_POWER; } if(eDirective == NO_GREAT_PEOPLE_DIRECTIVE_TYPE && GC.getGame().getGameTurn() <= ((GC.getGame().getEstimateEndTurn() * 1) / 3)) { if(GetDiplomacyAI()->IsGoingForSpaceshipVictory()) { eDirective = GREAT_PEOPLE_DIRECTIVE_CONSTRUCT_IMPROVEMENT; } else { //AMS: Even if not going spaceship right now, build academy 66% of times. if ((GC.getGame().getGameTurn()) % 3 != 0) { eDirective = GREAT_PEOPLE_DIRECTIVE_CONSTRUCT_IMPROVEMENT; } } } if (eDirective == NO_GREAT_PEOPLE_DIRECTIVE_TYPE) { // a tech boost is never bad eDirective = GREAT_PEOPLE_DIRECTIVE_USE_POWER; } return eDirective; }
void CreateGraph(int num) { int r; int c; int k; int x[4] = {0,0,-1,1}; int y[4] = {1,-1,0,0}; for(r=0; r< num; r++) { for(c=0; c<num; c++) { int l = 0; for(k=0; k < 4; k++) { if (IsSafe(r+x[k], c+y[k], num)) { int val = num*(r+x[k]) + (c+y[k]); //printf("indexx[%d] indexy[%d] val[%d]\n", r*num+c, l, val); adjlist[r*num+c][l] = val; l++; } } } } #if 0 /* Print Adjacency List */ for(r=0; r< num*num; r++) { for(c=0; c< 4; c++) { printf("[%d]", adjlist[r][c]); } printf("\n"); } #endif }
int FindSudoku_Util(int buffer[V][V]){ int row; int col; if(!IsEmptyCell(buffer,&row,&col)){ return 1; } int i; for(i=1;i<=9;i++){ if(IsSafe(buffer,row,col,i)){ buffer[row][col]=i; if(FindSudoku_Util(buffer)){ return 1; }else{ buffer[row][col]=0; } } } return 0; }
GreatPeopleDirectiveTypes CvPlayerAI::GetDirectiveArtist (CvUnit* pGreatArtist) { GreatPeopleDirectiveTypes eDirective = NO_GREAT_PEOPLE_DIRECTIVE_TYPE; if (eDirective == NO_GREAT_PEOPLE_DIRECTIVE_TYPE && PreparingForWar(this) && !isGoldenAge()) { eDirective = GREAT_PEOPLE_DIRECTIVE_GOLDEN_AGE; } if (eDirective == NO_GREAT_PEOPLE_DIRECTIVE_TYPE && GC.getGame().getGameTurn() <= ((GC.getGame().getEstimateEndTurn() * 2) / 4)) { if (GetDiplomacyAI()->IsGoingForCultureVictory()) { eDirective = GREAT_PEOPLE_DIRECTIVE_CONSTRUCT_IMPROVEMENT; } } // gank territory from neighbor we don't like if (eDirective == NO_GREAT_PEOPLE_DIRECTIVE_TYPE && IsSafe(this)) { int iScore = 0; CvPlot* pTargetPlot = FindBestArtistTargetPlot(pGreatArtist, iScore); if (pTargetPlot) { eDirective = GREAT_PEOPLE_DIRECTIVE_USE_POWER; } } if (eDirective == NO_GREAT_PEOPLE_DIRECTIVE_TYPE && (GC.getGame().getGameTurn() - pGreatArtist->getGameTurnCreated()) >= GC.getAI_HOMELAND_GREAT_PERSON_TURNS_TO_WAIT()) { eDirective = GetUnresolvedAction(this, pGreatArtist); } return eDirective; }
bool SolveSudoku(int grid[][N]) { int row, col; if (!FindUnassignedLocation(grid, row, col)) { return true; // solved it } for (int num = 1; num <= 9; ++num) { if (IsSafe(grid, row, col, num)) { grid[row][col] = num; if (SolveSudoku(grid)) { return true; } else { grid[row][col] = 0; } } } return false; }
GreatPeopleDirectiveTypes CvPlayerAI::GetDirectiveMerchant (CvUnit* pGreatMerchant) { GreatPeopleDirectiveTypes eDirective = NO_GREAT_PEOPLE_DIRECTIVE_TYPE; // if the merchant is in an army, he's already marching to a destination, so don't evaluate him if (pGreatMerchant->getArmyID() != FFreeList::INVALID_INDEX) { return NO_GREAT_PEOPLE_DIRECTIVE_TYPE; } if (eDirective == NO_GREAT_PEOPLE_DIRECTIVE_TYPE && PreparingForWar(this) && !isGoldenAge()) { eDirective = GREAT_PEOPLE_DIRECTIVE_GOLDEN_AGE; } // Attempt a run to a minor civ if (eDirective == NO_GREAT_PEOPLE_DIRECTIVE_TYPE && IsSafe(this)) { CvPlot* pTarget = FindBestMerchantTargetPlot (pGreatMerchant, true); if (pTarget) { eDirective = GREAT_PEOPLE_DIRECTIVE_USE_POWER; } } if (eDirective == NO_GREAT_PEOPLE_DIRECTIVE_TYPE && (GC.getGame().getGameTurn() - pGreatMerchant->getGameTurnCreated()) >= GC.getAI_HOMELAND_GREAT_PERSON_TURNS_TO_WAIT()) { eDirective = GetUnresolvedAction(this, pGreatMerchant); } return eDirective; }
GreatPeopleDirectiveTypes CvPlayerAI::GetDirectiveMerchant(CvUnit* pGreatMerchant) { GreatPeopleDirectiveTypes eDirective = NO_GREAT_PEOPLE_DIRECTIVE_TYPE; // if the merchant is in an army, he's already marching to a destination, so don't evaluate him if(pGreatMerchant->getArmyID() != FFreeList::INVALID_INDEX) { return NO_GREAT_PEOPLE_DIRECTIVE_TYPE; } if (eDirective == NO_GREAT_PEOPLE_DIRECTIVE_TYPE && GC.getGame().getGameTurn() <= ((GC.getGame().getEstimateEndTurn() * 2) / 4)) { if (GetDiplomacyAI()->IsGoingForDiploVictory()) { eDirective = GREAT_PEOPLE_DIRECTIVE_CONSTRUCT_IMPROVEMENT; } } // Attempt a run to a minor civ if(eDirective == NO_GREAT_PEOPLE_DIRECTIVE_TYPE && IsSafe(this)) { CvPlot* pTarget = FindBestMerchantTargetPlot(pGreatMerchant, true); if(pTarget) { eDirective = GREAT_PEOPLE_DIRECTIVE_USE_POWER; } } if(eDirective == NO_GREAT_PEOPLE_DIRECTIVE_TYPE && (GC.getGame().getGameTurn() - pGreatMerchant->getGameTurnCreated()) >= GC.getAI_HOMELAND_GREAT_PERSON_TURNS_TO_WAIT()) { eDirective = GREAT_PEOPLE_DIRECTIVE_CONSTRUCT_IMPROVEMENT; } return eDirective; }
void Vig(int i){ int j; if(i<=N){ //Se esta vazio a posicao i if(linha[i] == 0){ //qual j-esimo vigilante colocar na posicao i for(j=1;j<=N;j++){ //verifica se o j-esimo vigilante ja nao foi colocado if(IsSafe(j)){ linha[i]=j; Vig(i+1); linha[i]=0; } } } else{ Vig(i+1); } } else{ printf("%d",linha[1]); for(j=2;j<=N;j++){ printf(" %d",linha[j]); } printf("\n"); } }
void GoBlock::Write(std::ostream& stream) const { WriteID(stream); stream << '\n' << SgWritePointSet(Stones(), "Stones: ") << "\nhealthy: " << Healthy().Length() << "\nisSafe: " << SgWriteBoolean(IsSafe()) << "\nhas1Eye: " << SgWriteBoolean(Has1Eye()) << "\n"; }
AztecOO_StatusTestCombo& AztecOO_StatusTestCombo::AddStatusTest(AztecOO_StatusTest& a) { if (IsSafe(a)) tests_.push_back(&a); else // if (Utils::doPrint(Utils::Warning)) { const int indent = 2; cout << "\n*** WARNING! ***\n"; cout << "This combo test currently consists of the following:\n"; this->Print(cout, indent); cout << "Unable to add the following test:\n"; a.Print(cout, indent); cout << "\n"; } return *this; }
int DFS(pos p[],int i){ visited[i]=1; int j=0; if(IsSafe(p[i])==1) answer=1; else { for(j=0;j<num;j++){ // printf("give a judge\n"); if(visited[j]==0 && distance(p[i],p[j])<=step){ answer=DFS(p,j); if(answer==1) break; } } } return answer; }
int DFS007(ALGraph G, int v) { int w; int answer = 0; VertexType v1, w1; visited[v] = TRUE; if (IsSafe(G, v)) answer = 1; else { for (w = 0; w < G.vexnum; w++) { if (!visited[w] && w != v && Jump(G, v, w)) answer = DFS007(G, w); if (answer == 1) break; } } }
boolean Nqueen(int grid[n][n],int row) { for(int i=row;i<n;i++) { for(int j=0;j<n;j++) { if(IsSafe(grid,i,j)) { grid[i][j] = 1; if(Nqueen(grid,i+1)) return TRUE; grid[i][j] = 0; } } return FALSE; } return TRUE; }
Order FindSafePlace(User *user) { int selfX=user->x[user->who]; int selfY=user->y[user->who]; int select; if(!IsSafe(user,selfX,selfY)) { srand(unsigned(time(0))); select=rand()%safePositionCount; int x=safePosition[select]%boderX; int y=safePosition[select]/boderX; Path path=PathBetween(selfX,selfY,x,y); Order order; memset(&order,0,sizeof(order)); order.act=path.nextDirection[0]; return order; } Order order; memset(&order,0,sizeof(order)); order.act=STOP; return order; }
// Return true if we were in the safe time last update, but not now bool CCSBot::IsEndOfSafeTime() const { return m_wasSafe && !IsSafe(); }
const ValueType& GetSafe(const glm::ivec3& i, const ValueType& v) const { return (IsSafe(i[0], i[1], i[2]) ? (*this)(i[0], i[1], i[2]) : v); }
const ValueType& GetSafe(int i, int j, int k, const ValueType& v) const { return (IsSafe(i, j, k) ? (*this)(i, j, k) : v); }
// Update the "looking around" behavior. void CCSBot::UpdateLookAround(bool updateNow) { // check if looking around has been inhibited // Moved inhibit to allow high priority enemy lookats to still occur if (gpGlobals->time < m_inhibitLookAroundTimestamp) return; const float recentThreatTime = 0.25f; // 1.0f; // Unless we can hear them moving, in which case look towards the noise if (!IsEnemyVisible()) { const float noiseStartleRange = 1000.0f; if (CanHearNearbyEnemyGunfire(noiseStartleRange)) { Vector spot = m_noisePosition; spot.z += HalfHumanHeight; SetLookAt("Check dangerous noise", &spot, PRIORITY_HIGH, recentThreatTime); InhibitLookAround(RANDOM_FLOAT(2.0f, 4.0f)); return; } } // If we recently saw an enemy, look towards where we last saw them if (!IsLookingAtSpot(PRIORITY_MEDIUM) && gpGlobals->time - m_lastSawEnemyTimestamp < recentThreatTime) { ClearLookAt(); Vector spot = m_lastEnemyPosition; // find enemy position on the ground if (GetSimpleGroundHeight(&m_lastEnemyPosition, &spot.z)) { spot.z += HalfHumanHeight; SetLookAt("Last Enemy Position", &spot, PRIORITY_MEDIUM, RANDOM_FLOAT(2.0f, 3.0f), true); return; } } // Look at nearby enemy noises if (UpdateLookAtNoise()) return; if (IsNotMoving()) { // if we're sniping, zoom in to watch our approach points if (IsUsingSniperRifle()) { // low skill bots don't pre-zoom if (GetProfile()->GetSkill() > 0.4f) { if (!IsViewMoving()) { float range = ComputeWeaponSightRange(); AdjustZoom(range); } else { // zoom out if (GetZoomLevel() != NO_ZOOM) SecondaryAttack(); } } } if (m_lastKnownArea == NULL) return; if (gpGlobals->time < m_lookAroundStateTimestamp) return; // if we're sniping, switch look-at spots less often if (IsUsingSniperRifle()) m_lookAroundStateTimestamp = gpGlobals->time + RANDOM_FLOAT(5.0f, 10.0f); else m_lookAroundStateTimestamp = gpGlobals->time + RANDOM_FLOAT(1.0f, 2.0f); if (m_approachPointCount == 0) { ClearLookAt(); return; } int which = RANDOM_LONG(0, m_approachPointCount - 1); Vector spot = m_approachPoint[ which ]; // don't look at the floor, look roughly at chest level // TODO: If this approach point is very near, this will cause us to aim up in the air if were crouching spot.z += HalfHumanHeight; SetLookAt("Approach Point (Hiding)", &spot, PRIORITY_LOW); return; } // Glance at "encouter spots" as we move past them if (m_spotEncounter) { // Check encounter spots if (!IsSafe() && !IsLookingAtSpot(PRIORITY_LOW)) { // allow a short time to look where we're going if (gpGlobals->time < m_spotCheckTimestamp) return; // TODO: Use skill parameter instead of accuracy // lower skills have exponentially longer delays float_precision asleep = (1.0f - GetProfile()->GetSkill()); asleep *= asleep; asleep *= asleep; m_spotCheckTimestamp = gpGlobals->time + asleep * RANDOM_FLOAT(10.0f, 30.0f); // figure out how far along the path segment we are Vector delta = m_spotEncounter->path.to - m_spotEncounter->path.from; float_precision length = delta.Length(); float adx = float(Q_abs(int64(delta.x))); float ady = float(Q_abs(int64(delta.y))); float_precision t; if (adx > ady) t = (pev->origin.x - m_spotEncounter->path.from.x) / delta.x; else t = (pev->origin.y - m_spotEncounter->path.from.y) / delta.y; // advance parameter a bit so we "lead" our checks const float leadCheckRange = 50.0f; t += leadCheckRange / length; if (t < 0.0f) t = 0.0f; else if (t > 1.0f) t = 1.0f; // collect the unchecked spots so far const int MAX_DANGER_SPOTS = 8; HidingSpot *dangerSpot[MAX_DANGER_SPOTS]; int dangerSpotCount = 0; int dangerIndex = 0; const float checkTime = 10.0f; const SpotOrder *spotOrder; for (SpotOrderList::iterator iter = m_spotEncounter->spotList.begin(); iter != m_spotEncounter->spotList.end(); ++iter) { spotOrder = &(*iter); // if we have seen this spot recently, we don't need to look at it if (gpGlobals->time - GetHidingSpotCheckTimestamp(spotOrder->spot) <= checkTime) continue; if (spotOrder->t > t) break; dangerSpot[ dangerIndex++ ] = spotOrder->spot; if (dangerIndex >= MAX_DANGER_SPOTS) dangerIndex = 0; if (dangerSpotCount < MAX_DANGER_SPOTS) ++dangerSpotCount; } if (dangerSpotCount) { // pick one of the spots at random int which = RANDOM_LONG(0, dangerSpotCount - 1); const Vector *checkSpot = dangerSpot[ which ]->GetPosition(); Vector pos = *checkSpot; pos.z += HalfHumanHeight; // glance at the spot for minimum time SetLookAt("Encounter Spot", &pos, PRIORITY_LOW, 0, true, 10.0f); // immediately mark it as "checked", so we don't check it again // if we get distracted before we check it - that's the way it goes SetHidingSpotCheckTimestamp(dangerSpot[which]); } } } }