[micro_ai] slow

The place to post your WML questions and answers.

Moderator: Forum Moderators

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: [micro_ai] slow

Post by mattsc »

Yes, that's what I am saying. The MAIs are set up in a prestart event, and changed in moveto events. Both the original setup and the changes persist through save/load cycles.

For the record, I know that I had tested this when I originally set up the MAIs, I just wanted to make sure that nothing got broken in the meantime. At least for the tests I did, nothing got broken.
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: [micro_ai] slow

Post by enclave »

hmm very strange, i done same tests in both local game and then multiplayer and micro_ai was working after reload in both cases..

BUT then i done more tests and discovered a case when it doesnt work for me, the micro ai worked in local game but was not working in multiplayer server after second save reload.. (i tried both 1.14.4 and 1.14.5, the problem was on 1.14.5 also)

Ok.. the bug is very complicated... I will describe my steps of testing, and put 2 reload saves here... if you have any time to have a look at them (there is a chance you wont be able to reload though, there seem to be such a problem with my add-on sometimes.. i haven't figured out the reason yet..)

This save file:
HAC 4p Continents Random Map Turn 9v.gz
(271.64 KiB) Downloaded 261 times
- the micro ai will work in local game, but will not work in multiplayer, to test it just move your red unit near green enemy unit. When micro_ai works the green enemy unit will move 1 hex back and shoot ranged. When it doesn't work it will just attack melee. The save file was saved and loaded couple of times.. I found that saving it in local game 2 times has no affect on micro_ai, but when you save in multiplayer server it may lead to micro_ai stop working.

This save file:
HAC 4p Continents Random Map Turn 9vv.gz
(272.09 KiB) Downloaded 240 times
- i loaded the 9v (save file above above) in multiplayer server, moved red unit near green enemy slinger, saved the game. Now reloading it in local game or in multiplayer server, both micro_ai don't work. Slinger attacks melee in both cases.

Ah ok.. now i managed to simplify it.. This save file:
HAC 4p Continents Random Map Turn 9vvvv.gz
(226.22 KiB) Downloaded 230 times
Was saved in multiplayer server.
1) When you reload it in local game then it works fine, the enemy slinger goes back and shoots ranged (all micro_ai work fine).
HAC 4p Continents Random Map replay-yes.gz
(111.7 KiB) Downloaded 258 times
2) When you reload it in multiplayer server then micro_ai doesnt work anymore (not on default, neither experimental ai, doesnt matter).
HAC 4p Continents Random Map replay-no.gz
(111.75 KiB) Downloaded 253 times
I attached replays for each reload just in case if you can't reload my save files for some reason.

Now it was just to prove im not crazy...

i know i might be asking for a lot, but could you test your script the same way I did?... try to run your quick test on multiplayer server too (not just offline in local game), if you could tell me the result... because I don't have any micro_ai script ready to test on default era... and my half civ add-on may have it's own bugs that lead to that strange micro_ai behavior.. if you have time. otherwise i need to create some micro ai addon to test it some day on default era.

Thank you very much in advance, no matter if you have time for it or not.. still much appreciated.
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: [micro_ai] slow

Post by mattsc »

Hey - just writing quickly to say that I saw the post and am not ignoring it, but RL is such that I don't have time for my FL at all at the moment. Might be a couple weeks before I get back to Wesnoth.
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: [micro_ai] slow

Post by enclave »

yeah no problem at all, thanks for letting me know, I might run that default era test before you come back ;) I'll keep updated if new information comes up.
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: [micro_ai] slow

Post by mattsc »

I had a first look into this. I can replicate the problem even in a local game using your vvvv save. It's very "interesting". Looking into the AI configuration using the in-game inspector, it turns out that there are two AI stages (a stage is, more or less, an entire self-contained AI). The first one contains only the default AI. The second contains the default AI plus all your Micro AIs. Since the stages are played through in the order in which they appear in the config, the engine never gets to the MAIs (or more precisely, by the time it gets to them none of the AI units have moves left).

Anyway, what this means is:
  1. There is nothing wrong with the Micro AIs per se.
  2. For some reason, the engine adds a second stage containing only the default AI in front of the already existing AI with the MAIs. I don't know at this time what's the cause of this. The save already contains two separate AI configurations, so it does not seem that the problem originates at loading time.
