]> git.pond.sub.org Git - empserver/commitdiff
fairland: Move capital initialization to drift() & simplify
authorMarkus Armbruster <armbru@pond.sub.org>
Mon, 10 Aug 2020 15:55:15 +0000 (17:55 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Tue, 5 Jan 2021 09:41:36 +0000 (10:41 +0100)
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
src/util/fairland.c

index 382541a9190349a81a8e5bb26a4ac4553e6a5456..00e1aa102516d41bb640beb8c0186a346d9bc104 100644 (file)
@@ -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;