Finished the algorithm for checking the words. We now make sure the word isn't too...
authorRobert Sesek <rsesek@bluestatic.org>
Mon, 17 Dec 2007 20:37:11 +0000 (15:37 -0500)
committerRobert Sesek <rsesek@bluestatic.org>
Mon, 17 Dec 2007 20:37:11 +0000 (15:37 -0500)
* Source/NSStringAdditions.h:
* Source/NSStringAdditions.m:
([NSString(NSStringAdditions) occurenceOfChar:]): New Method
* Scrabbalize.xcodeproj: Project changes for NSStringAdditions
* Source/AppController.m: Use the new algorithm and occurence method

Scrabbalize.xcodeproj/project.pbxproj
Source/AppController.m
Source/NSStringAdditions.h [new file with mode: 0644]
Source/NSStringAdditions.m [new file with mode: 0644]

index 06b1bd1af0ae618ca596867fecac5c23dc88d105..93361aa1f436824e0e0965a33da9ccd01c70e999 100644 (file)
@@ -10,6 +10,7 @@
                1EAAC7970D16E9950058A23D /* dictionary.ka in Resources */ = {isa = PBXBuildFile; fileRef = 1EAAC7960D16E9950058A23D /* dictionary.ka */; };
                1EAAC79B0D16E9CE0058A23D /* AppController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1EAAC79A0D16E9CE0058A23D /* AppController.m */; };
                1EAAC8420D16F4A40058A23D /* Word.m in Sources */ = {isa = PBXBuildFile; fileRef = 1EAAC8410D16F4A40058A23D /* Word.m */; };
+               1EAAC93C0D17129D0058A23D /* NSStringAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 1EAAC93B0D17129D0058A23D /* NSStringAdditions.m */; };
                8D11072A0486CEB800E47090 /* MainMenu.nib in Resources */ = {isa = PBXBuildFile; fileRef = 29B97318FDCFA39411CA2CEA /* MainMenu.nib */; };
                8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; };
                8D11072D0486CEB800E47090 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; };
@@ -25,6 +26,8 @@
                1EAAC79A0D16E9CE0058A23D /* AppController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AppController.m; path = Source/AppController.m; sourceTree = "<group>"; };
                1EAAC8400D16F4A40058A23D /* Word.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Word.h; path = Source/Word.h; sourceTree = "<group>"; };
                1EAAC8410D16F4A40058A23D /* Word.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Word.m; path = Source/Word.m; sourceTree = "<group>"; };
+               1EAAC93A0D17129D0058A23D /* NSStringAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NSStringAdditions.h; path = Source/NSStringAdditions.h; sourceTree = "<group>"; };
+               1EAAC93B0D17129D0058A23D /* NSStringAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = NSStringAdditions.m; path = Source/NSStringAdditions.m; sourceTree = "<group>"; };
                29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
                29B97319FDCFA39411CA2CEA /* English */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = English; path = English.lproj/MainMenu.nib; sourceTree = "<group>"; };
                29B97324FDCFA39411CA2CEA /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; };
@@ -53,6 +56,8 @@
                                1EAAC79A0D16E9CE0058A23D /* AppController.m */,
                                1EAAC8400D16F4A40058A23D /* Word.h */,
                                1EAAC8410D16F4A40058A23D /* Word.m */,
+                               1EAAC93A0D17129D0058A23D /* NSStringAdditions.h */,
+                               1EAAC93B0D17129D0058A23D /* NSStringAdditions.m */,
                        );
                        name = Classes;
                        sourceTree = "<group>";
                                8D11072D0486CEB800E47090 /* main.m in Sources */,
                                1EAAC79B0D16E9CE0058A23D /* AppController.m in Sources */,
                                1EAAC8420D16F4A40058A23D /* Word.m in Sources */,
+                               1EAAC93C0D17129D0058A23D /* NSStringAdditions.m in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index 056c3fb0bf1ba25df7ab913b6261b79a142873d6..7b59c855fb83a3fa479999664663059feccac4a9 100644 (file)
@@ -16,7 +16,7 @@
 
 #import "AppController.h"
 #import "Word.h"
-
+#import "NSStringAdditions.h"
 
 @implementation AppController
 
                        continue;
                }
                
-               [wordlist addObject:[[Word alloc] initWithWord:word]];
+               BOOL success = YES;
+               for (NSString *tile in tiles)
+               {
+                       if ([word occurrenceOfChar:tile] > [tileString occurrenceOfChar:tile])
+                       {
+                               success = NO;
+                       }
+               }
+               
+               if (success)
+               {
+                       [wordlist addObject:[[Word alloc] initWithWord:word]];
+               }
        }
        
        // resort
diff --git a/Source/NSStringAdditions.h b/Source/NSStringAdditions.h
new file mode 100644 (file)
index 0000000..a34110c
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * Scrabbalize
+ * Copyright (c) 2007, Blue Static <http://www.bluestatic.org>
+ * 
+ * This program is free software; you can redistribute it and/or modify it under the terms of the GNU 
+ * General Public License as published by the Free Software Foundation; either version 2 of the 
+ * License, or (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License along with this program; if not, 
+ * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#import <Cocoa/Cocoa.h>
+
+
+@interface NSString (NSStringAdditions)
+
+- (int)occurrenceOfChar:(NSString *)aChar;
+
+@end
diff --git a/Source/NSStringAdditions.m b/Source/NSStringAdditions.m
new file mode 100644 (file)
index 0000000..aaae6e7
--- /dev/null
@@ -0,0 +1,32 @@
+//
+//  NSStringAdditions.m
+//  Scrabbalize
+//
+//  Created by Robert Sesek on 12/17/07.
+//  Copyright 2007 __MyCompanyName__. All rights reserved.
+//
+
+#import "NSStringAdditions.h"
+
+
+@implementation NSString (NSStringAdditions)
+
+/**
+ * Counts the number of times a given character is in the string
+ */
+- (int)occurrenceOfChar:(NSString *)aChar
+{
+       int count = 0;
+       
+       for (int i = 0; i < [self length]; i++)
+       {
+               if ([[self substringWithRange:NSMakeRange(i, 1)] isEqualToString:aChar])
+               {
+                       count++;
+               }
+       }
+       
+       return count;
+}
+
+@end