Author Topic: [WIP][SOURCEMOD][OXCE] Brutal-AI  (Read 20278 times)

Offline Xilmi

  • Moderator
  • Commander
  • ***
  • Posts: 642
    • View Profile
[WIP][SOURCEMOD][OXCE] Brutal-AI
« on: November 01, 2022, 05:21:16 pm »
Roughly a week or so ago I watched a video about the history of X-Com through wich I learned about OpenXcom.

After playing a little bit I got hooked enough to want to work on it's AI. And that's what I've done since then. Meridian helped me to set up a build that I could provide to others. You can download it from here.

https://github.com/Xilmi/OpenXcom/releases

It should be compatible with everything that OXCE is compatible with. So far I've only tested it with vanilla UFO. So tests with mods are also interesting in the sense of whether the AI doesn't know what to do with specific mod-features.

The new AI is enabled under Options=>Advanced=>AI=>Brutal AI

Incase you are in any kind of Ironman-mode-game you intend to have a chance on finishing, I recommend not to just switch it on mid-game.

I don't want to go into too much detail about how it is different from the regular AI and what exactly to expect so there's fewer spoilers. But I'm open to answer any questions that might arise.

My intention is to keep working on this for some time and letting any feedback influence what could be improved. Note that my main goal is to make it harder to beat.

Link last updated: 2022-12-27

New thread about this:

https://openxcom.org/forum/index.php/topic,10967.0.html
« Last Edit: December 27, 2022, 10:44:43 pm by Xilmi »

Offline Xilmi

  • Moderator
  • Commander
  • ***
  • Posts: 642
    • View Profile
Re: [WIP][SOURCEMOD][OXCE] Brutal-AI
« Reply #1 on: November 04, 2022, 01:54:36 am »
Made a little video.

It's unfortunately quite terrible quality. But it brings the point across.

https://youtu.be/rAWCGdKvdZo

Note: What's shown in the video is a newer version than the one linked here. I hope Meridian can get to building it soon.

Offline Cooper

  • Colonel
  • ****
  • Posts: 151
  • Chryssalids are awesome
    • View Profile
Re: [WIP][SOURCEMOD][OXCE] Brutal-AI
« Reply #2 on: November 04, 2022, 11:28:24 am »
Made a little video.

It's unfortunately quite terrible quality. But it brings the point across.

https://youtu.be/rAWCGdKvdZo

Note: What's shown in the video is a newer version than the one linked here. I hope Meridian can get to building it soon.

Would be interesting to see a longer mission, and in debug mode so we could se exactly what the aliens are doing.

Offline Xilmi

  • Moderator
  • Commander
  • ***
  • Posts: 642
    • View Profile
Re: [WIP][SOURCEMOD][OXCE] Brutal-AI
« Reply #3 on: November 04, 2022, 12:01:35 pm »
Would be interesting to see a longer mission, and in debug mode so we could se exactly what the aliens are doing.
Yeah, for sure, I'll be releasing more footage. I think that's better than any textual description.
One thing I noticed in a test run is that there is quite an exploitable behavior around choke-points. After I come up with a good solution I'll look into making more and better-quality videos.

Edit: New version is available: https://lxnt.wtf/oxem/builds//ExtendedTests/BrutalAI-7.8.2.1-test-36615bda7-2022-11-04-win64.7z
« Last Edit: November 04, 2022, 12:04:40 pm by Xilmi »

Offline psavola

  • Commander
  • *****
  • Posts: 839
    • View Profile
Re: [WIP][SOURCEMOD][OXCE] Brutal-AI
« Reply #4 on: November 04, 2022, 12:43:56 pm »
The only thing from the video I see that differs significantly from vanilla are grenades after mind control (or have I always avoided this by having a pre-primed smoke grenade, which the mind-controlled troops throw first). Though it is possible that lots of firing from every direction is made slightly more efficient in this case due to "information sharing" between the aliens. Obviously the example in the video is somewhat of a corner case, as no experienced player would dare to play in that manner even in the vanilla. So you would have been equally crushed with vanilla as well.

