corrected typoe.

Pascal J. Bourguignon [2014-04-03 20:17]
corrected typoe.
Filename
sources/Hangman.m
sources/generate-library.lisp
sources/hangman.lisp
diff --git a/sources/Hangman.m b/sources/Hangman.m
deleted file mode 100644
index b9c80ce..0000000
--- a/sources/Hangman.m
+++ /dev/null
@@ -1,140 +0,0 @@
-// -*- mode:objc;coding:utf-8 -*-
-//****************************************************************************
-//FILE:               Hangman.m
-//LANGUAGE:           Objective-C
-//SYSTEM:             POSIX
-//USER-INTERFACE:     NONE
-//DESCRIPTION
-//
-//    The Hangman game model.
-//
-//AUTHORS
-//    <PJB> Pascal J. Bourguignon <pjb@informatimago.com>
-//MODIFICATIONS
-//    2014-04-03 <PJB> Created.
-//BUGS
-//LEGAL
-//    AGPL3
-//
-//    Copyright Pascal J. Bourguignon 2014 - 2014
-//
-//    This program is free software: you can redistribute it and/or modify
-//    it under the terms of the GNU Affero General Public License as published by
-//    the Free Software Foundation, either version 3 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 Affero General Public License for more details.
-//
-//    You should have received a copy of the GNU Affero General Public License
-//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
-//****************************************************************************
-#include "Hangman.h"
-
-
-@implementation Hangman
-
--(void)initializeFound{
-    NSInteger length=[word length];
-    found=RETAIN(([NSMutableArray arrayWithCapacity:length]));
-    for(NSInteger i=0;i<length;i++){
-        [found addObject:no];
-    }
-    [found replaceObjectAtIndex:0 withObject:yes];
-    [found replaceObjectAtIndex:([found count]-1) withObject:yes];
-}
-
--(id)initWithWord:(NSString*)aWord maximumErrorCount:(NSInteger)aMaximumErrorCount
-{
-    if((self=[super init])) {
-        missingLetter=@".";
-        alphabet=@"abcdefghijklmnopqrstuvwxyz";
-        yes=RETAIN(([NSNumber numberWithBool:YES]));
-        no=RETAIN(([NSNumber numberWithBool:NO]));
-
-        word=RETAIN(([aWord lowercaseString]));
-        [self initializeFound];
-        triedLetters=RETAIN(([NSMutableString stringWithCapacity:[alphabet length]]));
-        currentErrorCount=0;
-        maximumErrorCount=aMaximumErrorCount;
-    }
-    return(self);
-}
-
-
--(NSString*)getWord
-{
-    return(word);
-}
-
--(NSString*)getFoundWord
-{
-    NSMutableString* foundWord=[word mutableCopy];
-    NSInteger length=[foundWord length];
-    for(NSInteger i=0;i<length;i++){
-        if(![[found objectAtIndex:i] boolValue]){
-            [foundWord replaceCharactersInRange:NSMakeRange(i,1) withString:missingLetter];
-        }
-    }
-    return(foundWord);
-}
-
-
--(NSInteger)tryLetter:(NSString*)letter
-{
-
-    NSRange r=[triedLetters rangeOfString:letter];
-    if(r.length!=0) {
-        if(currentErrorCount<maximumErrorCount){
-            currentErrorCount++;
-        }
-        if(currentErrorCount>=maximumErrorCount){
-            return(Hangman_loses);
-        }else{
-            return(Hangman_alreadyTried);
-        }
-    }
-    [triedLetters appendString:letter];
-
-    NSInteger length=[word length];
-    BOOL error=YES;
-    r=[word rangeOfString:letter];
-    while(r.length>0){
-        error=NO;
-        [found replaceObjectAtIndex:r.location withObject:yes];
-        NSInteger start=r.location+r.length;
-        NSRange searchRange=NSMakeRange(start,length-start);
-        r=[word rangeOfString:letter options:NSCaseInsensitiveSearch range:searchRange];
-    }
-    if(error){
-        if(currentErrorCount<maximumErrorCount){
-            currentErrorCount++;
-        }
-    }
-    if(currentErrorCount>=maximumErrorCount){
-        return(Hangman_loses);
-    }
-    if(![found containsObject:no]){
-        return(Hangman_wins);
-    }
-    if(error) {
-        return(Hangman_badGuess);
-    }else{
-        return(Hangman_newGuessedWord);
-    }
-}
-
--(NSInteger)errorCount
-{
-    return(currentErrorCount);
-}
-
--(NSString*)alphabet
-{
-    return(alphabet);
-}
-
-@end
-//// THE END ////
diff --git a/sources/generate-library.lisp b/sources/generate-library.lisp
new file mode 100644
index 0000000..4f3e939
--- /dev/null
+++ b/sources/generate-library.lisp
@@ -0,0 +1,2 @@
+(compile-file "sources/hangman.lisp" :system-p t)
+(c:build-static-library "hangman" :lisp-files '("sources/hangman.o"))
diff --git a/sources/hangman.lisp b/sources/hangman.lisp
index 45fcf70..23b0349 100644
--- a/sources/hangman.lisp
+++ b/sources/hangman.lisp
@@ -92,6 +92,8 @@
         (let ((error t))
           (push letter (hangman-tried-letters game))
           (loop
+            :with word = (hangman-word game)
+            :with found = (hangman-found game)
             :for i :below (length word)
             :do (when (and (not (aref found i))
                            (char-equal letter (aref word i)))
@@ -108,14 +110,14 @@
             ((every (function identity) (hangman-found game))
              +wins+)
             (error
-             +bad-guess)
+             +bad-guess+)
             (t
              +new-guessed-word+))))))

 (defun error-count (game)
   (hangman-current-error-count game))

-(defun alphabent (game)
+(defun alphabet (game)
   (hangman-alphabet game))

 ;;;; THE END ;;;;
ViewGit