Adding some comments to the -[findWords:] method
authorRobert Sesek <rsesek@bluestatic.org>
Mon, 17 Dec 2007 20:03:38 +0000 (15:03 -0500)
committerRobert Sesek <rsesek@bluestatic.org>
Mon, 17 Dec 2007 20:03:38 +0000 (15:03 -0500)
* Source/AppController.m

Source/AppController.m

index 04e257e978c6f3dd66a4c7bf609e78fcfb9b069a..056c3fb0bf1ba25df7ab913b6261b79a142873d6 100644 (file)
        int tileCount = [tileString length];
        
        NSMutableArray *tiles = [NSMutableArray arrayWithCapacity:tileCount - 1];
-       
        for (int i = 0; i < tileCount; i++)
        {
                [tiles addObject:[tileString substringWithRange:NSMakeRange(i, 1)]];
        }
        
+       // create character sets from the tiles
        NSCharacterSet *charset = [NSCharacterSet characterSetWithCharactersInString:tileString];
        NSCharacterSet *charsetInverted = [charset invertedSet];
        
+       // iterate over the dictionary to build our word list
        for (NSString *word in dictionary)
        {
+               // word is larger than the number of tiles we have, remove
                if ([word length] > tileCount)
                {
                        continue;
                }
                
-               if ([word rangeOfCharacterFromSet:charsetInverted].location == NSNotFound)
+               // if the word contains characters we don't have, then remove it
+               if ([word rangeOfCharacterFromSet:charsetInverted].location != NSNotFound)
                {
-                       [wordlist addObject:[[Word alloc] initWithWord:word]];
+                       continue;
                }
+               
+               [wordlist addObject:[[Word alloc] initWithWord:word]];
        }
        
        // resort