Page 1 of 2

Proposed Change to Flee AI

Posted: Sun Jul 15, 2018 7:17 pm
by another_commander
Following up on the discussion in this topic, I have made some tests with a slightly modified flee AI and I was quite happy with the result. I therefore submit this change for your further testing and consideration.

The change applies to ships with accuracy greater than 0. Dumb ships will continue to act dumb and flee in straight lines, but more often than not, you will be encountering pilots who will react more like a normal pilot would. "Clever" NPC pilots now check your position against theirs when fleeing and, if they feel that they are sitting in your sights, they will attempt to react. Most of the times they will try to jink more in order to get out of the way of your guns, but sometimes, in an act of desperation, they will turn and try to land a few hits on their attacker, hoping to surprise them. Current probability is 65% continue fleeing, 35% go evasive and consider an attack and they are open to suggestions.

The change required to test this:
Function performFlee in ShipEntityAI.m is changed to:

Code: Select all

- (void) performFlee
{
	if (behaviour != BEHAVIOUR_FLEE_EVASIVE_ACTION)
	{
		behaviour = BEHAVIOUR_FLEE_TARGET;
		[self setEvasiveJink:400.0];
		frustration = 0.0;
		if (accuracy > COMBAT_AI_ISNT_AWFUL)
		{
			double aspect = [self approachAspectToPrimaryTarget];
			// alert! they've got us in their sights! react!!
			if (aspect > 0.9995 || aspect < -0.999)
			{
				behaviour = randf() < 0.35 ? BEHAVIOUR_EVASIVE_ACTION : BEHAVIOUR_FLEE_EVASIVE_ACTION;
			}
		}
	}
}
Test binary for Windows x64 here.

Re: Proposed Change to Flee AI

Posted: Sun Jul 15, 2018 8:11 pm
by gsagostinho
I will test this later tonight and report back. Thank you so much for taking a look at this!

Re: Proposed Change to Flee AI

Posted: Sun Jul 15, 2018 8:17 pm
by another_commander
Thanks, looking forward to seeing the results. For completeness, there is one more small change that has been made in order to generate the test executable and I forgot to mention earlier. In the method setEvasiveJink in ShipEntity.m, the line that reads

Code: Select all

if (accuracy >= COMBAT_AI_IS_SMART)
has been commented out. Now all non-dumb ships do proper jinking manoeuvers.

Re: Proposed Change to Flee AI

Posted: Sun Jul 15, 2018 8:21 pm
by gsagostinho
Out of curiosity, what is the distribution of dumb ships in the game? How is accuracy set for the default NPCs? Is that dependent on the type of system?

Re: Proposed Change to Flee AI

Posted: Sun Jul 15, 2018 9:42 pm
by gsagostinho
Hmm, I just realized now that these modifications are for the source code and not for any game files post-compilation, right? I am quite unfamiliar with Oolite compilation and this might take me a while to figure out. Sorry about that!

Re: Proposed Change to Flee AI

Posted: Sun Jul 15, 2018 9:47 pm
by Cody
Simply drop the .exe into your (Windows x64) Oolite build, and run it (probably requires Oolite trunk).

Re: Proposed Change to Flee AI

Posted: Sun Jul 15, 2018 11:06 pm
by gsagostinho
Hadn't realized there was a link to a compiled exe file. Thanks Cody!

Re: Proposed Change to Flee AI

Posted: Mon Jul 16, 2018 5:55 am
by phkb
I'm looking forward to trying this out this afternoon! Thanks, a_c!

Re: Proposed Change to Flee AI

Posted: Mon Jul 16, 2018 12:27 pm
by another_commander
gsagostinho wrote: Sun Jul 15, 2018 8:21 pm
Out of curiosity, what is the distribution of dumb ships in the game? How is accuracy set for the default NPCs? Is that dependent on the type of system?
Hard question. Each ship type has its accuracy set by different parameters. Some (like pirates) depend on system governments and some others have their accuracies set based on generic expectations (like trader opportunitsts and hunters belonging in a pack expected to generally be good pilots). There is plenty of randomness involved too.

Check oolite-populator.js in the core scripts folder for occurrences of the _setSkill(ship, bias) method. That's where the magic happens.

Re: Proposed Change to Flee AI

Posted: Mon Jul 16, 2018 12:37 pm
by another_commander
Oh, and btw, core ships' AI does not go beyond 5.0. If you want higher level AIs, you need to OXP it.

Re: Proposed Change to Flee AI

Posted: Mon Jul 16, 2018 12:43 pm
by gsagostinho
Thanks for all the info. I still did not have the chance to test that executable but I will do so tonight.

Re: Proposed Change to Flee AI

Posted: Mon Jul 16, 2018 5:35 pm
by Redspear
another_commander wrote:
Most of the times they will try to jink more in order to get out of the way of your guns, but sometimes, in an act of desperation, they will turn and try to land a few hits on their attacker, hoping to surprise them. Current probability is 65% continue fleeing, 35% go evasive and consider an attack and they are open to suggestions.
Nice idea but IMHO 35% seems a tad high for a potentially suicidal 'act of desperation'.
Realistically 10% might even be too high but if one assumes that such behaviour might make combat more interesting then it should perhaps happen once in a while rather than once in a blue moon.

Re: Proposed Change to Flee AI

Posted: Mon Jul 16, 2018 8:48 pm
by another_commander
Redspear wrote: Mon Jul 16, 2018 5:35 pm
Nice idea but IMHO 35% seems a tad high for a potentially suicidal 'act of desperation'.
Realistically 10% might even be too high but if one assumes that such behaviour might make combat more interesting then it should perhaps happen once in a while rather than once in a blue moon.
Remember that the 65-35 percentages are not based on the total of ships you encounter, but on the ships that will be directed to use the bits of the new AI. Some ships still fly straight when fleeing and from those that don't, 35% may chose to break the run and attack. In reality you should be seeing desperation attacks less often than what it initially looks like.

But let's be sure first that the AI works, then I would be more than happy to drop the flee attacks a little.

Re: Proposed Change to Flee AI

Posted: Tue Jul 17, 2018 1:20 am
by gsagostinho
@another_commander The behaviour of the AI seems better from what I can tell but I did have some crashes using this executable together with the latest nightly. @phkb did you have more success testing this?

Re: Proposed Change to Flee AI

Posted: Tue Jul 17, 2018 2:53 am
by phkb
I had a couple of long play sessions, where I noted all the different behaviours in action. I didn’t see a lot of the “fly in a straight line” escape option, but I was possibly in a slightly biased environment (mission testing with particular ship roles), so that might not be important. I found I regularly had to break off shooting at a fleeing ship because they were juking under injectors to throw off my aim, and I was getting hammered by other ships who were lining up behind me. In all I found the experience much more satisfying. So, first impressions are positive. I’ll have another go this afternoon and report back again.

I didn’t have any crashes I could link to this change, but then I built my own exe rather than use a_c’s download.