]> git.pond.sub.org Git - empserver/commit
fairland: Correct island placement bias
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 9 Aug 2020 15:38:36 +0000 (17:38 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Tue, 5 Jan 2021 09:41:36 +0000 (10:41 +0100)
commiteecb9c982596916f42fa085e196db900ba29ad52
tree8831540cb91c31e5ff0424474ed585e66249b77b
parent001674e5c558f3a50da978919c3e26ba66bfd4e5
fairland: Correct island placement bias

A sector is admissible for island placement when land can be grown in
every sector within a certain distance.

place_island() picks a random start sector, then searches linearly for
an admissible sector.  If it finds one, it places the island there.
Else, it reduces the distance by one and tries again.  It fails when
none is found even for distance zero.

Trying with extra distance is obviously meant to reduce the risk of
islands from running into each other without need.  Initial distance
is @di, the minimum distance between continents, which doesn't really
make sense, and is undocumented.

Bug: place_island() never tries the start sector.

Bias: placement probability is higher for sectors immediately
following inadmissible sectors.  Because of that, islands are more
often placed to the right of existing islands.  Players could exploit
that to guide their search for land.

Rewrite place_island() to pick sectors with equal probability,
dropping the undocumented extra distance feature.  If it's missed, we
can bring it back.

The new code visits each sector once.  The old code visits only one
sector in the best case, but each sector several times in the worst
case.  fairland performance improves measurably for crowded setups
with large @di, else it suffers.  For instance, Hvy Fever example
given in the commit before previous runs seven times faster for me.
With @di reduced to 2, its run time more than doubles.  Not that it
matters.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
src/util/fairland.c
tests/fairland/no-spike.out
tests/fairland/no-spike.xdump
tests/fairland/plain.out
tests/fairland/plain.xdump
tests/fairland/spike.out
tests/fairland/spike.xdump
tests/fairland/stunted.out
tests/fairland/stunted.xdump