aliens

Author Topic: Autoplay  (Read 3038 times)

Offline GumChewer

  • Sergeant
  • **
  • Posts: 45
    • View Profile
Autoplay
« on: January 16, 2024, 07:41:34 pm »
I would just not enable it by default and this way the details about the implementation are not that important.
Also: Someone made a very, very related feature-request on discord:

Since those do not appear in the soldier's menu, I guess I'll just add it as a separate option. But other than that the framework is already there.

Sorry for necro-posting, but, I opened a pull request that added three default options.
One for geoscape soldiers (only evaluated at time of creation).
One for player units without a battlescape soldier (HWP and probably spawned units).
One for everything else (enemies and civilians under mind control and maybe something I do not know of).

I tested the code extensively on BrutalAI 7.9 and a little on the latest version.

As a quick reminder it was about fine-controlling which units of the player are controlled by the AI if autocombat is enabled.
« Last Edit: January 16, 2024, 08:56:34 pm by Xilmi »

Offline Xilmi

  • Moderator
  • Commander
  • ***
  • Posts: 642
    • View Profile
Re: Autoplay
« Reply #1 on: January 16, 2024, 09:05:34 pm »
Thanks!

I split your post to discuss something related to this feature.
It would be cool to customize the auto-play a bit in this "c"-menu.

I removed the aggression-settings from the options for auto-play a while ago. For benchmark-testing I don't really use them much and it's also very clunky to go to the advanced options to change something.

But for people who want to use the auto-play a bit more seriously and would go as far as to turn it on and off for indvidual units, they'd probably also like to set the "playstyle" on an indvidual-unit-level.

What do you think about this? If you'd do the UI work, I could integrate it with the AI.

Offline GumChewer

  • Sergeant
  • **
  • Posts: 45
    • View Profile
Re: Autoplay
« Reply #2 on: January 17, 2024, 03:42:41 pm »
Good idea!

I made a new pull request. First commit is just renaming etc.
Second one modifies battleunit::_agression. Is that right?
Changing aggression works via right-click. Just as before, toggling the AI control is done via a left-click.

You need to fill the constants (marked by TODO and compiler errors) or there should be an option for it.
The TODOs regarding the look of the window can be ignored for now.

I did some testing, it should work. But probably I'm not available due to Real Life.

Things I have not approached:

Due to mind-control, you might want/need to distinguish the case if the unit is not controlled by the original faction?

Also, maybe the interplay with the inheriting from the ruleset, I think that is the AgressionMode option?

Also, maybe renaming the class? Like "AIUnitControlState"?

Offline Xilmi

  • Moderator
  • Commander
  • ***
  • Posts: 642
    • View Profile
Re: Autoplay
« Reply #3 on: January 18, 2024, 11:53:25 pm »
It is implemented in the new 8.2.0-version.

One small thing though:

In the "c"-menu during the Battlescape it also shows units that have already died. Could you make it so they no longer appear in the list? Could use the BattleUnit::isOut()-function for that.

Offline GumChewer

  • Sergeant
  • **
  • Posts: 45
    • View Profile
Re: Autoplay
« Reply #4 on: January 29, 2024, 08:31:37 pm »
In the "c"-menu during the Battlescape it also shows units that have already died. Could you make it so they no longer appear in the list? Could use the BattleUnit::isOut()-function for that.
A little late, you already merged the request, but
so much for my extensive testing.
Also thanks for the credits in the releases of github!

Offline 0xEBJC

  • Colonel
  • ****
  • Posts: 180
  • Y'all are awesome! Thankful for this community.
    • View Profile
    • My Projects
Re: Autoplay
« Reply #5 on: March 23, 2024, 04:23:41 pm »
Posting here, because this thread seams most relevant to any discussion, request, or issue related to auto-play.

High Important Requests:

Fix auto-play hanging with user unable to disable auto-play or interact with menu when CPU 100%
I understand that auto-play will likely spike cpu or single processor/thread to 100%, but currently it's almost impossible to 'escape' to the menu or more importantly hit the keyboard keys at the right time to disable auto-play.

