Latest Posts

Topic: Ability to use replay instructions for AI

Wide_knight
Avatar
Topic Opener
Joined: 2024-10-04, 13:09
Posts: 3
Ranking
Just found this site
Posted at: 2024-10-04, 14:26

Hey,

TL;DR: ability to run bot on saved instructions until „conditions“ are met.

If I understand replays correctly, they are saved as „initial world state“ and „player instructions“ to essentially make the game engine re-play the game. The AI is just an „instruction generator“, so in my mind it should be possible to give it a replay instructions file and make it output those instead until some condition is met, the most obvious being „last instruction in list“ followed by „invalid instruction“ (e.g. using instructions on a different initial world state) and then „enemy detected“ as that breaks isolation.

Use case: playing against „yourself“/ benchmarking yourself/overcoming AI shortcomings by copying a player instead

I want to play a map and crush the AI, then switch positions and let the AI use my own buildup instructions to then overcome from the other side and so on.

In my opinion that would make single player quite fun for the following reasons:

  • enemy is exactly at your level of skill (until met)
  • using starting conditions that AI struggles with, e.g. crowded starting spot with few building spots
  • AI is as map-aware as you and will actively work on blockers between it and the player e.g. rocks.
  • can be used as challenges, e.g. use some tournament replay file for a „beat the champ“ (maybe needs tweaking with the AI takeover conditions)

Top Quote
OIPUN
Avatar
Joined: 2020-11-17, 09:34
Posts: 150
Ranking
At home in WL-forums
Location: Czech
Posted at: 2024-10-05, 14:15

A little bit out of topic but related to the topic. The biggest problem of AI is road system. How would AI replicate the road system according to replays on many different starting positions with different tribes? And even if there is a reply on the same spot with the same tribe, the game is never the same because the enemies behave differently, the length of the game is different... From my point of view, the best solution for AI is to have different levels of AI not related to replays. Anyway, you have to improve the road system building first, then you can try to transform the replays into some form of AI hints. But I am not a developer so this is just how I see it. It would be great, if there were not only different AI for level (easy, normal, ...) but also for a map (e.g. small, big). By the way I would also have a question. Is it possible to modify AI hints by tribes add-on and if not, would it by implemented?


Top Quote
OIPUN
Avatar
Joined: 2020-11-17, 09:34
Posts: 150
Ranking
At home in WL-forums
Location: Czech
Posted at: 2024-10-05, 14:28

And another aspect to be mentioned is fertility of land. It looks like AI doesn't count with this at all. But the road system is probably more crucial.


Top Quote
Wide_knight
Avatar
Topic Opener
Joined: 2024-10-04, 13:09
Posts: 3
Ranking
Just found this site
Posted at: 2024-10-06, 11:52

To clarify, this is not for general AI but for specifically making the AI follow a players build-up. It is inevitably tied to the same map if not the same world with RNG seed and all entirely.

AI seems nice as it is but has some shortcomings that I assume are quite complex to address though they are easy for a player (e.g. AI only building small military sites at the border and thus being vision blocked by a castle)

My initial impetus was using having my past run as a benchmark for a new strategy.

It can also be used to locally rectify low resource/low building spot starts (you do the basic set up in game 1 and use the instructions to kickstart the AI for game 2+).


Top Quote
OIPUN
Avatar
Joined: 2020-11-17, 09:34
Posts: 150
Ranking
At home in WL-forums
Location: Czech
Posted at: 2024-10-06, 15:52

Well someone more competent should reply, someone who knows the script better. I am just giving my points. As I know, the trees are growing randomly too. So there might be necessary to replicate the tree growth probably. It looks really complicated. Once you meet the enemy and the enemy starts to behave as a normal AI again, then you can't expect the AI to build a big military building on a reasonable place anyway. You don't know where you will meet the AI in advance. You need a good AI as a benchmark. When I need a benchmark, I simply look at my past games and set a goal. Then I compare the result with the expectation.


Top Quote
tothxa
Avatar
Joined: 2021-03-24, 12:44
Posts: 482
OS: antix / Debian
Version: some new PR I'm testing
Ranking
Tribe Member
Posted at: 2024-10-06, 17:31

Hi Wide_knight, and welcome to the forum! face-smile.png

If I understand replays correctly, they are saved as „initial world state“ and „player instructions“ to essentially make the game engine re-play the game. The AI is just an „instruction generator“, so in my mind it should be possible to give it a replay instructions file and make it output those instead until some condition is met

Well, yes, that's about right. There's one problem though: There is one pseudo-random generator controlling the whole game, so as soon as any player does anything diffently that then requires one more or one less random number, all random actions start to behave differently, resulting in a snowball of divergence of the game state. The most obvious problem for your use case is tree growth: sooner or later there will be an instruction to build something where now there is a tree that wasn't there, so from then on the player's economy will be broken, also snowballing into ever bigger difference.

On the other hand, in theory it's possible to replicate those player instructions in lua code that directly manipulates the game state, forcing every placement, to come up with the same economy. But that code would have to deal with removing obstacles where free spots are required for farms and foresters, and adjust stocks as required.

That is if you want to play against your previous self real time.

I want to play a map and crush the AI, then switch positions and let the AI use my own buildup instructions to then overcome from the other side and so on.

If it's OK to you to simply "turn the table" when you're about to break your AI opponent's defences, that's quite easy with multiplayer savegames. (you can start local "multiplayer" games with yourself as the single human player) Even if you started the game in singleplayer mode, if you have the replay, then you can save the game from the replay viewer, and it will create a multiplayer replay. But be prepared that the AI will have very different opinions about what makes a good economy, so it'll start transforming your nice build-up to its own liking, probably making it much weaker. That's a problem in some of the campaign scenarios too, where the AI is given a supposedly good economy.

Alternatively, if you download the sources (or just these 2 files from codeberg or github), we have a pair of lua scripts in utils/dump_economy.lua and utils/load_economy.lua that make it possible to take and restore a snapshot of all buildings and roads of a player. You could use these to help the AI overcome the limitations of its starting position and give it some boost at the start of the game. Again, you may have to remove some rocks and trees beyond the ones cleared by the forced placement of buildings and roads.


e.g. AI only building small military sites at the border and thus being vision blocked by a castle

Well, that may have that disadvantage for attacking, but it sure works well for defence. At least I find it rather annoying when I have to take them out one by one, and it certainly limits the damage of the loss of a single building.

Edited: 2024-10-06, 18:24

Top Quote
Wide_knight
Avatar
Topic Opener
Joined: 2024-10-04, 13:09
Posts: 3
Ranking
Just found this site
Posted at: 2024-10-14, 18:02

Thank you for the feedback.

I glossed over the fact that the opposite player breaks the rng.

I think, I‘ll have to implement and train map specific AI then instead.

And for the hard starts I have to read up on AI hints.

Switching into the AI mid game sounds fun though. Gonna try that.


Top Quote