Offline Xilmi

  • Moderator
  • Commander
  • ***
  • Posts: 642
    • View Profile
Re: [WIP][SOURCEMOD][OXCE] Brutal-AI
« Reply #5 on: November 04, 2022, 01:20:50 pm »
The only thing from the video I see that differs significantly from vanilla are grenades after mind control (or have I always avoided this by having a pre-primed smoke grenade, which the mind-controlled troops throw first). Though it is possible that lots of firing from every direction is made slightly more efficient in this case due to "information sharing" between the aliens. Obviously the example in the video is somewhat of a corner case, as no experienced player would dare to play in that manner even in the vanilla. So you would have been equally crushed with vanilla as well.
Yes, the video is way too short to shows a whole lot of things.

Here's some things that happen which can't necessarily be told from the video:

1. Vanilla AI limits itself to 1 psi-attack per unit per turn. This limit was removed so the amount of psi-attacks you have to endure against sectoids are essentially doubled.
2. Aliens that are not involved in the battle head towards it's direction no matter where they are. If any of their friends already has vision on enemy units, they don't head towards the enemy-units themselves but to the closest tile from where they have a line of fire on any of my units. They also will reserve fewer or even no TUs if they are further away from their enemies.

That second part is the key difference. The aliens don't just wait until you find them. They head to where the action is. However, this currently is a bit exploitable. So goal for the next version is to avoid walking into traps and rather wait for the player to walk into theirs. I think I have a pretty good idea of how to accomplish that.

Good hint with the preprimed smoke-grenades. The code that scores the grenade-throwing needs to make sure it's actually something that can deal damage.

Offline psavola

  • Commander
  • *****
  • Posts: 839
    • View Profile
Re: [WIP][SOURCEMOD][OXCE] Brutal-AI
« Reply #6 on: November 04, 2022, 04:14:41 pm »
Here's some things that happen which can't necessarily be told from the video:

1. Vanilla AI limits itself to 1 psi-attack per unit per turn. This limit was removed so the amount of psi-attacks you have to endure against sectoids are essentially doubled.
...

The code appears to have something to this effect (_didPsi flag). But I keep wondering. I think I have seen numerous times missions where there is only one PSI-capable alien do multiple attacks during the turn (multiple "blips" on the same person, maybe even a different one). I would have even have sworn that. But maybe I am still mistaken or something else is going on (e.g., multiple signals are still actually one attack).

Quote
Good hint with the preprimed smoke-grenades. The code that scores the grenade-throwing needs to make sure it's actually something that can deal damage.

With current AI you can eliminate almost all impact of alien mind control by having a primed smoke grenade and dropping your hand-held weapons at the end of the turn (and picking them up again). The only thing you might lose is having your guy wander around (and possibly trigger proximity grenades). The game is going to be extremely brutal if AI under alien MC is made better and more realistic (e.g. throwing grenades, taking weapons out of your belt or backpack, picking up weapons), which might also be rather easy to implement. Some missions or campaigns might even become essentially impossible (with previous battlescape tactics) until you develop protections against MC.

Maybe a more realistic and brutal AI under MC could even be a separate feature with toggle on/off. I wonder if that could more easily be merged to mainstream.
« Last Edit: November 04, 2022, 04:17:51 pm by psavola »

Offline psavola

  • Commander
  • *****
  • Posts: 839
    • View Profile
Re: [WIP][SOURCEMOD][OXCE] Brutal-AI
« Reply #7 on: November 05, 2022, 07:11:18 am »
YouTube suggested the latest vid (attacking a large UFO). You could certainly see a difference there. The aliens seemed to be "sniping"  more, and rushing out of the ufo like a tsunami (in a regular game, you usually would need to wait for around turn 30 or so until every alien is out of the ufo). This is also a downside. As you could see, there might be even 4-5 aliens clustered together, easily killed with a single grenade. You may need to make the rushing out less aggressive and/or ensure that they don't stick around as easily killable clusters (like your soliders were). One criteria might be that they might prefer to move so that they could have enough TUs to end up in a covered spot and at the very least not next to other aliens.