Recommendation: add the following features for when auto play is running:
1.) Really Important - pole the keyboard for input (meaning that even when CPU is maxed, at any time entering keys are priority) this can be done by checking for keyboard input at every loop of the auto-play logic, but also caching the keyboard input during one iteration of the auto-play logic.  The Problem I'm having for example is: during auto-play with CPU at 100% I can repeatedly hit escape and get to the menu sometimes, but hitting the keyboard shortcut to enable/disable auto-play just hangs and is almost impossible to disable auto-play.

2.) Have auto-play track player unit movement... or make this an optional setting.  So when the player units running on auto-play move out of the screen the screen shifts to a new location to follow the unit, or have it smoothly move the map as the player unit moves?


Lower Priority:
3.) GUI logic should take priority over the auto-play logic even when it's maxing out the CPU.  For example the user should be able to move the cursor around without the screen locking or lagging?  (I'm not sure how easily this could be implemented, this is more of a QoL, but not as necessary as the keyboard poling for disabling auto-play)

4.) Keyboard shortcut to rotate settings for all player soldiers to 'individually managed' for auto-play or 'all' soldiers auto-play.
Example: sometimes you want only a few specific soldiers that have been set to auto-play.  scenario: I have soldiers 1,2,3,4,5.  I set soldiers 1,5 as individual auto-play. hitting a specific key enables all soldiers for non-individual auto-play, and hitting that key again reverts it back to only soldiers 1,5 to run as individual auto-play when auto-play is re-enabled.


« Last Edit: March 23, 2024, 08:39:20 pm by 0xEBJC »

Offline 0xEBJC

  • Colonel
  • ****
  • Posts: 180
  • Y'all are awesome! Thankful for this community.
    • View Profile
    • My Projects
Re: Autoplay
« Reply #6 on: March 23, 2024, 04:29:47 pm »
Another suggestion would be to add the 'Game Options' menu into the available buttons when in auto-play'  then I could go into there and disable auto-play.

currently when auto-play is running and I hit escape, I get the following see attached image, there is no 'Game Options' button, so I can go into the settings and disable auto-play.

Offline Xilmi

  • Moderator
  • Commander
  • ***
  • Posts: 642
    • View Profile
Re: Autoplay
« Reply #7 on: March 23, 2024, 08:54:58 pm »
The key-press is registered. But since there is no feedback and the current unit will still fulfill it's command, it's hard to tell if it worked. I'll add a pop-up so you can see whether you just turned it on or off.

Offline 0xEBJC

  • Colonel
  • ****
  • Posts: 180
  • Y'all are awesome! Thankful for this community.
    • View Profile
    • My Projects
Re: Autoplay
« Reply #8 on: March 27, 2024, 05:48:46 pm »
I'm testing the player AI and having a sort of issues when using only a single soldier in the battlescape.

Not sure if anyone else is seeing this, and if this is just my settings that need to be adjusted or if this is an overall AI issue.

Settings:
   BRUTAL AI:                                            no
   BRUTAL AI for neutral forces:                  yes
   Allow AI to use explosives on turn one:    yes
   BUG HUNT mode for BRUTAL AI:              no
   Allow BRUTAL AI to pre-prime grenades:  yes
   Spread out:                                           yes
   Performance optimizations:                     yes
   Targeting behavior for BRUTAL AI:           2
   Aggressiveness-mode:                            1
   Intelligence-mode:                                 1
   
Scenario:
 - I have a very strong soldier upgraded to Kyber, and having the synthsuit, so I think this is a very stong soldier.
 - In auto play, usually where the map is fairly complex either in caves, or map with lots of buildings the soldier stops exploring.
 - The solder finds a hiding place, or usually goes to the center of the map, and then just spins around looking then ends turn
 - This repeats every turn.


What setting should I adjust for the solder to explore more?  I'm going to try out different settings, but just asking if anyone has seen this? known issues? or just my settings need adjusted?


