From 3fc24e35b9a110e716a2943f13078f5ed55774b8 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Mon, 10 Aug 2020 17:55:15 +0200 Subject: [PATCH] fairland: Move capital initialization to drift() & simplify Signed-off-by: Markus Armbruster --- src/util/fairland.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/src/util/fairland.c b/src/util/fairland.c index 382541a9..00e1aa10 100644 --- a/src/util/fairland.c +++ b/src/util/fairland.c @@ -506,29 +506,13 @@ allocate_memory(void) static void init(void) { - int i, j, xx = 0, yy = 0; + int i, j; for (i = 0; i < WORLD_X; ++i) { for (j = 0; j < WORLD_Y; ++j) { own[i][j] = -1; } } - - for (i = 0; i < nc; ++i) { - if (xx >= WORLD_X) { - ++yy; - xx = yy % 2; - if (yy == WORLD_Y) { - fprintf(stderr, - "%s: world not big enough for all the continents\n", - program_name); - exit(1); - } - } - capx[i] = xx; - capy[i] = yy; - xx += 2; - } } /**************************************************************************** @@ -562,6 +546,17 @@ drift(void) { int turns, i; + for (i = 0; i < nc; i++) { + capy[i] = (2 * i) / WORLD_X; + capx[i] = (2 * i) % WORLD_X + capy[i] % 2; + if (capy[i] >= WORLD_Y) { + fprintf(stderr, + "%s: world not big enough for all the continents\n", + program_name); + exit(1); + } + } + for (turns = 0; turns < DRIFT_MAX; ++turns) { if (stable(turns)) return 1;