As an improvement of your own battlescape tactics, you should always use smoke grenades if you don't have other cover and especially if you have many people in the same place (= otherwise an alien grenade magnet). The aliens can't get visibility on you while you are in a sufficiently thick smoke. So in that mission, you might have avoided almost all casualties by using a sufficient smoke cover.

Because the aliens don't have smoke grenades, they cannot protect themselves in this manner. But you should certainly try to avoid the aliens imitating the "basic" battlescape tactics where you deploy all your troops in the same place.

A very nasty alien tactic might be throwing grenades at smoke-covering areas, in the hopes that they would hit or wound someone. But this might be too brutal.

Offline Xilmi

  • Moderator
  • Commander
  • ***
  • Posts: 642
    • View Profile
Re: [WIP][SOURCEMOD][OXCE] Brutal-AI
« Reply #8 on: November 06, 2022, 04:11:04 am »
This is also a downside. As you could see, there might be even 4-5 aliens clustered together, easily killed with a single grenade.
Indeed. Due to an unnoticed error they were rushing towards my units. What they actually should have done and now do is to go towards a position from where they can shoot. However, if they all start at a similar place and there's an obstacle along the way, they might still end up quire clustered.

Ideally they'd do some sort of encirclement and then move in at the same time from as many directions as possible. I'm not quite sure yet how to realize that algorithmically. Planning their move over the whole map had the advantage of me being able to send them anywhere. Before they were limited to what they could reach within one turn. With what's reachable in one turn it's easy to make sure some spread. But with when they move bigger distances, this doesn't work like that anymore.

I need more practice with the smoke-grenades. I found them to be quite the double-edged-sword due to also imparing my own vision.

About the prepriming of smoke-grenades. The aliens always paid the price of priming the grenade too and then not even actually priming it. I made it possible for them to just prime and not throw it too. But doing this generally was very counterproductive particularly due to the alien clustering. It allowed me to kill one and that nuked a few others. So they now only do it in very specifiic scenarios. With weapon-pickup enabled and priming having no cost, this should help. Telling that their grenade is a smoke-grenade would also help with that.

But the Psied-soldier-behavior isn't the biggest priority for me. The general behavior needs to get better. Especially the clustering issue.

Offline Rangerh

  • Colonel
  • ****
  • Posts: 126
    • View Profile
Re: [WIP][SOURCEMOD][OXCE] Brutal-AI
« Reply #9 on: November 12, 2022, 01:12:30 pm »
2. Aliens that are not involved in the battle head towards it's direction no matter where they are. If any of their friends already has vision on enemy units, they don't head towards the enemy-units themselves but to the closest tile from where they have a line of fire on any of my units. They also will reserve fewer or even no TUs if they are further away from their enemies.

That sounds just completely awesome ! Thank you so much for this.
It is to me the biggest flaw of UFO and TFTD : nearly half the aliens aren't actually attacking but roughly waiting around their spawn points, killing a bit the atmosphere as it often transform the last part of the battle into a "look for the aliens that are hiding since the beginning of the battle in a corner of a building" .

In itself it can be fun and tactically interesting, but that hide&seek fun is thrown out of the window when you play long sessions of the game with completing 4 or 5 battles in a row and the repetition of the camping aliens is just becoming annoying instead of "tacticool" , so an option that forces the aliens AI to actively looking for a fight is really something interesting to me.

Is this version of OXCE compatible with mods or is it vanilla UFO only for now ?

Offline Xilmi

  • Moderator
  • Commander
  • ***
  • Posts: 642
    • View Profile