[Suggestions]:
AI Logic that I think should happen:
1.) Determine if solder stats are low or very strong?
2.) If one soldier left and stats low, maybe hide more
3.) If solder stats strong and high TUs, then explore more
4.) At some point the soldier should explore instead of just camping
5.) If the environment affects moral, then soldier should explore more knowing that waiting just depletes moral
6.) Maybe AI should prompt player if AI auto-play should continue or give back control to player if AI performs only camping for x number of turns
7.) x number of turns could be a setting in the advanced options or just hard coded like 3 turns?

Thanks!



Offline 0xEBJC

  • Colonel
  • ****
  • Posts: 180
  • Y'all are awesome! Thankful for this community.
    • View Profile
    • My Projects
Re: Autoplay
« Reply #9 on: March 27, 2024, 07:53:48 pm »
The key-press is registered. But since there is no feedback and the current unit will still fulfill it's command, it's hard to tell if it worked. I'll add a pop-up so you can see whether you just turned it on or off.

So I've tested this a bunch and from what I am experiencing is that no matter how frequent I press the toggle key for auto-play the game will not register or exit auto-play even through multiple turns.  A single cpu thread is maxed to 100%.  The only time I can manage to disable auto-play is when the AI's turn and there is the little red progress bar at the top right of the turn screen.  Then and only then if I hit the toggle key to disable auto-play before the progress bar disappears, does it exit at my next turn.  I'm guessing that other than then, the CPU max is to great to even register the keys as also the mouse is frozen and if I click on the screen some times the game window turn grayed out and I get a windows thinking cursor with the little blue spinning circle loop.

It might be more helpful to have an exit auto-play mode keyboard shortcut, so spamming it won't toggle between on and off auto-play.
« Last Edit: March 27, 2024, 09:22:07 pm by 0xEBJC »

Offline Xilmi

  • Moderator
  • Commander
  • ***
  • Posts: 642
    • View Profile
Re: Autoplay
« Reply #10 on: March 28, 2024, 01:46:56 pm »
- In auto play, usually where the map is fairly complex either in caves, or map with lots of buildings the soldier stops exploring.
 - The solder finds a hiding place, or usually goes to the center of the map, and then just spins around looking then ends turn
 - This repeats every turn.

What setting should I adjust for the solder to explore more?  I'm going to try out different settings, but just asking if anyone has seen this? known issues? or just my settings need adjusted?
This is likely an issue with the soldiers's default-aggression.
Note that your soldiers don't use the aggression-settings for the enemy-AI but have their own.
You can bring up the menu for that during battle by pressing the "c"-key (c is default, can be changed in settings).
In that menu where you can also toggle whether AI is enabled or not for that soldier there's a 2nd column for the aggression-value. This value is changed by right-clicking on the selected line.

You will want to change that to 3 in order to force the soldier to keep searching for enemies instead of camping.

This value is saved to the geoscape-soldier object and will be memorized for that soldier. It can also be taggled from the base in the soldiers menu which has an additional sub-menu to be selected in the bottom left.

Offline Xilmi

  • Moderator
  • Commander
  • ***
  • Posts: 642
    • View Profile
Re: Autoplay
« Reply #11 on: March 28, 2024, 01:55:48 pm »
So I've tested this a bunch and from what I am experiencing is that no matter how frequent I press the toggle key for auto-play the game will not register or exit auto-play even through multiple turns.  A single cpu thread is maxed to 100%.  The only time I can manage to disable auto-play is when the AI's turn and there is the little red progress bar at the top right of the turn screen.  Then and only then if I hit the toggle key to disable auto-play before the progress bar disappears, does it exit at my next turn.  I'm guessing that other than then, the CPU max is to great to even register the keys as also the mouse is frozen and if I click on the screen some times the game window turn grayed out and I get a windows thinking cursor with the little blue spinning circle loop.

It might be more helpful to have an exit auto-play mode keyboard shortcut, so spamming it won't toggle between on and off auto-play.
I can't reproduce this kind of behavior. With the new confirmation-window I recently introduced on whether I toggle auto-play on or off, I get immediate feedback when and that it is turned off.
I have basically zero delay when doing so.

You neither mentioned the popup of the confirmation window nor that you have updated to the latest version. So I feel like I have to explicitly ask you whether you have done so.

