Finished the algorithm for finding words

Robert Sesek [2008-06-05 19:07]
Finished the algorithm for finding words

* Source/AppController.m:
(findWords:)
diff --git a/Source/AppController.m b/Source/AppController.m
index 30653c0..4b9800f 100644
--- a/Source/AppController.m
+++ b/Source/AppController.m
@@ -78,10 +78,17 @@
 		}

 		BOOL add = YES;
-		int j, k;
-		for (j = 0, k = numWild; k < length && j < [word length]; j++, k++)
+		int j = 0, k = numWild;
+		while (k < length && j < [word length])
 		{
-			if ([[word alphagram] characterAtIndex:j] != [tiles characterAtIndex:k])
+			unichar charW = [[word alphagram] characterAtIndex:j];
+			unichar charT = [tiles characterAtIndex:k];
+			if (charW == charT)
+			{
+				j++;
+				k++;
+			}
+			else if (charW < charT)
 			{
 				wildCounter--;
 				if (wildCounter < 0)
@@ -91,9 +98,14 @@
 				}
 				else
 				{
-					continue;
+					j++;
+					k++;
 				}
 			}
+			else
+			{
+				k++;
+			}
 		}

 		if (j < [word length] && j + wildCounter < [word length])