fairland: Make actual island sizes fair

The previous commit reduced the difference in island size within the
same batch of islands to at most one.  Eliminate the remaining
difference by shrinking the bigger islands by one sector.

This invalidates the precomputed exclusive zones, so recompute them.

fairland-test needs a tweak to avoid loss of test coverage.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
Markus Armbruster 2020-08-11 16:41:20 +02:00
parent 212c7ddcef
commit 08ca6ace12
7 changed files with 1749 additions and 1743 deletions

View file

@ -65,7 +65,7 @@
* Each continent has a "sphere of influence": the set of sectors * Each continent has a "sphere of influence": the set of sectors
* closer to it than to any other continent. Each island is entirely * closer to it than to any other continent. Each island is entirely
* in one such sphere, and each sphere contains the same number of * in one such sphere, and each sphere contains the same number of
* islands. * islands with the same sizes.
* *
* Pick an island size, and place one island's first sector into each * Pick an island size, and place one island's first sector into each
* sphere, randomly. Then add one sector to each island in turn, * sphere, randomly. Then add one sector to each island in turn,
@ -944,15 +944,17 @@ can_grow_at(int c, int x, int y)
static void static void
adj_land_update(int x, int y) adj_land_update(int x, int y)
{ {
int is_land = own[x][y] != -1;
int dir, nx, ny, noff; int dir, nx, ny, noff;
assert(own[x][y] != -1);
for (dir = DIR_FIRST; dir <= DIR_LAST; dir++) { for (dir = DIR_FIRST; dir <= DIR_LAST; dir++) {
nx = new_x(x + diroff[dir][0]); nx = new_x(x + diroff[dir][0]);
ny = new_y(y + diroff[dir][1]); ny = new_y(y + diroff[dir][1]);
noff = XYOFFSET(nx, ny); noff = XYOFFSET(nx, ny);
adj_land[noff] |= 1u << DIR_BACK(dir); if (is_land)
adj_land[noff] |= 1u << DIR_BACK(dir);
else
adj_land[noff] &= ~(1u << DIR_BACK(dir));
} }
} }
@ -1117,13 +1119,17 @@ grow_islands(void)
{ {
int n = ni / nc; int n = ni / nc;
int stunted_islands = 0; int stunted_islands = 0;
int i, j, c, done, secs, isiz; int xzone_valid = 0;
int i, j, c, done, secs, isiz, x, y;
xzone_init(nc);
init_spheres_of_influence(); init_spheres_of_influence();
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
c = nc + i * nc; c = nc + i * nc;
if (!xzone_valid)
xzone_init(c);
isiz = roll(is) + roll0(is); isiz = roll(is) + roll0(is);
for (j = 0; j < nc; j++) { for (j = 0; j < nc; j++) {
@ -1142,6 +1148,21 @@ grow_islands(void)
} }
} }
if (!done) {
secs--;
for (j = 0; j < nc; j++) {
if (isecs[c + j] != secs) {
isecs[c + j]--;
assert(isecs[c + j] == secs);
x = sectx[c + j][secs];
y = secty[c + j][secs];
own[x][y] = -1;
adj_land_update(x, y);
}
}
xzone_valid = 0;
}
for (j = 0; j < nc; j++) for (j = 0; j < nc; j++)
stunted_islands += isecs[c + j] != isiz; stunted_islands += isecs[c + j] != isiz;

View file

@ -17,7 +17,7 @@ $empdump -x >sandbox/plain.xdump
cmp_out plain.xdump plain-newcap_script cmp_out plain.xdump plain-newcap_script
$files -f >/dev/null $files -f >/dev/null
run_and_cmp stunted $fairland -s sandbox/stunted-newcap_script -R 1 8 35 24 3 0 0 5 2 run_and_cmp stunted $fairland -s sandbox/stunted-newcap_script -R 1 8 35 24 20 0 0 5 2
$empdump -x >sandbox/stunted.xdump $empdump -x >sandbox/stunted.xdump
cmp_out stunted.xdump stunted-newcap_script cmp_out stunted.xdump stunted-newcap_script

View file

