Topic: main roads becoming normal again

Tibor

Joined: 2009-03-23, 23:24 UTC+1.0
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2018-05-07, 07:15 UTC+2.0

It crashes reliably for me. AI-players only game...

Yes, your fix is exactly what I had in my mind, but you are an author face-smile.png


Top Quote
ypopezios
Avatar
Joined: 2018-04-20, 00:22 UTC+2.0
Posts: 220
Ranking
Widelands-Forum-Junkie
Posted at: 2018-05-07, 14:03 UTC+2.0

Tibor wrote:

It crashes reliably for me. AI-players only game...

This is an indication that AI makes something unintelligent. But AI fixes should wait for later, after the underlying model gets friendlier to them.

EDIT: This time AI was innocent.

Edited: 2018-05-10, 06:37 UTC+2.0

Top Quote
Tibor

Joined: 2009-03-23, 23:24 UTC+1.0
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2018-05-07, 14:23 UTC+2.0

ypopezios wrote:

Tibor wrote:

It crashes reliably for me. AI-players only game...

This is an indication that AI makes something unintelligent. But AI fixes should wait for later, after the underlying model gets friendlier to them.

Oh no. You cannot forbid users to build dead end roads.It is other way round - your algorithm should support all cases....

Edited: 2018-05-07, 14:26 UTC+2.0

Top Quote
ypopezios
Avatar
Joined: 2018-04-20, 00:22 UTC+2.0
Posts: 220
Ranking
Widelands-Forum-Junkie
Posted at: 2018-05-07, 14:37 UTC+2.0

Tibor wrote:

You cannot forbid users to build dead end roads.It is other way round - your algorithm should support all cases....

In my tests I built everything I could think of (including all kinds of dead-ends), without ever getting a crash. So the crash should be some special edge case. But sure, better be safe than sorry.

EDIT: Although a rare case, it was not an edge case.

Edited: 2018-05-10, 06:39 UTC+2.0

Top Quote
Tibor

Joined: 2009-03-23, 23:24 UTC+1.0
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2018-05-07, 14:42 UTC+2.0

ypopezios wrote:

Tibor wrote:

You cannot forbid users to build dead end roads.It is other way round - your algorithm should support all cases....

In my tests I built everything I could think of (including all kinds of dead-ends), without ever getting a crash. So the crash should be some special edge case. But sure, better be safe than sorry.

So your test coverage is not 100%. AI does only human player can do - at least in regard to road making and dismantling....


Top Quote
ypopezios
Avatar
Joined: 2018-04-20, 00:22 UTC+2.0
Posts: 220
Ranking
Widelands-Forum-Junkie
Posted at: 2018-05-07, 14:49 UTC+2.0

Tibor wrote:

So your test coverage is not 100%. AI does only human player can do - at least in regard to road making and dismantling....

It is easily observable that AI's road-making is like a trial-and-error process, quite unsimilar to what humans do. But yes, I never claimed 100% test coverage. People are encouraged to test for themselves.


Top Quote
Tibor

Joined: 2009-03-23, 23:24 UTC+1.0
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2018-05-07, 14:58 UTC+2.0

ypopezios wrote:

Tibor wrote:

So your test coverage is not 100%. AI does only human player can do - at least in regard to road making and dismantling....

It is easily observable that AI's road-making is like a trial-and-error process

I meant that AI can do only what humans can do:

  • build road
  • dismantle road
  • set a flag on long road

AI's road making and dismantling is sensitive to ware traffic and scarcity of buildable spots - yes, it is quite dynamic and if you wish you can call it trial-and-error process...


Top Quote
ypopezios
Avatar
Joined: 2018-04-20, 00:22 UTC+2.0
Posts: 220
Ranking
Widelands-Forum-Junkie
Posted at: 2018-05-07, 15:17 UTC+2.0

Tibor wrote:

  • set a flag on long road

Let's fix that too. Insert line 518 in file economy/road.cc like this:

newroad.wallet_ = wallet_;
Edited: 2018-05-07, 15:22 UTC+2.0

Top Quote
Tibor

Joined: 2009-03-23, 23:24 UTC+1.0
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2018-05-07, 21:28 UTC+2.0

OK, it does not crash anymore. Also new revision was pushes to launchpad.

And finally it looks like working :)


Top Quote
ypopezios
Avatar
Joined: 2018-04-20, 00:22 UTC+2.0
Posts: 220
Ranking
Widelands-Forum-Junkie
Posted at: 2018-05-10, 06:00 UTC+2.0

Corrected propagation method, based on shortage instead of possession:

void Flag::propagate_promoted_road(Road* const promoted_road) {
  // abort if flag has a building attached to it
  if (building_) return;

  // calculate the sum of the involved wallets' adjusted value
  int16_t max_wallet = 1500; // NOCOM should be replaced by kMaxWallet
  int32_t sum = 0;
  for (int8_t i = 0; i < 6; ++i) {
    Road* const road = roads_[i];
    if (!road || road == promoted_road) continue;
    sum += max_wallet + road->wallet_ * road->wallet_;
  }

  // distribute propagation coins in a smart way
  for (int8_t i = 0; i < 6; ++i) {
    Road* const road = roads_[i];
    if (!road || road->type_ == RoadType::kBusy) continue;
    road->wallet_ += 0.5 * (max_wallet - road->wallet_) * (max_wallet + road->wallet_ * road->wallet_) / sum;
  }
}
Edited: 2018-05-10, 15:25 UTC+2.0

Top Quote