Brad Wardell's site for talking about the customization of Windows.
Published on January 14, 2015 By Frogboy In GalCiv III Dev Journals

Well the party is almost over for you humans.

I’ve never hidden the fact that I consider human beings playing my AI a necessary evil.  I need your money to fund my AI work. Smile

This time around, I’ve got a talented young developer working with me.  He makes me feel old. Very. Very old. 

A lot has changed over the past 20 years.  It is still technically C++ but it’s all very different from what it used to be.

Example code

//GalCiv III:  Example code tags a planet as a potential target.

if(atWar)
        {
            FixedDecimal militaryPower = GetInterface<IStat>(*it)->GetStat(StatTypes::FactionPower, StatUsages::Actual);

            CBasicGameObject* pClosestPlanet = NULL;
            ULONG closestDistance = ULONG_MAX;

            const ObjectPtrList& ownedPlanets = GetInterface<IGC3Player>(*it)->GetOwnedPlanets();
            for(auto planetIt = ownedPlanets.Begin(); planetIt != ownedPlanets.End(); ++planetIt)
            {
                TilePair planetPos = GetInterface<IBasicGameObject>(*planetIt)->GetTilePosition().tile;
               
                BOOL isPlanetInRange = CGalaxy::GetInstance()->GetRangeSystem().IsWithinFleetRangeValue(m_pPlayer, planetPos.posX, planetPos.posY, rangeToUse);
                if(isPlanetInRange)
                {
                    ULONG planetDistance = CWorldSpace::HexDistance(capitalPos, planetPos);
                    if(planetDistance < closestDistance)
                    {
                        closestDistance = planetDistance;
                        pClosestPlanet = (*planetIt);
                    }
                }
            }

            if(pClosestPlanet && militaryPower < weakestPower)
            {
                weakestPower = militaryPower;
                pWeakestPlayer = (*it);
                pTargetPlanet = pClosestPlanet;
            }
        }

 

 

  //GalCiv II: I wrote this to control a transport

