[gnome-tetravex] Fix a bug.



commit a78e18f42dfbec6bd624bb6f14eec6d31fc19716
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Sat Sep 28 21:13:08 2019 +0200

    Fix a bug.
    
    It was possible to obtain
    incompatible tiles on the
    left board by inverting a
    tile and one bordering it
    if no other compatibility
    problem. Check that also.

 src/puzzle.vala | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
---
diff --git a/src/puzzle.vala b/src/puzzle.vala
index 1ed0b40..da9318d 100644
--- a/src/puzzle.vala
+++ b/src/puzzle.vala
@@ -224,12 +224,31 @@ private class Puzzle : Object
         if (t0 == null && t1 == null)
             return false;
 
-        /* If placing onto the final area check if it fits */
+        /* if placing onto the final area, check if it fits regarding current tiles */
         if (t0 != null && x1 < size && !tile_fits (x0, y0, x1, y1))
             return false;
         if (t1 != null && x0 < size && !tile_fits (x1, y1, x0, y0))
             return false;
 
+        /* if inverting two tiles of the final area, check that they are compatible */
+        if (t0 != null && t1 != null && x0 <size && x1 < size)
+        {
+            if (x0 == x1)
+            {
+                if (y0 == y1 + 1 && ((!) t0).south != ((!) t1).north)
+                    return false;
+                if (y0 == y1 - 1 && ((!) t0).north != ((!) t1).south)
+                    return false;
+            }
+            else if (y0 == y1)
+            {
+                if (x0 == x1 + 1 && ((!) t0).east != ((!) t1).west)
+                    return false;
+                if (x0 == x1 - 1 && ((!) t0).west != ((!) t1).west)
+                    return false;
+            }
+        }
+
         return true;
     }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]