Well, that's how far I got. Good news is it's not a problem with the Micro AIs. Bad news: it happens somewhere in the MP setup/save/load process and might be hard to track down. I'll see if I can somehow recreate this with a simpler test case and then trouble shoot it, but that might take some time.
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: [micro_ai] slow

Post by enclave »

Thank you very much mattsc, i'm very short on time too, still havent tried a default era test with save-loading.. sorry..

could something like [modify_side] have affect on added the default AI on top of already existing one? I will browse my codes when i get time and see all cases when im messing with ai.. will try to list them here.. maybe it could help. But i dont know when i get time for it either.. Thank you very much for your time!
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: [micro_ai] slow

Post by mattsc »

Minor progress update: I can reproduce the issue by simply starting an MP game (local or on the server), using any of the default AIs for a side, saving it, and then re-loading from the MP Create Game screen (again, both local and server). After loading, there is an extra stage for the AI sides. This stage is not there right after creating the game, or when loading from the title screen. The stage is duplicated for all AI sides created in the game setup, but not for player controlled sides or automatically inserted AI sides such as the enemies on the A New Land map.

So while I do not know why this is happening, I now have an easy way to recreate the issue and know which step causes it. I'd guess that it happens when/after going through the Game Lobby screen after loading an MP game while in MP mode.

Edit: I also confirmed that the stage duplication is not present in the saved game yet, so it definitely happens at loading/setup time.
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: [micro_ai] slow

Post by mattsc »

This is now fixed in both 1.14 and master by adding a new option "Keep saved AI" for computer players when reloading a game from the MP Create Game screen. If nothing is selected, this is the default option, which means the game continues with the AI from the save.
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: [micro_ai] slow

Post by enclave »

mattsc wrote: December 23rd, 2018, 9:32 pm This is now fixed in both 1.14 and master by adding a new option "Keep saved AI" for computer players when reloading a game from the MP Create Game screen. If nothing is selected, this is the default option, which means the game continues with the AI from the save.
Thank you very much mattsc! Im so sorry that I didn't even have time to reply to your previous post.. Happy Christmas!
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: [micro_ai] slow

Post by enclave »

mattsc, a naive question.. is there any micro_ai for a human controlled side? like kind of what you see in games under "goto"... like you specify unit a goal on map and he would perform the goto action to that goal each turn (while side is controlled with human player, not AI)

I just think to add caravans to my game which would NOT be controllable by player, while they would belong to player.. kind of silly units that act on behalf of human player... and if they reach the end of trade route they would provide owner with gold.. basically they would act same as micro ai goto.. avoid enemies in range.. your micro_ai would be just ideal for that purpose..

do you have by any chance any advice on how I could use your micro_ai for a human controller controlled side?

would be silly for me to build a new micro ai for that.. since u already created one.. but if it's very complicated from your point of view then don't waste your time explaining it in huge details, I really dont want to waste your time. Just tell me if its very hard or not, and IF not then I would be happy to hear howto... no rush with reply, I will not have time to implement it in nearest time anyway.. just preparing myself for the future updates..

my basic idea for alternative human controlled micro ai/goto would be quite simple... but it's huge work.. which would only be good if there is no alternative.. so I hope your micro_ai could be used for goto somehow :D
Spoiler:
I think that is basically it, as you can see it is very silly way of doing it... long and hard work... your micro_ai would be much much better.. but can it be adopted for human player side anyhow?

PS.
Spoiler:
User avatar
The_Gnat
Posts: 2215
Joined: October 10th, 2016, 3:06 am
Contact:

Re: [micro_ai] slow

Post by The_Gnat »

enclave wrote: January 4th, 2019, 1:10 am do you have by any chance any advice on how I could use your micro_ai for a human controller controlled side?
Would it be easier just to create another side that is on the same team as you and is controlled by the ai? Or are you planning on using all 9 sides?

I am of course not at all an expert at ai so I might just be being dumb :whistle:
User avatar
Celtic_Minstrel
Developer
Posts: 2158
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: [micro_ai] slow

