Latest Posts

Topic: Improving the AI

Tibor

Joined: 2009-03-23, 23:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2019-12-02, 16:52

hessenfarmer wrote:

Problem for me still is why the values I have seen with instrumented code were so weird and far from displayed stats.

Yes, this sounds bad, it is good you will investigate this...


Top Quote
hessenfarmer
Avatar
Joined: 2014-12-11, 23:16
Posts: 2646
Ranking
One Elder of Players
Location: Bavaria
Posted at: 2019-12-02, 23:40

ok I found the issue with crude statistics. It is simple but not obvious with a timebase of 10 minutes or 600000 ms we were limited to 71 % max as this is were we reached the uint32 overflow. with 480 it is something about 91 %. I will try a fix for this and retest.


Top Quote
Tibor

Joined: 2009-03-23, 23:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2019-12-03, 07:58

hessenfarmer wrote:

ok I found the issue with crude statistics. It is simple but not obvious with a timebase of 10 minutes or 600000 ms we were limited to 71 % max as this is were we reached the uint32 overflow. with 480 it is something about 91 %. I will try a fix for this and retest.

ouh, sh*t. Great catch!

This is typical case where unittests would help

Also I think this fix should go in separate branch.... as fast as possible and I will retrain AI

Edited: 2019-12-03, 08:34

Top Quote
hessenfarmer
Avatar
Joined: 2014-12-11, 23:16
Posts: 2646
Ranking
One Elder of Players
Location: Bavaria
Posted at: 2019-12-03, 09:19

Please wait with retraining until I have implemented the worker management in AI although I am not planning to use genetics here I don't know yet if there might be a reason to do so. I have implemented som penalty for unoccupied buildings as well i my amazons branch.
For the fix of the crude_statistics issue I just skipped one digit in our Integer percentage (1000 is now equal to 100% instead of 10000). I believe we could live easily with the lost precision which we never needed.


Top Quote
Tibor

Joined: 2009-03-23, 23:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2019-12-03, 09:23

So you will make separate branch for crude statistics fix and new worker management - would be great.... tell me if you will need some help...


Top Quote
hessenfarmer
Avatar
Joined: 2014-12-11, 23:16
Posts: 2646
Ranking
One Elder of Players
Location: Bavaria
Posted at: 2019-12-03, 10:55

Tibor wrote:

So you will make separate branch for crude statistics fix and new worker management - would be great.... tell me if you will need some help...

exactly! I will develop and test them with my amazons branch and then pull them out to an AI branch. Testing with amazons is necessary as only there the worker evict is of high importance. the AI branch will contain the penalty for unoccupied sites as well.


Top Quote
hessenfarmer
Avatar
Joined: 2014-12-11, 23:16
Posts: 2646
Ranking
One Elder of Players
Location: Bavaria
Posted at: 2019-12-03, 22:23

Well I really could use some help as my knowledge of c++ is to little. Here is what I have tried:

for (uint8_t i = 0; i < site.bo->positions.size(); ++i) {
    if (!(site.bo->positions[i] == site.site->working_positions()[i].worker)) {
        if (calculate_stocklevel(site.site->working_positions()[i].first, WareWorker::kWorker) < 1) {
            site.site->remove_worker(*site.site->working_positions()[i].worker);
            return true;
        }
    }
}

but it isn't compiling and i don't understand what to do.


Top Quote
hessenfarmer
Avatar
Joined: 2014-12-11, 23:16
Posts: 2646
Ranking
One Elder of Players
Location: Bavaria
Posted at: 2019-12-04, 00:04

ok got htings to compile but crashes.

What i wanted to do is for a given productioinsite check for all working positions described in the bo whether the actual worker is the worker in the bo. If not check if we have at least 1 worker of the current worker in stock. if not evict him from the side.
My problem is I don't know how to get the index or name of the current worker. And I don't know how to give a pointer to this current worker to the remove routine.


Top Quote
hessenfarmer
Avatar
Joined: 2014-12-11, 23:16
Posts: 2646
Ranking
One Elder of Players
Location: Bavaria
Posted at: 2019-12-04, 00:55

I am getting there. This code does not crash:

for (auto worker : site.bo->positions) {
    const Worker* cw = site.site->working_positions()[0].worker;
        if (cw) {
            DescriptionIndex current_worker = cw->descr().worker_index();
            log("%s , %d, %d, %d\n", site.bo->name, worker, cw, current_worker);
            if (current_worker != worker && calculate_stocklevel(current_worker, WareWorker::kWorker) < 1) {
                site.site->remove_worker(*site.site->working_positions()[0].worker);
                return true;
            }
        }
}

However all master workers get removed completely instead of expelled. And it is only working for buildings with only 1 working position so far.


Top Quote
hessenfarmer
Avatar
Joined: 2014-12-11, 23:16
Posts: 2646
Ranking
One Elder of Players
Location: Bavaria
Posted at: 2019-12-04, 01:19

ok last update this is doing what it should do:

for (auto worker : site.bo->positions) {
    const Worker* cw = site.site->working_positions()[0].worker
        if (cw) {
            DescriptionIndex current_worker = cw->descr().worker_index();
            log("%s , %d, %d, %d\n", site.bo->name, worker, cw, current_worker);
            if (current_worker != worker && calculate_stocklevel(current_worker, WareWorker::kWorker) < 1) {
                game().send_player_evict_worker(*site.site->working_positions()[0].worker);
                return true;
            }
        }
}

So I only need to find out how to compare multiple workers in a building with its related position.


Top Quote