@ -15,29 +15,29 @@ World dimensions: 64x32
seed is 1 seed is 1
placing capitals... placing capitals...
growing continents... growing continents...
growing islands: 1(12) 2(12) 3(12) 4(11) 5(12) 6(12) 7(12) 8(12) growing islands: 1(11) 2(11) 3(11) 4(11) 5(11) 6(11) 7(11) 8(11)
8 stunted islands 8 stunted islands
elevating land... elevating land...
writing to sectors file... writing to sectors file...
^ b b # # . . . . ^ % . % % . . % % ^ . . . . . . . . . % . . . ^ b b # # . . . . ^ % . % % . . % % ^ . . . . . . . . . . . . .
# # ^ # . . . % % % % . % % % % % % % . . . . . . . % % . # # # # # ^ # . . . % % % % . % % % % % % . . . . . . . . % % . # # #
# # # # . . . % % % % . % % % . . . . . . . . . . . % % % . # # # # # # . . . % % % % . % % % . . . . . . . . . . . % % % . # #
# # . . . . % . . % . . % % % . % . . . . . . . . . % ^ % . . # # # . . . . . . . % . . % % % . . . . . . . . . . . % ^ % . . #
. # . . . . . . # . . . . % % ^ % . . . . . . . . . . % % % . . . # . . . . . . # . . . . % % ^ % . . . . . . . . . . % % % . .
. . . . . . . # # . . . . . % . . # # . . . . . . . . . . . . . . . . . . . . # # . . . . . % . . # # . . . . . . . . . . . . .
. . . . . # # # ^ # . . . # . . # # # # # # . . . . . . . . . # . . . . . # # # ^ # . . . # . . # # # # # # . . . . . . . . . #
. . . . # # # # # . . . . # # # ^ f f . . # # . . . . . . . # . . . . . # # # # # . . . . # # # ^ f f . . # # . . . . . . . # .
# . . . . # # e e ^ # . . . . # # ^ # . . . # . . . . . . . # # # . . . . # # e e ^ # . . . . # # ^ # . . . # . . . . . . . # #
. % . . . . # # # # # # . . # ^ # # . . . . # . . . . . . ^ # # . ^ . . . . # # # # # # . . # ^ # # . . . . # . . . . . . ^ # #
. % % . . . . # ^ . # # . . # # # . . . . . . . . . . . . # ^ # . % % . . . . # ^ . # # . . # # # . . . . . . . . . . . . # ^ #
. % % . . . . # . . . . . . . . . . . . . . . . . . . . h h # ^ . % % . . . . # . . . . . . . . . . . . . . . . . . . . h h # ^
. % % . . . . . . . . . . . . . . . . . . . . . . . # # # # # # . % % . . . . . . . . . . . . . . . . . . . . . . . # # # # # #
% ^ % . . . . . . . . . . . . . . . . . . . . . . # # # . . # . % % % . . . . . . . . . . . . . . . . . . . . . . # # # . . # .
. % % . . . . . . . . . . . . . . . . # . . . . . # . # . . # # . . % . . . . . . . . . . . . . . . . # . . . . . # . # . . # #
. . . . . . . . . . . . . . . . . # # # # # # . . . . # . . . . . . . . . . . . . . . . . . . . . # # # # # # . . . . # . . . .
. . . . . . . # . # # . . . . . . . . # ^ # ^ # . . . . . . . . . . . . . . . # . # # . . . . . . . . # ^ # ^ # . . . . . . . .
. . . . . . ^ # # # . . . . . . . . # # d d # # . . . . . . % . . . . . . . ^ # # # . . . . . . . . # # d d # # . . . . . . . .
% . . . . # # # # . . . . . . . . . # # ^ # # # # . . . . . . % % . . . . # # # # . . . . . . . . . # # ^ # # # # . . . . . . %
% . . . . # # # . . . . . . . . . # . # . . . # . . . . . # . ^ % . . . . # # # . . . . . . . . . # . # . . . # . . . . . # . ^
% . . . # # c c . . . . . . . . . # . . . % % . # . . . # # # . % . . . # # c c . . . . . . . . . # . . . % % . # . . . # # # .
@ -48,7 +48,7 @@ writing to sectors file...
. . . . . % . # ^ . . . . . . # . # # . . . . . . . # # . . # # . . . . . % . # ^ . . . . . . # . # # . . . . . . . # # . . # #
. . . . . . ^ . . . . . . # # # # # # . . . . . . . . . . . # # . . . . . . ^ . . . . . . # # # # # # . . . . . . . . . . . # #
. . . . . % % % . . . . . . . ^ # # # # . . . . . . . . # # . . . . . . . % % % . . . . . . . ^ # # # # . . . . . . . . # # . .
. . . . . . % % % % . . . . . # a a # ^ # . . . . . . . . . . . . . . . . . % % % . . . . . . # a a # ^ # . . . . . . . . . . .
. # . . . . . % % % . . . . # # # # # # . . . . . . . . . . . . . # . . . . . % % % . . . . # # # # # # . . . . . . . . . . . .
^ # # . . . . . . . . . . . . . . # # . . . . . . . . . . . . . ^ # # . . . . . . . . . . . . . . # # . . . . . . . . . . . . .
# # # # . . . . . . . . . . . . . . . . . . . . . . . . . . . . # # # # . . . . . . . . . . . . . . . . . . . . . . . . . . . .

