Currently Online

Latest Posts

Topic: auto_speed problem

Tibor
Joined: 2009-03-23, 23:24
Posts: 1374
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2021-12-05, 17:48

I noticed the behaviour of game has changed. If I set very high speed, fps are OK, but AI does not work... In the past, FPS were good indicator how much CPU time AI gets, but no more.

I can run AI training at fixes speed, like 3x, but this is waste of the time.

Any ideas?

EDIT:

In fact, I can imagine AI training without UI, or with UI with extra low priority...

Edited: 2021-12-05, 17:59

Top Quote
Nordfriese
Avatar
Joined: 2017-01-17, 18:07
Posts: 1522
Ranking
One Elder of Players
Location: 0x55555d3a34c0
Posted at: 2021-12-05, 18:22

Widelands is multithreaded in current master now. FPS now only indicates how responsive the UI thread is, but AI is managed by the logic thread. hessenfarmer is currently working on giving the AI a thread of its own. After this refactoring we could consider how to make auto_speed useful again


Top Quote
hessenfarmer
Avatar
Joined: 2014-12-11, 23:16
Posts: 2071
Ranking
One Elder of Players
Location: Bavaria
Posted at: 2021-12-05, 18:23

This is due to the fact that the ui is now running in an own thread whiuch means fps is no valid measure anymore.
maybe we can use the AI internal delay time which is evaluated anyway?

Edit: I just had a look and I think moving the auto_speed function into the AI code and using the schedule delay as a measure should work

Edited: 2021-12-05, 18:41

Top Quote
Tibor
Joined: 2009-03-23, 23:24
Posts: 1374
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2021-12-05, 18:43

This is generally good news!

AI now presumes that is it called twice a second, see here:

https://github.com/widelands/widelands/blob/42089b9a5d645b8814c2e04cab394fbe62f9847b/src/ai/defaultai.cc#L256

In my opinion, up to 1 second frequency is bearable, but I would not go beyond. If you know the code of game scheduler - do you see even at least dirty hack for to make the game regulate the speed to keep the frequency below 1000 ms per one think() of each player?

Generally I need 100 hours for meaningful training, if I set the speed to 3, it might mean 2x-3x more time, this is simply too much...

EDIT:

based on my long ago investigation AI was called each 0.1 second, and as the code above shows it just "skipped" the turn if too early after last execution.

Edited: 2021-12-05, 18:45

Top Quote
hessenfarmer
Avatar
Joined: 2014-12-11, 23:16
Posts: 2071
Ranking
One Elder of Players
Location: Bavaria
Posted at: 2021-12-05, 18:43

Nordfriese wrote:

Widelands is multithreaded in current master now. FPS now only indicates how responsive the UI thread is, but AI is managed by the logic thread. hessenfarmer is currently working on giving the AI a thread of its own. After this refactoring we could consider how to make auto_speed useful again.

As my knowledge seems to be too limited to get this done, I'd rather go the other way round and maybe postpone the threading of AI.
I'll try to make a branch with my suggestion made above


Top Quote
hessenfarmer
Avatar
Joined: 2014-12-11, 23:16
Posts: 2071
Ranking
One Elder of Players
Location: Bavaria
Posted at: 2021-12-05, 19:28

ok my branch is compiling locally. if it succeeds I'll push it on Github. Let's keep fingers crossed

after some attempts it compiled and it is working.
the values to evaluate whether to increase or decrease speed might need some adjustments though.

https://github.com/widelands/widelands/pull/5149

Edited: 2021-12-05, 20:59

Top Quote
Tibor
Joined: 2009-03-23, 23:24
Posts: 1374
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2021-12-05, 21:14

I will test the branch, I will have some feedback tomorrow probably

Do you want to merge it into Master?


Top Quote
hessenfarmer
Avatar
Joined: 2014-12-11, 23:16
Posts: 2071
Ranking
One Elder of Players
Location: Bavaria
Posted at: 2021-12-05, 21:27

Tibor wrote:

Do you want to merge it into Master?

yes after I got a positive review.


Top Quote
Tibor
Joined: 2009-03-23, 23:24
Posts: 1374
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2021-12-05, 21:55

Where can I see actual speed - I do not see it on the default screen.


Top Quote
Tibor
Joined: 2009-03-23, 23:24
Posts: 1374
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2021-12-05, 22:00

Also

game().is_auto_speed()

was broken before, and I am not sure if it works now...


Top Quote