From f867228e6427d36aff6127670be12a0bee5e423a Mon Sep 17 00:00:00 2001
From: Manuel Bucher <manuel.bucher@hu-berlin.de>
Date: Fri, 22 Jun 2018 17:52:42 +0200
Subject: [PATCH] fixed oben/unten-Beziehung von Nachbarberechnung

---
 loesung2.c | 32 ++++++++++++++++++++++----------
 1 file changed, 22 insertions(+), 10 deletions(-)

diff --git a/loesung2.c b/loesung2.c
index f3049ac..5b37b0b 100755
--- a/loesung2.c
+++ b/loesung2.c
@@ -178,25 +178,29 @@ int field_neighbours(Field *this) {
     uint32_t begin_line = 1; // start der aktuellen Zeile
     Tile *t = this->tiles;
     for (uint32_t cur = 2; cur < this->num_tiles; cur++) {
-        // ermitteln der ost/west-Beziehung
+        // ermitteln der x-Beziehung
         uint32_t east = cur-1;
-        if (t[cur].x == t[east].x) {
-            if (t[cur].y == t[east].y) {
+        if (t[cur].x == t[east].x) { // gleiche Zeile
+            if (t[cur].y == t[east].y) { // gleiche Spalte
                 return 1; // Doppelung
             } else if (t[cur].y-1 == t[east].y) {
                 t[cur].neigh[1] = east;
                 t[east].neigh[3] = cur;
             }
         } else {
+            top = begin_line;
             begin_line = cur; // neue Zeile
         }
-        // ermitteln der nord/sued-Beziehung
-        if (t[top].x < t[cur].x - 1) {
-            top = begin_line; // Luecke zwischen zeilen
+        // ermitteln der Zeilen-Beziehung
+        if (t[begin_line].x != 0 && t[top].x < t[begin_line].x - 1) {
+            // Zeilensprung => Warten bis zur naechsten Zeile angekommen
         } else if (t[top].x == t[cur].x - 1) {
             // finden, ob paar nach oben existiert O(n) fuer alle Nachbarn nach oben/unten.
             for(;t[top].y < t[cur].y && top < begin_line; top++);
-            if (t[top].y == t[cur].y) {
+
+            // aktuelle obere Kachel koennte benachbart sein
+            if (t[top].y == t[cur].y) { // nicht auf naechste Zeile uebergegangen
+                // Neue Verbindung oben/unten gefunden
                 t[top].neigh[2] = cur;
                 t[cur].neigh[0] = top;
             }
@@ -207,8 +211,16 @@ int field_neighbours(Field *this) {
 
 void field_print(Field *this) {
     printf("[\n");
+    Tile *t = this->tiles;
     for (uint32_t i = 1; i < this->num_tiles; i++){
-        printf("\t(%u %u)\n", this->tiles[i].x, this->tiles[i].y);
+        printf("\t(%u %u): {", t[i].x, this->tiles[i].y);
+        for (int j = 0; j < 4; j++) {
+            if(t[i].neigh[j] != 0) {
+                Tile *neigh = &t[t[i].neigh[j]];
+                printf(" (%u %u)", neigh->x, neigh->y);
+            }
+        }
+        printf(" }\n");
     }
     printf("]\n");
 }
@@ -348,9 +360,9 @@ int main() {
             fprintf(stderr, "Error: Duplicated entry\n"); // Duplikat exisitert
             break;
         }
-        /*if (f.num_tiles - f.num_odd == f.num_odd) {
+        if (f.num_tiles - f.num_odd == f.num_odd) {
             printf("None\n");
-        }*/
+        }
         hk(&f); // Algorithmus von Hopcroft und Karp
         result = EXIT_SUCCESS;
         break;
-- 
GitLab