I know it was hard to tell whether the button-press was registered before. Especially if the player-turns were really short. But with that confirmation-window it is extremely obvious and you even have to click the pop-up away (or wait a few seconds so it goes away by itself).

Offline 0xEBJC

  • Colonel
  • ****
  • Posts: 180
  • Y'all are awesome! Thankful for this community.
    • View Profile
    • My Projects
Re: Autoplay
« Reply #12 on: March 29, 2024, 05:39:30 pm »
You can bring up the menu for that during battle by pressing the "c"-key (c is default, can be changed in settings).
In that menu where you can also toggle whether AI is enabled or not for that soldier there's a 2nd column for the aggression-value. This value is changed by right-clicking on the selected line.

You will want to change that to 3 in order to force the soldier to keep searching for enemies instead of camping.

This value is saved to the geoscape-soldier object and will be memorized for that soldier. It can also be taggled from the base in the soldiers menu which has an additional sub-menu to be selected in the bottom left.

Thanks! I changed the value to 3, and I appreciate the help, I don't think I would have ever figured out that 'right-click' would change the aggression level

I can't reproduce this kind of behavior. With the new confirmation-window I recently introduced on whether I toggle auto-play on or off, I get immediate feedback when and that it is turned off.
I have basically zero delay when doing so.

The auto-play pop-up screen is 'very' helpful and 'way' better, thank you!  I can now spam the toggle for autoplay until I get the disable autoplay pop-up.

- A lot of time the game interaction and pop-up is immediate.
- The problem I'm having is when there is a complex map
  -- If the players see enemies when entering autoplay the AI seams to not lug down the CPU too much
  -- When there are no enemies seen and it a complex map (Buildings, caves, etc.), then when entering autoplay (a single CPU core spikes to 100%, the game is single core threaded) and the application becomes unresponsive, I can no longer move the mouse, interact with the game.... the AI is still working, but the application is so ramped up the OS can't interact with the game application and that's why it's not receiving a keyboard input.
  -- When this is happening (100% CPU on a single thread) the only time the CPU has a slight drop is when the enemy progress bar shows progress across the top right. That's when I can get it to receive the 'disable autoplay' command with   -- Also, this is happening with a single soldier, so there are no transitions to another soldier.  I haven't tried it with multiple soldiers, I'll test that.


The pop-up message is much better, I can spam the toggle and sometimes get it to disable autoplay during the players turn. Thank you!



Here's my hardware: ( I'm sure it's not a hardware problem)
i7-8750H CPU 12x Core (Mobile Workstation - Laptop CPU)
64 GB RAM
NVMe drive
Winwdows 10



« Last Edit: March 29, 2024, 05:53:10 pm by 0xEBJC »

Offline Xilmi

  • Moderator
  • Commander
  • ***
  • Posts: 642
    • View Profile
Re: Autoplay
« Reply #13 on: March 30, 2024, 05:25:04 pm »
It's still weird that you have to spam it. For me it just works every time without fail. But I haven't really tested mods with much more complex scenarios and how it impacts things.

I suppose you use the version I uploaded and not a self-compiled one?

It sounds like something on your end swallows the key-stroke-events under heavy load.

Offline 0xEBJC

  • Colonel
  • ****
  • Posts: 180
  • Y'all are awesome! Thankful for this community.
    • View Profile
    • My Projects
Re: Autoplay
« Reply #14 on: March 30, 2024, 10:20:13 pm »
I am using the binary from your github releases

yes, if only under heavy load when the one CPU core running the game is spiked to 100% and I can't even click or move the mouse.

scenario is...
- With X-Com Files (complex map)
- Start auto-play
- After a few turns player is somewhere just spinning, looking for enemies, ends turn, repeats these actions and continues to end turns
- CPU core running game is 100%
- Only time there is a brief register of keystrokes is when top right red/green progress bar during enemy turn.

I've had this happen even on aggressive mode 3... in this case it's when the soldier(s) have stunned or killed all but one or two enemies and can't find the last of them.. like a ghost at knight with very poor visibility.


Spamming the keys I can trigger the auto-play off sometime during high CPU and know that I've turned it off.

I'll continue to due more testing, but it work good enough, the auto-play message is very helpful... thank you.