//*****************************************************************************
//* AIFindTransportDestination
//* Purpose:
//* Find a planet for a transport to go to
//*****************************************************************************
BOOL classCivilization::AIFindTransportDestination(PclassStarShip pShip)
{
 
   if(pShip->IsInFleet() && !pShip->IsFleet()) return false;


   //Preliminaries: Wait for escorts
   if(pShip->HasDestination() && pShip->IsOrbiting() == FALSE && !pShip->GetAttack() && !AIHostilesInSector(pShip->GetSectorID()) &&  g_pGalaxy->GetDistanceFromFriendlyPlanet(QueryID(),pShip->GetTileX(),pShip->GetTileY())<SECTOR_SIZE && pShip->ulTransportWaitTurns<5)
   {
      pShip->CancelDestination();
      pShip->SetMovesLeft(0);
      return false;
   }

   //Preliminaries: Wait for escorts
   if(pShip->IsOrbiting() == FALSE && !pShip->GetAttack() && !AIHostilesInSector(pShip->GetSectorID()) &&  g_pGalaxy->GetDistanceFromFriendlyPlanet(QueryID(),pShip->GetTileX(),pShip->GetTileY())<SECTOR_SIZE && pShip->ulTransportWaitTurns<5)
   {
      pShip->ulTransportWaitTurns++;
      return false;
   }

   //Step #0: Let's see if there are hostiles near by..
   if(AIHostilesInSector(pShip->GetSectorID()) && pShip->GetAttack()<10 && !pShip->IsOrbiting())
   {
      PclassStarShip pEnemy = pShip->FindClosestLocalEnemyShip(0);

      if (pEnemy && pShip->GetTurnsAway(pEnemy->GetTileX(),pEnemy->GetTileY()) < 2 && pEnemy->GetAttack() > pShip->GetAttack())
      {
         pShip->AITakeEvasiveAction(pEnemy->GetTileX(),pEnemy->GetTileY());
         return TRUE;
      }

   }

   //Step #1: Let's see if there's another undefended planet in sector.
   PclassPlanet pPlanet = AIFindUndefendedEnemyPlanet(pShip->GetSectorID());

 
   if(pPlanet && (!AIHostilesInSector(pPlanet->GetSectorID()) || pShip->GetAttack()>8))
   {
      pShip->CancelDestination();
      pShip->pPlanetDestination = pPlanet;
      return true;
   }

   //Step #2: Let's see where they're currently going.
   pPlanet = pShip->pPlanetDestination;
   if(pPlanet && ulIntelligence<40)
   {
      if(pPlanet->IsDefended() == FALSE && GetRelationsWith(pPlanet->GetOwner()) == AT_WAR)
         return true;
   }

   if(pPlanet)
   {
      if(pPlanet->IsDefended() == TRUE || (AIHostilesInSector(pPlanet->GetSectorID()) && !pShip->GetAttack()) )
         pShip->CancelDestination();
   
   }

 

   //Step #3: Let's look at our primary sector focus and use that.
   if(this->AIulSectorFocuses[0] != INVALID_SECTOR_FOCUS)
   {
        ULONG ulSectorsToFocusOn = this->GetNumSectorFocuses();   
        for (ULONG ulIndex = 0; ulIndex<ulSectorsToFocusOn; ulIndex++)
        {
           ULONG ulSectorID = this->AIulSectorFocuses[ulIndex];
           pPlanet = AIFindUndefendedEnemyPlanet(ulSectorID);
           BOOL bHostilesInSector = false;
           if(pPlanet)
           {
               bHostilesInSector = this->AIHostilesInSector(pPlanet->GetSectorID());


               if(this->ulIntelligence<50 || pShip->GetAttack()>5 )
                  bHostilesInSector = false;
           }
           if(pPlanet && pPlanet->ulAIInvadersAssigned[QueryID()]<4 && !bHostilesInSector )
           {
              pShip->CancelDestination();
              pShip->pPlanetDestination = pPlanet;
              return true;
           }
        }
   }

   //Step #4: Let's see if there are other planets to deal with.
   //Note that we won't go over to sectors with undefended planets
   //IF there are enemy ships in there
   pPlanet = pShip->FindClosestUndefendedEnemyPlanet(0);
   if(pPlanet && (AIHostilesInSector(pPlanet->GetSectorID() == FALSE || pShip->GetAttack()>0)))
   {
         pShip->CancelDestination();
         pShip->pPlanetDestination = pPlanet;
         return true;
   }

   //Step #4: We're AT the Rally Point
   PclassRallyPoint pOnRallyPoint = this->FindNearestRallyPoint(pShip->GetTileX(),pShip->GetTileY());
   if(pOnRallyPoint && pOnRallyPoint->GetDistanceInTiles(pShip) == 0)
   {
      pShip->GoHome();
   }
  
   //Step #5: What if there are hostiles here? Let's retreat
   if(this->AIHostilesInSector(pShip->GetSectorID() && !pShip->GetAttack()))
   {
      pShip->GoHome();
   }
 
   return false;

}


Comments (Page 3)
3 Pages1 2 3 
on Jan 20, 2015

ozgunguner_99

Lets face the fact guys, GalCiv III Ai will not be different from other tbs games . Give more money, research to ai . Because there is no real ai concept on software programming . I played endless space last week, i isolated an ai planet from other ai planets . Then what happened ? That planet produced a big fleet in one turn . Just one planet ! In one turn ! Even i played only hard difficulty . There is no Ai on tbs games, only brutality 

I don't know how endless space works, however, in Gal Civ it would be impossible for this to happen.  They have to follow the same rules humans do, which means one ship at one time.  They have a budget, they have a ship yard.  Not saying there isn't cheats the AI will take but, this is not one of them.

on Jan 20, 2015

ozgunguner_99

I played endless space last week, i isolated an ai planet from other ai planets . Then what happened ? That planet produced a big fleet in one turn .

I really enjoy Amplitude's games. Endless Legend was the best 4x I've played in a long time, and I bought Endless Space on the basis and thought it was very solid. That said, AI is probably the biggest weakness of those games. Using Endless Space as an example to proclaim that good TBS AI is not possible is a fallacy.  Even if Stardock can only get GCII-level AI in, it will be considerably better than Endless Space imo.

on Jan 21, 2015

I would like to she an adaptive ai.

on Feb 20, 2015

Admiral and Ozgun, 

 

The ai will be one that adapts to the player. It did this so so in GC II and will be FAR more reactive in GC III. It will use YOUR designs. I will react to your ships and counter them and it will form massive fleets to support invasions on YOUR planets. 

 

I do believe you both will be unpleasantly surprised. 

3 Pages1 2 3