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 2)
3 Pages1 2 3 
on Jan 15, 2015

hedetet

I'm not sure what this thread is about...

Well, it IS certain that there is a conspiracy, right?  And it is aimed as us Earthlings!

 

on Jan 15, 2015

Maybe frog boy is like me, and wants to see some intelligent robots. Maybe he was just mocking. Maybe he just wanted to show off how he writes code. Maybe he wanted input on how he programs.

on Jan 15, 2015

hedetet

'm not sure what this thread is about...

Showing the differences in writing code for Galactic Civilizations II versus Galactic Civilizations III. 

Mind you this is all well above my head and I have no clue would love to be able to get into it but, life get's in the way. 

As quoting above, time for some candy now

on Jan 15, 2015

Wait a minute. Is this " talented young developer " actually an AI??

on Jan 15, 2015

hedetet
Wait a minute. Is this " talented young developer " actually an AI??

Yes. Brad calls him J.A.R.V.I.S.

on Jan 15, 2015

I know a conspiracy when I see one. This is clearly false code purposely planted by Brad to deceive. Sometimes I hate it when I'm right. I also like candy, especially Reese's Pieces.

on Jan 16, 2015

I take this example code to tag a potential planet as a target is only one of many codes that tag a planet as a target for varying reasons and not the sole reason a planet may be tagged as such.

on Jan 18, 2015

I'm by no means a coder, but am I right in saying that means the AI doesn't take any strategic or tactical factors into account when deciding what planets to attack when? It's always just the closest enemy planet?

on Jan 18, 2015

AI development for GalCiv 3 is one of the things I'm worried most about.

I'm worried that either the AI will not be as good as GalCiv 2, or that it will not be significantly better than GalCiv2.

I'm constantly getting the impression that AI has, and is, taking a back burner within GalCiv development, or maybe that is because we get a lot less info on it from the dev blogs.

I am looking forward to being proven wrong though...

on Jan 18, 2015

Xydonus

I'm worried that either the AI will not be as good as GalCiv 2, or that it will not be significantly better than GalCiv2.

So it won't be good if it was equal to Galactic Civilizations II?  I think it would be great if it was as good or better, which I have no doubt that it will match this.  AI is slowly being brought into the game but is being worked on separately from everything else.  

on Jan 18, 2015

I heard that galactic civilizations 2 is getting a new patch. It wouldn't be that difficult all you would have to tell the ai to put priority to bigger worlds. When they include espionage, tell the ai  to spy. After spying look for worlds with wonders,even make a list where you prioritise which worlds. 

on Jan 18, 2015

Xydonus

AI development for GalCiv 3 is one of the things I'm worried most about.

I'm worried that either the AI will not be as good as GalCiv 2, or that it will not be significantly better than GalCiv2.

I'm constantly getting the impression that AI has, and is, taking a back burner within GalCiv development, or maybe that is because we get a lot less info on it from the dev blogs.

I am looking forward to being proven wrong though...

you're somewhat right the ai has been taking a back seat until the base mechanics of the game were completed. 

There was no sense programming the ai to do X if X was going to be removed from the game or completely reworked. the ai development so far has been programming how to do the basics. Now its reaching the tipping point where the game mechanics are solid enough that ai development can ramp up

on Jan 18, 2015

Seilore

I think it would be great if it was as good or better, which I have no doubt that it will match this. AI is slowly being brought into the game but is being worked on separately from everything else.

The AI continues to be the last feature to receive its final polish before release, and for good reason. If you have seen how the game has developed during this EA you will have seen how features are phased into the external builds they are shipping to us. (The same was true for GC2.) The AI is dependent on the features already included at each build, and would have to be revamped in their entirety with each build, which would be an onerous task, Waiting until all of the major features have been included to start building the "real" AI is the only practical solution to this problem. I have no doubt that the real AI that replaces the current "place holder" AI will be different in the extreme (for good or bad).

on Jan 19, 2015

I guess that means the code for the "Fountain of Youth" is not ready yet. Not that drinking data helps much to alleviate this entropy thing at any rate. Ah well. We'll just conquer the universe and hope that in space, nobody can see how old you really are!

on Jan 20, 2015

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 

3 Pages1 2 3