[gnome-games] Properly prune duplicates in find_matches()



commit 0ff3b8b7f1f5bea3f0b13c6204b0a2b74c77ffd6
Author: Jim Evins <evins snaught com>
Date:   Tue Jul 17 21:14:23 2012 -0400

    Properly prune duplicates in find_matches()
    
    Search all existing matches for duplicates, not just those that match the
    current tile.

 gnome-mahjongg/src/game.vala |   30 +++++++++++++++---------------
 1 files changed, 15 insertions(+), 15 deletions(-)
---
diff --git a/gnome-mahjongg/src/game.vala b/gnome-mahjongg/src/game.vala
index 563d6c9..3dd06f8 100644
--- a/gnome-mahjongg/src/game.vala
+++ b/gnome-mahjongg/src/game.vala
@@ -269,7 +269,20 @@ public class Game
             foreach (var t in tiles)
             {
                 foreach (var match in find_matches (t))
-                    matches.append (match);
+                {
+	                bool already_matched = false;
+	                foreach (var existing_match in matches)
+	                {
+		                if (existing_match.tile0 == match.tile1 && existing_match.tile1 == match.tile0)
+		                {
+			                already_matched = true;
+			                break;
+		                }
+	                }
+
+	                if (!already_matched)
+		                matches.append (match);
+                }
             }
         }
         else
@@ -279,20 +292,7 @@ public class Game
                 if (t == tile || !tile_can_move (t))
                     continue;
 
-                if (!t.matches (tile))
-                    continue;
-
-                var already_matched = false;
-                foreach (var match in matches)
-                {
-                    if (match.tile0 == tile && match.tile1 == t)
-                    {
-                        already_matched = true;
-                        break;
-                    }
-                }
-
-                if (!already_matched)
+                if (t.matches (tile))
                     matches.append (new Match (t, tile));
             }       
         }



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