aliens

Author Topic: How to code the AI  (Read 26328 times)

Offline darkestaxe

  • Colonel
  • ****
  • Posts: 254
  • Emissary of the Brain
    • View Profile
Re: How to code the AI
« Reply #30 on: September 15, 2013, 08:43:54 pm »
Here's a thought, suppose we have a three option setting: Original, Realistic, and RealSmart. When Warboy or whoever finds a part of the code like the examples he gave then that part can be coded up to three ways. RealSmart would fall through to Realistic when a RealSmart version isn't present. The idea is to have a consistent system for distinguishing between the three attitudes toward AI when the AI programmer wants to without having to code/update/maintain 3 separate AIs for everything.

Original: Mimic original behavior as accurately as possible, down to wandering chrysilids and omniscient aliens.

Realistic: Original-like non cheating choices in which aliens make decisions that make sense and are based on what they can know.

RealSmart: Ignore the original and make the AI as smart, deadly, and unpredictable as possible without cheating or otherwise being unrealistic.

Example with chrissalid:
Code: [Select]
IF (AI=STR_ORIG) {
   https://wander aimlessly
}
ELSE {
   https://approach visible soldiers directly without thinking
}

https://with smart AI code added
IF (AI=STR_ORIG) {
   https://wander aimlessly
}
IF (AI=STR_SMART) {
    https://plan optimal number of zombies without taking too much reaction fire and still
    https://being able to retreat to cover, or hide and wait for better opportunity.
}
ELSE {
   https://approach visible soldiers directly without thinking
}

Offline djemon_lda

  • Captain
  • ***
  • Posts: 52
    • View Profile
Re: How to code the AI
« Reply #31 on: October 13, 2013, 04:54:01 pm »
you are going to suffer deadly in all those "if-else/switches" just begging for someone to show you mercy and kill you.
make the core AI actions polimorphic and be produced by an abstract factory configured by your options with concreete factories for example:
Code: [Select]
IAIFactory
{
virtual IAIBehaviour* Make(UnitCreationData creationData) = 0;
};
or
Code: [Select]
IAIFactory
{
virtual IAIBehaviour* MakeSectiod() = 0;
.
.
.
virtual IAIBehaviour* MakeCivilian() = 0;
};
whatever suits you best, but I personally would chose the first version, and then make an implementation for each of the AI type like:

Code: [Select]
class VanillaAIFactory : public IAIFactory{ ... };
class RealisticAIFactory : public IAIFactory { ... };
class RealSmartAIFactory : public IAIFactory { ... };

That way you can write a lot of code, that won't have to be changed when you add new AI modes, or will wish to do stuff like sharing some AI behaviour, or distinguishing. You will be able to, at any point, say "hey, I want all sectoids to do ABC, but their commanders are going to act absolutely different, but only for Smart AI!", and the only thing you need to change in that scenario is:
a) make an SectoidCommanderSmartBehaviour class describing it's behaviour
b) change the RealSmartIAFactory to support the new guy - here is why I prefered the first factory, because giving it the creation data makes it THAT much more stabile code, and the interface would basically never change