Algorithm updates. We no longer crash/get raise:'d but we miss words.
authorRobert Sesek <rsesek@bluestatic.org>
Wed, 28 May 2008 20:33:25 +0000 (16:33 -0400)
committerRobert Sesek <rsesek@bluestatic.org>
Wed, 28 May 2008 20:33:25 +0000 (16:33 -0400)
* Source/AppController.m:
(-[findWords:])

Source/AppController.m

index 45a9b6a2bda43405bfb9ac445881d56a16024df0..bb04e17fb01dcfcbce0a33685186e3a35162914f 100644 (file)
@@ -65,7 +65,7 @@
        [temp release];
        
        NSRange wildRange = [tiles rangeOfString:@"?" options:NSBackwardsSearch];
-       int numWild = wildRange.length + wildRange.location;
+       int numWild = (wildRange.location == NSNotFound ? 0 : wildRange.length + wildRange.location);
        int length = [tiles length];
        
        for (int i = 0; i < [dictionary count]; i++)
@@ -79,7 +79,8 @@
                }
                
                BOOL add = YES;
-               for (int j = 0, k = numWild; k < length; j++, k++)
+               int j, k;
+               for (j = 0, k = numWild; k < length && j < [word length]; j++, k++)
                {
                        if ([[word alphagram] characterAtIndex:j] != [tiles characterAtIndex:k])
                        {
                        }
                }
                
+               if (j < [word length] && j + wildCounter < [word length])
+               {
+                       add = NO;
+               }
+               
                if (add)
                {
                        [wordlist addObject:word];