Finished the algorithm for finding words
authorRobert Sesek <rsesek@bluestatic.org>
Thu, 5 Jun 2008 19:07:14 +0000 (15:07 -0400)
committerRobert Sesek <rsesek@bluestatic.org>
Thu, 5 Jun 2008 19:07:14 +0000 (15:07 -0400)
* Source/AppController.m:
(findWords:)

Source/AppController.m

index 30653c0d2d5f47205106b69c9d5d3003a6d55731..4b9800ffd25cc7f61be9267d2b1a4c0a3954b2ac 100644 (file)
                }
                
                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)
                                }
                                else
                                {
-                                       continue;
+                                       j++;
+                                       k++;
                                }
                        }
+                       else
+                       {
+                               k++;
+                       }
                }
                
                if (j < [word length] && j + wildCounter < [word length])