Offline Xilmi

  • Moderator
  • Commander
  • ***
  • Posts: 642
    • View Profile
Re: [WIP][SOURCEMOD][OXCE] Brutal-AI
« Reply #11 on: November 12, 2022, 02:37:39 pm »
Is this version of OXCE compatible with mods or is it vanilla UFO only for now ?
Should be compatible with all mods that OXCE is also compatible with as it's built on OXCE. However, I cannot promise the AI to act correctly in the context of all Mods.

Offline Leflair

  • Colonel
  • ****
  • Posts: 252
    • View Profile
Re: [WIP][SOURCEMOD][OXCE] Brutal-AI
« Reply #12 on: November 12, 2022, 04:48:23 pm »
How does this affect the melee AI?

Some issues I've noticed in the normal AI:
- Enemies will shy away from fire, even if they can pass safely through
- Melee enemies will stop if they are reaction fired upon, hit or no hit, or even if the attack can't really do damage.
- Very conservative in conserving TU to lower reaction fire risk, regardless of if LeeroyJenkins mode is on or not.
- Will be very caution in moving in if 2+ soldiers have LOS on them (presumably also to not draw reaction fire).

So instead of just moving in and getting their hits in, they'll waddle around back and forth or just plain stop cold well within fire range of the enemy - getting killed when it's the players turn.

I have a few units where just shutting this kinda caution off will significantly increase their lethality and danger.
« Last Edit: November 12, 2022, 04:49:56 pm by Leflair »

Offline Xilmi

  • Moderator
  • Commander
  • ***
  • Posts: 642
    • View Profile
Re: [WIP][SOURCEMOD][OXCE] Brutal-AI
« Reply #13 on: November 12, 2022, 05:06:48 pm »
I did some extra-testing for melee-units because especially the bigger ones were quite derpy. So Melee units should be well supported by Brutal-AI.

Regarding to fire: I suppose fire marks a tile as dangerous, which is something that melee-units are coded to avoid. I currently also have them avoid tiles marked as dangerous so in this case they probably also shy away from fire. I shall check that and maybe add different flags for different kinds of danger.

There is a call-back from movement to AI whenever a unit sees more enemies. So your observation is indirectly impacted by reaction-fire. The base-AI uses weight-based randomization to decide which of 4 possible kinds of actions it wants to perform. The more enemies that it sees, the more likely it is to decide to run away. When applied to melee-units this will mess with them big time. I have a completely different logic for fleeing that melee-units generally should ignore. So my AI would definitely not do that and further pursue the target it wants to attack.

Melee units generally don't conserve TUs in my AI. Others till do in the release form today. But I'm currently experimenting with ways where my Units generally don't reserve TUs unless they reached the position where they want to be at. If there goal is to camp, they will reserve everything. But if their goal is to walk somewhere else, they'll try to get there more quickly. But as I said, that's not yet in the release and still being tested for whether it's an improvement or not.

Last question is pretty much the same answer as the second question. It's not directly correlated to reaction-fire but to how many enemies they see.

I guess you need that for a mod. So I guess that for the next release I will also add the option to control whether to use brutal-AI via modding flags to specific units. (currently it's only all or nothing)

Offline Leflair

  • Colonel
  • ****
  • Posts: 252
    • View Profile
Re: [WIP][SOURCEMOD][OXCE] Brutal-AI
« Reply #14 on: November 12, 2022, 05:11:32 pm »
Specific unit flags would be quite handy, that way you can divide it between melee units, normal units and "elite units".

Another interesting way would be to have it flagged for race lists, so any unit within a race list is under say "shock attack" command and will obey brutal AI rules but otherwise not (example, press ganged cultists who are normally derpy/cowardly but in a certain list acts under better command).

One final issue I've encountered is with chryssalid type units, that will waste all their TUs on one target (I believe even if that target is zombified?). There was an attempt at a flag to allow controlling how many attacks a unit will do against a single target before moving on, but I couldn't get that to work.