File diff suppressed because it is too large Load diff

View file

@ -1,17 +1,17 @@
add 1 1 1 p add 1 1 1 p
newcap 1 13,13 newcap 1 47,11
add 2 2 2 p add 2 2 2 p
newcap 2 45,29 newcap 2 42,0
add 3 3 3 p add 3 3 3 p
newcap 3 49,13 newcap 3 57,23
add 4 4 4 p add 4 4 4 p
newcap 4 17,29 newcap 4 61,3
add 5 5 5 p add 5 5 5 p
newcap 5 31,7 newcap 5 31,21
add 6 6 6 p add 6 6 6 p
newcap 6 63,3 newcap 6 14,26
add 7 7 7 p add 7 7 7 p
newcap 7 31,21 newcap 7 24,6
add 8 8 8 p add 8 8 8 p
newcap 8 63,23 newcap 8 9,15
add 9 visitor visitor v add 9 visitor visitor v

View file

@ -3,7 +3,7 @@ Creating a planet with:
8 continents 8 continents
continent size: 35 continent size: 35
number of islands: 24 number of islands: 24
average size of islands: 3 average size of islands: 20
spike: 0% spike: 0%
0% of land is mountain (each continent will have 0 mountains) 0% of land is mountain (each continent will have 0 mountains)
minimum distance between continents: 5 minimum distance between continents: 5
@ -15,74 +15,59 @@ World dimensions: 64x32
seed is 1 seed is 1
placing capitals... placing capitals...
growing continents... growing continents...
growing islands: 1(2) 2(2) 3(2) 4(2) 5(2) 6(2) 7(1) 8(1) 9(2) 10(2) 11(2) 12(1) 13(2) 14(2) 15(1) 16(2) growing islands: 1(2) 2(2) 3(2) 4(2) 5(2) 6(2) 7(2) 8(2) 9(1) 10(1) 11(1) 12(1) 13(1) 14(1) 15(1) 16(1)
No room for island #19 No room for island #23
try #2 (out of 10)... try #2 (out of 10)...
placing capitals... placing capitals...
growing continents... growing continents...
growing islands: 1(2) 2(3) 3(3) 4(3) 5(2) 6(3) 7(3) 8(3) 9(1) 10(1) 11(2) 12(2) 13(2) 14(2) 15(1) 16(2) Only managed to grow 33 out of 35 sectors.
No room for island #18
try #3 (out of 10)... try #3 (out of 10)...
placing capitals... placing capitals...
growing continents... growing continents...
Only managed to grow 33 out of 35 sectors. growing islands: 1(2) 2(2) 3(2) 4(2) 5(2) 6(2) 7(2) 8(2) 9(1) 10(1) 11(1) 12(1) 13(1) 14(1) 15(1) 16(1)
No room for island #24
try #4 (out of 10)... try #4 (out of 10)...
placing capitals... placing capitals...
growing continents... growing continents...
Only managed to grow 32 out of 35 sectors. growing islands: 1(1) 2(1) 3(1) 4(1) 5(1) 6(1) 7(1) 8(1) 9(1) 10(1) 11(1) 12(1) 13(1) 14(1) 15(1) 16(1) 17(1) 18(1) 19(1) 20(1) 21(1) 22(1) 23(1) 24(1)
24 stunted islands
try #5 (out of 10)...
placing capitals...
growing continents...
Only managed to grow 29 out of 35 sectors.
try #6 (out of 10)...
placing capitals...
growing continents...
Only managed to grow 33 out of 35 sectors.
try #7 (out of 10)...
placing capitals...
growing continents...
growing islands: 1(1) 2(2) 3(2) 4(2) 5(2) 6(2) 7(2) 8(2) 9(2) 10(2) 11(2) 12(2) 13(1) 14(2) 15(2) 16(2) 17(2) 18(2) 19(2) 20(2) 21(2) 22(2) 23(1) 24(1)
10 stunted islands
elevating land... elevating land...
writing to sectors file... writing to sectors file...
. # . . . . . # # # # . . . % % . . . . . . # # . . . . . . . . . . . . . . . . . . . . . . . . . . . # # # # # # . . . . . . %
# # . . . . . . # # . . . . . . . . . . . . # # . . . . . . # # . . . . . . . . . . . . . . . . . . . # # # # # # # . . . . . .
# # # . . . . . . . . . . . . . . . . . . . . . . . . . . . # # . . . . . . . % . . . . . . . . . . . . # # # # # # . . . . . .
# # . . . . % . . . . . . . # # # # . . . . . . . % . . . # # # . # # # . . . . . . . . . . . . . . . . . . . . . . . . . . # .
# # # . . . . % . . . . . . # # # # # . . . . . . % . . . . # # # # # # # . . . . . . # # # # # . . . . . . . . . . . . . . # #
g # # . . . . . . . . . . . # # # # # . . % . . . . . % . . # g e # # # . . . . . # # # # # # # . . . . . . . . . . . % . . # e
# # # . . . . . . % % . . # # # # # # # . . . . . . . . . . # # # # # # # . . . . . # # # # # # # . . % . . . . . . . . . . # #
# # . . . . . . . . . . . # # h h # . . . . . . . . . . . . # # # # # . . . . % . . # # c c # # # . . . . . . . . . . . . . # #
. # . . . % % . . . . . . . # # # # # . . . . . . . . . . . . . # # # . . . . . . . . # # # # # # . . . . . # # # # . . . . . #
. . . . . . . . . . % . . . # # # # . . . . . # # # . . . . . . # . . . . . . . . . . . # # . . . . . . . # # # # # . . . . . #
. . . . . . . . . . . % . . . . . . . . . . . # # # # . . . . . . . . . . . . . . . . . . # . . . . . . . # # f f # # . . . . .
% . . . . # # # # . . . . . . . . . . . % . . # # # # . . . . % . . . . . . . . . . . . . . . . % . . . # # # # # # # . . . . .
. . . . . # # # # # . . . . . . . . . . % . . # # # # # . . . . . . . . . . # # . . % . . . . . . . . . . # # # # # # # . . . %
. . . . # # b b # # # . . . % % . . . . . . # # d d # # . . . . . % . . . # # # . . . . . . . . . . . . . . # # # # . . . . . .
. . . . . # # # # # # # . . . . . . . . . . . # # # # # . . % % . . . . # # # # # . . . % . . . . . . % . . . # # . . . . . . .
. . . . . # # # # # # . . . . . . . . . . . . # # # # . . . . . . . . # # # # # . . . . . . . . . . . . . . . . . . . . % . . %
. % % . . . # # # # . . . . . . # # # . . . . . # # # . . . . . . . . # # b b # # . . . . . # # # . . . . . . . . . . . . . . .
. . . . . . . # # . . . . . . # # # # . . . . . . # . . . . . . . . . # # # # # # . . . . . # # # . . . . . % . . . . . . . . .
. . . . . . . . . . . . . . . # # # # # . . . . . . . . . % . . . . . . # # # # # . . . . . # # # # # . . . . . . . . . . . . %
# # . . . % . . . . . . . . # f f # # # . . . . . . . . % . . . . . . # # # . . . . . . . # d d # # . . % . . . . . . . . . . .
# # # . . . % . . . . . . . . # # # # # # . . . % % . . . . . . . . . . . . . . . . . . . # # # # # # . . . . . . . # # # . . .
# # # . . . . . . . . . % . . # # # # # . . . . . . . . . . # # . . . . . . . . . . . . . # # # # # . . . . % . . # # # # . . .
# # # # . . . . . % % . . % . . # # # # . . . . . . . % . . # # . . . . . . . . . . . . . . # # # # . . . . . . . . # # g g # .
e # # # . . . . . . . . . . . # # . . . . . . . . . . . . # # e . . . . . . . . . . . . . . # # # . . . % . . . . . # # # # # #
# # # # . . . . . . . . . . . . . . . . . . . . . . . . . . # # . . . . . % . . . # . . . . . # . . . . . . . . . . # # # # # #
# # . . . . . . # # . . . . . . . . . . . . . # . . . . . . # # . . . . . . . # # # . . . . . . . . . . . . . . . . # # # # # .
# . . . . . . . # # # . . . . . . % % . . . . # # # . . . . . # . . . . . . . # # # # . . . . . . . . . % . . . . . . # # # # .
. . . . . . . # # # # . . . . . . . . . . . # # # # . . . . . . . . . . . # # a a # # . . . . . . % . . . . . . . . . # # . . .
. . . . . . . # # # # # # . . % . . . . . # # # # # # . . . . . . . . . . # # # # # # # . . . . . . . . . . . . . . . . . . . .
. . % . . . # # c c # . . . % . . . . . # # a a # # . . % . . . . . . . . # # # # # # # . . . . . . . # # # # . . . . . . . . %
. . . % . . . # # # # # . . . . . . % . . # # # # # # . . . . . . . . . . . . # # # # # # . . . . . # # # # # # . . . . . . . .
. . . . . . . # # # # . . . . . . . % . . # # # # # . . . . . . . . . . . . . # . . . . . . % . . . # # h h # # . . . % . . . .
A script for adding all the countries can be found in "sandbox/stunted-newcap_script". A script for adding all the countries can be found in "sandbox/stunted-newcap_script".

File diff suppressed because it is too large Load diff