Post by Celtic_Minstrel »

I think for your specific case it would make more sense to place the caravans on a separate allied AI-controlled side. I'm pretty sure no AI is run for a human player - the goto implementation for human players is probably handled separately from the AI implementation.

(There is no limit of 9 sides in the engine. There might be a limit of 9 human-controlled sides in an MP scenario, and I think there are only 9 selectable team colours, but you can have as many additional sides as you like.)
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: [micro_ai] slow

Post by mattsc »

My advice would also be to use a separate side. AI candidate actions are not executed at all for a human controlled side, so the only way to make something like that work would be in some sort of semi-hacky way. You could set up an event that changes the controller to AI at the end of the previous side's turn and then to human as soon as all caravans (etc.) have moved. Or do the same at the end of the move once all other player's units have no moves left. But just using a separate side would be much easier for the same effect (and you could use the same color and make the side hidden, so that it kind of looks like it is the player's side).

Now, you could set goto_x,goto_y for a unit at the beginning of the player's turn. That has the same effect as if you set a unit to move to a location more than one move away (using the cursor). The remaining moves automatically get executed at the beginning of the turn. But the player can always undo that and/or change where the unit is going by clicking on it and changing it's destination, so it would not really server your purpose.

So ... in summary, I agree with The_Gnat and Celtic_Minstrel that I'd use another side. However, if it must be the same side, then it's possible to do it more simply in WML than what you have in your first spoiler tag, by using tags like [find_path].

Let me know if the above contains the information you need, maybe I misunderstood you.

As for your second spoiler tag (barbarian side), let's talk about that again when you get to it.

Oh, and please
Spoiler:
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: [micro_ai] slow

Post by enclave »

The_Gnat wrote: January 4th, 2019, 1:47 am Would it be easier just to create another side that is on the same team as you and is controlled by the ai? Or are you planning on using all 9 sides?
Celtic_Minstrel wrote: January 4th, 2019, 1:51 am I think for your specific case it would make more sense to place the caravans on a separate allied AI-controlled side. I'm pretty sure no AI is run for a human player - the goto implementation for human players is probably handled separately from the AI implementation.
(There is no limit of 9 sides in the engine. There might be a limit of 9 human-controlled sides in an MP scenario, and I think there are only 9 selectable team colours, but you can have as many additional sides as you like.)
Yeah it would be easier, but it would require random maps to have specified sides (since random are mainly played with my add-on) , 4 players ffa would be 8 player map, the caravan side for each team, it would probably be completely messed up if a host would change random map settings for more players in random map settings and regenerate it.. not sure if it would be possible at all with 5 players (caravan side for each team), since random maps limited to 9 players to the best of my knowledge, and to start each caravan team would require king (which could be deleted on turn 1)..
extra side for each side would probably be overall a very messy solution... (specially the fact that currently my add-on could be played on ANY map.. but with separate caravan side it would no longer be the case)

I remember I was told that it is impossible to add more sides on the go... if you start with 2 sides, you can't just place unit for side 3.. they would never get controller kind of.. (if its not true then extra side for each side would be a good idea). Adding sides on the go could be good for many things for add-on makers.. but doesn't seem possible currently.
mattsc wrote: January 4th, 2019, 4:50 am You could set up an event that changes the controller to AI at the end of the previous side's turn and then to human as soon as all caravans (etc.) have moved. Or do the same at the end of the move once all other player's units have no moves left.
Yay, that sounds like a nice idea to test it.. (from my experience although the computer will only start controlling the side after u end turn, so there is a chance that it won't work, at least in the end of turn is more unlikely... but im very positive to try test it) the start of turn is very promissing.. if only controller can start working immediately then it will work.. otherwise it wont.. thanks for idea!
User avatar
Celtic_Minstrel
Developer
Posts: 2158
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: [micro_ai] slow

Post by Celtic_Minstrel »

Well... if you're making your own random maps (rather than using maps made by other people), you could totally do it using Lua scenario generation, which could automatically generate twice as many sides as the map settings called for.

If you're trying to make it work with other people's maps though, you'll probably need to use some sort of event-based solution, like a turn start event that moves the caravans for that side.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
Post Reply