Sudoku-0.7004075500017500000144000000000001161000177200120135ustar multixusersSudoku-0.7/Resources004075500017500000144000000000001157605321700140015ustar multixusersSudoku-0.7/Resources/Sudoku.tiff010064400017500000144000000160601157317166200162060ustar multixusersII*$$$%%%$%$$%$$%$$%$$%$$%$$%$$%$$%$$%$$%$'(' ((($$$$%$$%$$%$$%$$%$$%$$%$$%$$%$$%$$%$'(' ((($$$$%$$%$$%$$%$$%$$%$$%$$%$$%$$%$%%%$$$$$$TVTTVT$$$%%%WXWWXW%%%$%$VWVVWV$%$$%$ʮVWV糶VWV$%$$%$WXW wywVWV lolVWV>@>$%$$%$  VWVOQO)*)~~VWV797232$%$$%$VWVDFDBDBVWVOQOQQQ&'&$%$$%$cdc(*(VWVgkg]`]VWV>@>???+++$%$$%$ VWVVWVMOM)*) $%$$%$VWVLMLܑVWV&&&$%$$%$z}z VWV"$"jljVWV???+++$%$$%$VWVVWV$%$$%$UVUUVU$%$%%%YYYYYY%%%bcb676bcb676 TVTWXWVWVVWVVWVVWVVWVVWVVWVVWVVWVVWVUVU]^]676]_]UVUVWVVWVVWVVWVVWVVWVVWVVWVVWVVWVUVU]^]676]_]UVUVWVVWVVWVVWVVWVVWVVWVVWVVWVVWVWXWTVT %%%YYYYYY%%%$$$UVUUVU$$$$%$VWVVWV$%$$%$񸼸VWVVWVȶ$%$$%$)+){}{VWVVWVVYV $%$$%$oqo祩VWV()(VWVuwu$%$$%$OPO!!!VWV 9;9#$#VWVacaZ\Z$%$$%$lnlJLJVWV353SUSVWVTVT}}$%$$%$787pspVWVVWVZ\Z ! #$#KMK$%$$%$VXVꈋ VWVWZW&(&~~VWV$%$$%$VWVVWV[^[JLJ$%$$%$VWVVWV$%$$%$UVUUVU$%$%%%YYYYYY%%%bcb676bcb676 TVTWXWVWVVWVVWVVWVVWVVWVVWVVWVVWVVWVUVU]^]676]_]UVUVWVVWVVWVVWVVWVVWVVWVVWVVWVVWVUVU]^]676]_]UVUVWVVWVVWVVWVVWVVWVVWVVWVVWVVWVWXWTVT %%%YYYYYY%%%$$$UVUUVU$$$$%$VWVVWV$%$$%$붺VWV󺽺VWV$%$$%$ ! PSPVWV575lnlVWVuxu$%$$%$cec겵VWVVWV"#"$%$$%$VWV)+)gigILIVWVPQP$%$$%$#$#898VWV;=; MOMVWV___$%$$%$acaVWVWYWVWV\]\$%$$%$^`^VWVjljʒVWV\^\$%$$%$dgd VWV898klkVWV\^\$%$$%$VWVVWV$%$%%%WXWWXW%%%$$$TVTTVT$$$$$$%%%$%$$%$$%$$%$$%$$%$$%$$%$$%$$%$$%$'(' ((($$$$%$$%$$%$$%$$%$$%$$%$$%$$%$$%$$%$'(' ((($$$$%$$%$$%$$%$$%$$%$$%$$%$$%$$%$%%%$$$00 K@ ((/home/multix/gnustep-cvs/gap/user-apps/Games/Sudoku6/Resources/Sudoku.tiffHHSudoku-0.7/DigitSource.h010064400017500000144000000023201157337726500145030ustar multixusers/* Project: Sudoku DigitSource.h Copyright (C) 2007-2011 The Free Software Foundation, Inc Author: Marko Riedel This application 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 3 of the License, or (at your option) any later version. This application 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 Library General Public License for more details. You should have received a copy of the GNU General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #import #import #define DIGIT_TYPE @"Digit" #define DIGIT_FIELD_DIM 40 #define DIGIT_FONT_SIZE 24 @interface DigitSource : NSView { int digit; } - initAtPoint:(NSPoint)loc withDigit:(int)dval; - (unsigned int)draggingSourceOperationMaskForLocal:(BOOL)flag; - makeDragImages; - (void)mouseDown:(NSEvent *)theEvent; @end Sudoku-0.7/ChangeLog010064400017500000144000000023121160777144000136530ustar multixusers2011-07-12 Riccardo Mottola * Controller.m * main.m Windows port 2011-06-20 Riccardo Mottola * SudokuView.m * Sudoku.m * main.m C89 fixes and code cleanup 2011-06-16 Riccardo Mottola * Controller.m Fix new game. * Controller.m Code cleanup. 2011-06-15 Riccardo Mottola * Document.m Fix warning and reorganize code. * Controller.m * DigitSource.m * Document.m * SudokuView.m C99 fixes and code tidy up. 2011-06-07 Riccardo Mottola * Controller.h * DigitSource.h * Document.h * Document.m * KnobView.h * KnobView.m * Sudoku.h * SudokuView.h * SudokuView.m Organized imports better. 2011-06-07 Riccardo Mottola * Controller.h * Controller.m * DigitSource.h * DigitSource.m * Document.h * Document.m * KnobView.h * KnobView.m * Sudoku.h * Sudoku.m * SudokuInfo.plist * SudokuView.h * SudokuView.m * main.m * Sudoku.pcproj/PC.project Put boiler plate on each file. 2011-06-07 Riccardo Mottola * Controller.m include instead of import system header. 2011-06-06 Riccardo Mottola * Resources/Sudoku.tiff Adjusted resolution. Imported. Icons renamed to Resources Sudoku-0.7/Controller.h010064400017500000144000000030131157337726500144050ustar multixusers/* Project: Sudoku Controller.h Copyright (C) 2007-2011 The Free Software Foundation, Inc Author: Marko Riedel This application 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 3 of the License, or (at your option) any later version. This application 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 Library General Public License for more details. You should have received a copy of the GNU General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #import #import #import #import "SudokuView.h" typedef enum { MENU_NEW_20CLUES = 20, MENU_NEW_25CLUES = 25, MENU_NEW_30CLUES = 30, MENU_NEW_35CLUES = 35, MENU_NEW_48CLUES = 48, MENU_NEW_60CLUES = 60, MENU_NEW_70CLUES = 70, } MENU_NEW; @interface Controller: NSObject { NSPanel *palette; NSPanel *enterPanel; SudokuView *sdkview; } - makeInputPanel; - newPuzzle:(id)sender; - actionEnter:(id)sender; - actionReset:(id)sender; - actionCancel:(id)sender; - enterPuzzle:(id)sender; -(void)applicationDidFinishLaunching:(NSNotification *)aNotification; - makeDigitPalette; @end Sudoku-0.7/patch1010064400017500000144000000120041157634051000131760ustar multixusers--- Controller.m 2011-06-16 10:35:03.000000000 +0200 +++ /home/multix/Desktop/Controller.m 2011-06-16 10:38:09.000000000 +0200 @@ -42,9 +42,11 @@ + (NSPanel *)prog_ind { - if(_prog_ind_panel==nil){ + if(_prog_ind_panel==nil) + { NSRect pi_frame = NSMakeRect(0, 0, PROG_IND_WIDTH, PROG_IND_HEIGHT); + KnobView *_prog_ind; _prog_ind_panel = [[NSPanel alloc] @@ -54,8 +56,7 @@ defer:NO]; [_prog_ind_panel setReleasedWhenClosed:NO]; - KnobView *_prog_ind = - [[KnobView alloc] initWithFrame:pi_frame]; + _prog_ind = [[KnobView alloc] initWithFrame:pi_frame]; [_prog_ind_panel setContentView:_prog_ind]; [_prog_ind_panel setTitle:_(@"Computing Sudoku")]; @@ -184,12 +188,14 @@ - makeInputPanel { int m = NSTitledWindowMask; - - NSRect frame = - {{ 0, BUTTON_HEIGHT + DIGIT_FIELD_DIM}, { SDK_DIM, SDK_DIM} }; + int x; + float margin; + NSButton *button; + NSRect allframe ; + NSRect frame = {{ 0, BUTTON_HEIGHT + DIGIT_FIELD_DIM}, { SDK_DIM, SDK_DIM} }; sdkview = [[SudokuView alloc] initWithFrame:frame]; - NSRect allframe = frame; + allframe = frame; allframe.size.height += BUTTON_HEIGHT + DIGIT_FIELD_DIM; enterPanel = @@ -202,10 +208,9 @@ [[enterPanel contentView] addSubview:sdkview]; - float margin = (SDK_DIM - DIGIT_FIELD_DIM*10)/2; + margin = (SDK_DIM - DIGIT_FIELD_DIM*10)/2; assert(margin>0); - int x; for(x=1; x<=10; x++){ DigitSource *dgs = [[DigitSource alloc] @@ -216,13 +221,12 @@ } - NSButton *button = [NSButton new]; + button = [NSButton new]; [button setTitle:_(@"Enter")]; [button setTarget:self]; [button setAction:@selector(actionEnter:)]; - [button - setFrame:NSMakeRect(0, 0, SDK_DIM/3, BUTTON_HEIGHT)]; + [button setFrame:NSMakeRect(0, 0, SDK_DIM/3, BUTTON_HEIGHT)]; [[enterPanel contentView] addSubview:button]; @@ -231,8 +235,7 @@ [button setTarget:self]; [button setAction:@selector(actionReset:)]; - [button - setFrame:NSMakeRect(SDK_DIM/3, 0, SDK_DIM/3, BUTTON_HEIGHT)]; + [button setFrame:NSMakeRect(SDK_DIM/3, 0, SDK_DIM/3, BUTTON_HEIGHT)]; [[enterPanel contentView] addSubview:button]; @@ -241,8 +244,7 @@ [button setTarget:self]; [button setAction:@selector(actionCancel:)]; - [button - setFrame:NSMakeRect(2*SDK_DIM/3, 0, SDK_DIM/3, BUTTON_HEIGHT)]; + [button setFrame:NSMakeRect(2*SDK_DIM/3, 0, SDK_DIM/3, BUTTON_HEIGHT)]; [[enterPanel contentView] addSubview:button]; @@ -255,40 +257,50 @@ - actionEnter:(id)sender { - [[NSApplication sharedApplication] - stopModal]; + BOOL success; + NSDocumentController *dc; + Document *doc; + Sudoku *sdk; + Sudoku *user; + NSPanel *pi_panel; + KnobView *pi; + NSModalSession solveSession; + float percent, dir; + NSDate *end; + + [[NSApplication sharedApplication] stopModal]; [enterPanel orderOut:self]; [palette orderFront:self]; - NSApplication *app = [NSApplication sharedApplication]; - - NSDocumentController *dc = - [NSDocumentController sharedDocumentController]; + dc = [NSDocumentController sharedDocumentController]; [dc newDocument:self]; - Document *doc = [dc currentDocument]; - Sudoku *sdk = [doc sudoku], *user = [sdkview sudoku]; + doc = [dc currentDocument]; + sdk = [doc sudoku]; + user = [sdkview sudoku]; [sdk copyStateFromSource:user]; [sdk guessToClues]; // [sdk cluesToPuzzle]; - NSPanel *pi_panel = [Controller prog_ind]; - KnobView *pi = [pi_panel contentView]; + pi_panel = [Controller prog_ind]; + pi = [pi_panel contentView]; [pi_panel makeKeyAndOrderFront:self]; - NSModalSession solveSession; - solveSession = [app beginModalSessionForWindow:pi_panel]; + solveSession = [[NSApplication sharedApplication] beginModalSessionForWindow:pi_panel]; - float percent = 0, dir = 1; + percent = 0; + dir = 1; - BOOL success; - NSDate *end = [NSDate dateWithTimeIntervalSinceNow:MAX_SOLVE_SECS]; + end = [NSDate dateWithTimeIntervalSinceNow:MAX_SOLVE_SECS]; + success = NO; do { int tick; + NSDate *now; + for(tick=0; tick #import #import "DigitSource.h" @implementation DigitSource : NSView static NSImage *dragImages[10] = { nil, nil, nil, nil, nil, nil, nil, nil, nil, nil }; - initAtPoint:(NSPoint)loc withDigit:(int)dval { NSRect frame = { { loc.x, loc.y }, { DIGIT_FIELD_DIM, DIGIT_FIELD_DIM } }; [super initWithFrame:frame]; digit = dval; if(dragImages[0]==nil){ [self makeDragImages]; } return self; } - (unsigned int)draggingSourceOperationMaskForLocal:(BOOL)flag { return NSDragOperationCopy; } - makeDragImages { int dg; NSBezierPath *bnds; NSFont *font; NSDictionary *attrDict; for(dg=1; dg<=10; dg++){ NSImage *img; char str[2] = { (dg==10 ? '.' : '0' + dg), 0 }; NSString *strObj; NSSize strSize; NSPoint loc; img = [[NSImage alloc] initWithSize:NSMakeSize(DIGIT_FIELD_DIM, DIGIT_FIELD_DIM)]; RETAIN(img); [img lockFocus]; bnds = [NSBezierPath bezierPathWithRect:[self bounds]]; [[NSColor whiteColor] set]; [bnds fill]; [[NSColor blackColor] set]; [bnds setLineWidth:4.0]; [bnds stroke]; font = [NSFont boldSystemFontOfSize:DIGIT_FONT_SIZE]; attrDict = [NSDictionary dictionaryWithObjectsAndKeys: font, NSFontAttributeName, [NSColor blueColor], NSForegroundColorAttributeName, nil]; [font set]; strObj = [NSString stringWithCString:str]; strSize = [strObj sizeWithAttributes:attrDict]; loc = NSMakePoint((DIGIT_FIELD_DIM-strSize.width)/2, (DIGIT_FIELD_DIM-strSize.height)/2); [strObj drawAtPoint:loc withAttributes:attrDict]; [img unlockFocus]; dragImages[dg-1] = img; } return self; } - (void)drawRect:(NSRect)aRec { [dragImages[digit-1] compositeToPoint:NSMakePoint(0, 0) operation:NSCompositeCopy]; } - (void)mouseDown:(NSEvent *)theEvent { if([theEvent type]==NSLeftMouseDown){ NSPasteboard *pboard = [NSPasteboard pasteboardWithName:NSDragPboard]; [pboard declareTypes: [NSArray arrayWithObjects:DIGIT_TYPE, nil] owner:self]; [pboard setString: [NSString stringWithFormat:@"%d", digit] forType:DIGIT_TYPE]; [self dragImage:dragImages[digit-1] at:NSMakePoint(0, 0) offset:NSMakeSize(0, 0) event:theEvent pasteboard:pboard source:self slideBack:YES]; } return; } @end Sudoku-0.7/Document.h010064400017500000144000000026631157337726500140520ustar multixusers/* Project: Sudoku Document.h Copyright (C) 2007-2011 The Free Software Foundation, Inc Author: Marko Riedel This application 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 3 of the License, or (at your option) any later version. This application 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 Library General Public License for more details. You should have received a copy of the GNU General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #import #import #import @class Sudoku; @class SudokuView; #define DOCTYPE @"sudoku" @interface Document : NSDocument { SudokuView *sdkview; NSArray *lines; } - init; - (NSData *)dataRepresentationOfType:(NSString *)aType; - (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType; - (void)makeWindowControllers; - (void)windowControllerDidLoadNib:(NSWindowController *)aController; - (Sudoku *)sudoku; - (SudokuView *)sudokuView; - resetPuzzle:(id)sender; - solvePuzzle:(id)sender; @end Sudoku-0.7/Document.m010064400017500000144000000105511157632724500140460ustar multixusers/* Project: Sudoku Document.m Copyright (C) 2007-2011 The Free Software Foundation, Inc Author: Marko Riedel This application 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 3 of the License, or (at your option) any later version. This application 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 Library General Public License for more details. You should have received a copy of the GNU General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #import #import "SudokuView.h" #import "Document.h" @interface Document (Private) - (NSWindow*)makeWindow; @end @implementation Document - init { [super init]; sdkview = nil; lines = nil; return self; } - (NSData *)dataRepresentationOfType:(NSString *)aType { if([aType isEqualToString:DOCTYPE]) { NSString *all; [[sdkview window] saveFrameUsingName:[self fileName]]; all = [NSString stringWithFormat:@"%@\n%@\n%@\n%@\n", [[sdkview sudoku] stateToString:FIELD_VALUE], [[sdkview sudoku] stateToString:FIELD_PUZZLE], [[sdkview sudoku] stateToString:FIELD_GUESS], [[sdkview sudoku] stateToString:FIELD_SCORE]]; return [all dataUsingEncoding:NSASCIIStringEncoding]; } else { NSString *msg = [NSString stringWithFormat: @"Unknown type: %@", [aType uppercaseString]]; NSRunAlertPanel(@"Alert", msg, @"Ok", nil, nil); return nil; } } - (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType { if([aType isEqualToString:DOCTYPE]) { lines = [[NSString stringWithCString:[data bytes] length:[data length]] componentsSeparatedByString:@"\n"]; RETAIN(lines); } else { NSString *msg = [NSString stringWithFormat: @"Unknown type: %@", [aType uppercaseString]]; NSRunAlertPanel(@"Alert", msg, @"Ok", nil, nil); return NO; } return YES; } - (void) makeWindowControllers { NSWindowController *controller; NSWindow *win = [self makeWindow]; controller = [[NSWindowController alloc] initWithWindow: win]; RELEASE (win); [self addWindowController: controller]; RELEASE(controller); // We have to do this ourself, as there is currently no nib file // [controller setShouldCascadeWindows:NO]; [self windowControllerDidLoadNib: controller]; [win setFrameAutosaveName:[self fileName]]; if([win setFrameUsingName:[self fileName]]==NO){ [win center]; } [win orderFrontRegardless]; [win makeKeyWindow]; [win display]; } - (void)windowControllerDidLoadNib:(NSWindowController *)aController; { NSEnumerator *en; [super windowControllerDidLoadNib:aController]; en = [lines objectEnumerator]; if(lines != nil){ [[sdkview sudoku] stateFromLineEnumerator:en what:FIELD_VALUE]; [[sdkview sudoku] stateFromLineEnumerator:en what:FIELD_PUZZLE]; [[sdkview sudoku] stateFromLineEnumerator:en what:FIELD_GUESS]; [[sdkview sudoku] stateFromLineEnumerator:en what:FIELD_SCORE]; RELEASE(lines); lines = nil; } } - (Sudoku *)sudoku { return [sdkview sudoku]; } - (SudokuView *)sudokuView { return sdkview; } - resetPuzzle:(id)sender { [sdkview reset]; [self updateChangeCount:NSChangeDone]; return self; } - solvePuzzle:(id)sender { [sdkview loadSolution]; [self updateChangeCount:NSChangeDone]; return self; } @end @implementation Document (Private) - (NSWindow*)makeWindow { NSWindow *window; int m = (NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask); NSRect frame = {{ 0, 0}, {SDK_DIM, SDK_DIM} }; sdkview = [[SudokuView alloc] initWithFrame:frame]; frame = [sdkview frame]; // just in case window = [[NSWindow alloc] initWithContentRect:frame styleMask:m backing: NSBackingStoreRetained defer:YES]; [window setDelegate:self]; [window setContentView:sdkview]; [window setReleasedWhenClosed:YES]; [self setFileType:DOCTYPE]; return window; } @end Sudoku-0.7/GNUmakefile010064400017500000144000000017001157632724500141600ustar multixusers# # GNUmakefile - Generated by ProjectCenter # ifeq ($(GNUSTEP_MAKEFILES),) GNUSTEP_MAKEFILES := $(shell gnustep-config --variable=GNUSTEP_MAKEFILES 2>/dev/null) endif ifeq ($(GNUSTEP_MAKEFILES),) $(error You need to set GNUSTEP_MAKEFILES before compiling!) endif include $(GNUSTEP_MAKEFILES)/common.make # # Application # VERSION = 0.7 PACKAGE_NAME = Sudoku APP_NAME = Sudoku Sudoku_APPLICATION_ICON = Sudoku.tiff # # Resource files # Sudoku_RESOURCE_FILES = \ Resources/Sudoku.tiff \ # # Header files # Sudoku_HEADER_FILES = \ Controller.h \ DigitSource.h \ Document.h \ KnobView.h \ Sudoku.h \ SudokuView.h # # Class files # Sudoku_OBJC_FILES = \ Controller.m \ DigitSource.m \ Document.m \ KnobView.m \ Sudoku.m \ SudokuView.m # # Other sources # Sudoku_OBJC_FILES += \ main.m # # Makefiles # -include GNUmakefile.preamble include $(GNUSTEP_MAKEFILES)/aggregate.make include $(GNUSTEP_MAKEFILES)/application.make -include GNUmakefile.postamble Sudoku-0.7/SudokuInfo.plist010064400017500000144000000013261157632724500152550ustar multixusers{ ApplicationDescription = "Sudoku game"; ApplicationIcon = "Sudoku.tiff"; ApplicationName = Sudoku; ApplicationRelease = "0.7"; Authors = ( "Marko Riedel " ); Copyright = "Copyright (C) 2007-2011 Free Software Foundation, Inc."; CopyrightDescription = "Released under GPL v3 or later"; FullVersionID = "0.7"; NSExecutable = Sudoku; NSIcon = "Sudoku.tiff"; NSPrincipalClass = NSApplication; NSRole = Application; NSTypes = ( { NSDocumentClass = Document; NSHumanReadableName = "SUDOKU Document"; NSName = sudoku; NSRole = Editor; NSUnixExtensions = ( sdk ); } ); URL = "http://gap.nongnu.org/sudoku/"; }Sudoku-0.7/KnobView.h010064400017500000144000000020431157337726500140100ustar multixusers/* Project: Sudoku KnobView.h Copyright (C) 2007-2011 The Free Software Foundation, Inc Author: Marko Riedel This application 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 3 of the License, or (at your option) any later version. This application 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 Library General Public License for more details. You should have received a copy of the GNU General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #import #import @interface KnobView : NSView { float percent; } - (float)percent; - setPercent:(float)pval; - (void)drawRect:(NSRect)aRect; @end Sudoku-0.7/KnobView.m010064400017500000144000000033621157337726500140220ustar multixusers/* Project: Sudoku KnobView.m Copyright (C) 2007-2011 The Free Software Foundation, Inc Author: Marko Riedel This application 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 3 of the License, or (at your option) any later version. This application 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 Library General Public License for more details. You should have received a copy of the GNU General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #import #import "KnobView.h" @implementation KnobView - (float)percent { return percent; } - setPercent:(float)pval { NSAssert(pval>=0.0 && pval<=100.0, @"not a percentage"); percent = pval; return self; } - (void)drawRect:(NSRect)aRect { NSRect frame = [self frame]; float radius = frame.size.height/3.0; NSPoint center = { percent*frame.size.width/100.0, frame.size.height/2.0 }; [[NSColor whiteColor] set]; PSrectfill(0, 0, frame.size.width, frame.size.height); [[NSColor blueColor] set]; if(center.xframe.size.width-radius){ center.x = frame.size.width-radius; } PSarc(center.x, center.y, radius, 0, 360); PSfill(); [[NSColor blackColor] set]; PSsetlinewidth(4); PSrectstroke(0, 0, frame.size.width, frame.size.height); } @end Sudoku-0.7/Sudoku.h010064400017500000144000000044571157337726500135510ustar multixusers/* Project: Sudoku Sudoku.h Copyright (C) 2007-2011 The Free Software Foundation, Inc Author: Marko Riedel This application 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 3 of the License, or (at your option) any later version. This application 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 Library General Public License for more details. You should have received a copy of the GNU General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #import #define NBCOUNT (8+8+4) #define EX_COMPLETE @"SudokuCompleted" #define EX_LOOP @"SudokuLoop" #define EX_COMPLETE_FMT @"Sudoku completed." #define EX_LOOP_FMT @"Solver entered a loop." typedef enum { FIELD_VALUE = 0, FIELD_PUZZLE, FIELD_GUESS, FIELD_SCORE } FIELD_TYPE; typedef struct _field { int value, puzzle, guess; int x, y; void *nbdigits[9]; int score; struct { int nx, ny; } adj[NBCOUNT]; } field, *fieldptr; #define SDK_DIM (9*FIELD_DIM) typedef struct { int x, y, checked; } seqstruct; typedef struct { int x, y; int value; } cluestruct; @interface Sudoku : NSObject { field data[9][9]; seqstruct seq[9*9]; BOOL success; int placed; int allclues; cluestruct clues[9*9]; } - init; - (seqstruct)seq:(int)pos; - (cluestruct)clue:(int)pos; - (int)retrX:(int)x Y:(int)y; - (int)valueX:(int)x Y:(int)y; - (int)puzzleX:(int)x Y:(int)y; - (int)guessX:(int)x Y:(int)y; - (field)fieldX:(int)x Y:(int)y; - (fieldptr)fieldptrX:(int)x Y:(int)y; - (int)computescore:(fieldptr)fp; - (BOOL)completed; - (NSString *)stateToString:(FIELD_TYPE)what; - stateFromLineEnumerator:(NSEnumerator *)en what:(FIELD_TYPE)what; - (BOOL)selectClues; - (BOOL)find; - doFind:(NSMutableSet *)seen; - (NSString *)checkSequence; - (int)setClues:(int)count; - (int)clues; - reset; - loadSolution; - copyStateFromSource:(Sudoku *)src; - guessToClues; - cluesToPuzzle; @end Sudoku-0.7/Sudoku.m010064400017500000144000000254011160777144000135350ustar multixusers/* Project: Sudoku Sudoku.m Copyright (C) 2007-2011 The Free Software Foundation, Inc Author: Marko Riedel This application 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 3 of the License, or (at your option) any later version. This application 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 Library General Public License for more details. You should have received a copy of the GNU General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #import "Sudoku.h" #import "DigitSource.h" #ifdef __MINGW__ #define srand48 srand #define lrand48 rand #endif @implementation Sudoku - (int)computescore:(fieldptr)fp { int d, res = 0; for(d=0; d<9; d++){ if(fp->nbdigits[d] != NULL){ res++; } } fp->score = res; return res; } #define RETR(_x, _y) \ (data[_x][_y].puzzle==-1 ? data[_x][_y].guess : data[_x][_y].puzzle) - (int)retrX:(int)x Y:(int)y { return (data[x][y].puzzle==-1 ? data[x][y].guess : data[x][y].puzzle); } - (BOOL)completed { int x, y; for(x=0; x<9; x++){ for(y=0; y<9; y++){ if(RETR(x, y)==-1){ return NO; } } } return YES; } - init { int x, y, pos; allclues = 0; for(x=0; x<9; x++) { for(y=0; y<9; y++) { data[x][y].value = -1; data[x][y].guess = -1; data[x][y].puzzle = -1; } } // adjaceny for(x=0; x<9; x++){ for(y=0; y<9; y++){ int n = 0; int zx, zy; for(pos=0; pos<9; pos++){ if(pos!=y){ data[x][y].adj[n].nx = x; data[x][y].adj[n].ny = pos; n++; } } for(pos=0; pos<9; pos++){ if(pos!=x){ data[x][y].adj[n].nx = pos; data[x][y].adj[n].ny = y; n++; } } zx = x/3; zy = y/3; for(pos=0; pos<9; pos++){ int zzx = 3*zx + pos/3, zzy = 3*zy + pos%3; if(zzx!=x && zzy!=y){ data[x][y].adj[n].nx = zzx; data[x][y].adj[n].ny = zzy; n++; } } assert(n == NBCOUNT); } } return self; } - (int)valueX:(int)x Y:(int)y { return data[x][y].value; } - (int)puzzleX:(int)x Y:(int)y { return data[x][y].puzzle; } - (int)guessX:(int)x Y:(int)y { return data[x][y].guess; } - (field)fieldX:(int)x Y:(int)y { return data[x][y]; } - (fieldptr)fieldptrX:(int)x Y:(int)y { return &(data[x][y]); } - (seqstruct)seq:(int)pos { return seq[pos]; } - (cluestruct)clue:(int)pos { return clues[pos]; } - (NSString *)stateToString:(FIELD_TYPE)what { NSString *res = @""; int x, y; for(y=0; y<9; y++){ for(x=0; x<9; x++){ int outval; if(what==FIELD_VALUE){ outval = data[x][y].value; } else if(what==FIELD_PUZZLE){ outval = data[x][y].puzzle; } else if(what==FIELD_GUESS){ outval = data[x][y].guess; } else{ [self computescore:&(data[x][y])]; outval = data[x][y].score; } res = [res stringByAppendingFormat: (x>0 ? @" %c" : @"%c"), (outval==-1 ? '.' : ((what==FIELD_SCORE ? '0' : '1') + outval))]; } res = [res stringByAppendingString:@"\n"]; } return res; } - stateFromLineEnumerator:(NSEnumerator *)en what:(FIELD_TYPE)what { int x, y; for(y=0; y<9; y++){ NSString *line = [en nextObject]; NSArray *fields = [line componentsSeparatedByString:@" "]; NSEnumerator *fieldenum = [fields objectEnumerator]; for(x=0; x<9; x++){ NSString *field = [fieldenum nextObject]; NSScanner *scn = [NSScanner scannerWithString:field]; int inval = -1; if([field isEqualToString:@"."]==NO){ [scn scanInt:&inval]; } if(what==FIELD_VALUE){ data[x][y].value = inval-1; } else if(what==FIELD_PUZZLE){ data[x][y].puzzle = (inval==-1 ? -1 : inval-1); } else if(what==FIELD_GUESS){ data[x][y].guess = (inval==-1 ? -1 : inval-1); } else{ data[x][y].score = inval; } } } // skip separator // NSLog(@"sep <%@>", [en nextObject]); [en nextObject]; return self; } #define RAND_DIST 35 - (BOOL)selectClues { int pos, x, y, randpl = 0; BOOL initial[9][9]; int present[9]; for(x=0; x<9; x++){ for(y=0; y<9; y++){ initial[x][y] = NO; } } while(randpl=8){ return NO; } } for(y=0; y<9; y++){ int count = 0; for(pos=0; pos<9; pos++){ if(initial[pos][y]==YES){ count++; } } if(count>=8){ return NO; } } for(x=0; x<3; x++){ for(y=0; y<3; y++){ int e, f, count = 0; for(e=0; e<3; e++){ for(f=0; f<3; f++){ if(initial[3*x+e][3*y+f]==YES){ count++; } } } if(count>=8){ return NO; } } } } randpl=0; while(randplscore < bp->score){ return +1; } else if(ap->score > bp->score){ return -1; } return 0; } - doFind:(NSMutableSet *)seen { NSString *dataStr = [self stateToString:FIELD_VALUE]; int rest; fieldptr buf[9*9]; fieldptr *bPtr; int x, y; int score; int range; int mx; int pos, d; if(placed==9*9){ // NSLog(@"--\n%@", dataStr); // NSLog(@"--\n%@", scoreStr); [NSException raise:EX_COMPLETE format:EX_COMPLETE_FMT]; return self; // not reached } if([seen containsObject:dataStr]==YES){ [NSException raise:EX_LOOP format:EX_LOOP_FMT]; return self; // not reached } [seen addObject:dataStr]; rest = 9*9-placed; bPtr = buf; for(x=0; x<9; x++){ for(y=0; y<9; y++){ fieldptr loc = &(data[x][y]); [self computescore:loc]; if(data[x][y].value == -1){ *bPtr++ = loc; } } } qsort(buf, rest, sizeof(fieldptr), comparefieldptrs); // NSLog(@"--\n%@", dataStr); // NSLog(@"--\n%@", scoreStr); score = buf[0]->score; range = 1; mx = 0; while(rangescore==score){ range++; } if(range>1){ // permute for(mx=range; mx>1; mx--){ int ind = lrand48() % mx; fieldptr tmp; tmp = buf[ind]; buf[ind] = buf[mx-1]; buf[mx-1] = tmp; } } for(pos=0; posx, y = fp->y; for(d=0; d<9; d++){ if(fp->nbdigits[d]==NULL){ int nb; seq[placed].x = x; seq[placed].y = y; seq[placed].checked++; placed++; data[x][y].value = d; for(nb=0; nb #import #import #import "Sudoku.h" #define FIELD_DIM 54 #define FONT_SIZE 36 #define MARKUP_SIZE 10 @interface SudokuView : NSView { Sudoku *sdk; } - initWithFrame:(NSRect)frame; - (Sudoku *)sudoku; - reset; - loadSolution; - (void)drawMarkupAtX:(int)x andY:(int)y; - (void)drawString:(char *)str atX:(int)x andY:(int)y color:(NSColor *)col; - (void)drawRect:(NSRect)rect; - (void)mouseDown:(NSEvent *)theEvent; - (unsigned int)draggingEntered:(id )sender; - (unsigned int)draggingUpdated:(id )sender; - (BOOL)performDragOperation:(id )sender; - (BOOL)prepareForDragOperation:(id )sender; @end Sudoku-0.7/Sudoku.pcproj004075500017500000144000000000001157632724500146025ustar multixusersSudoku-0.7/Sudoku.pcproj/PC.project010064400017500000144000000040461157632724500165540ustar multixusers{ APPLICATIONICON = "Sudoku.tiff"; "APP_DOCUMENT_BASED" = YES; "APP_TYPE" = GORM; "BUILDER_TARGETS" = ( all, install, uninstall, clean, distclean, dist ); "CLASS_FILES" = ( "Controller.m", "DigitSource.m", "Document.m", "KnobView.m", "Sudoku.m", "SudokuView.m" ); COMPILEROPTIONS = ""; CPPOPTIONS = ""; "CREATION_DATE" = "2011-06-06 12:33:50 +0200"; "DOCU_FILES" = ( ); FRAMEWORKS = ( ); "HEADER_FILES" = ( "Controller.h", "DigitSource.h", "Document.h", "KnobView.h", "Sudoku.h", "SudokuView.h" ); IMAGES = ( "Sudoku.tiff" ); INSTALLDIR = "$(HOME)/GNUstep"; INTERFACES = ( ); LANGUAGE = English; LIBRARIES = ( "gnustep-base", "gnustep-gui" ); LINKEROPTIONS = ""; "LOCALIZED_RESOURCES" = ( ); MAININTERFACE = ""; MAKEFILEDIR = "$(GNUSTEP_MAKEFILES)"; "OBJC_COMPILEROPTIONS" = ""; "OTHER_RESOURCES" = ( ); "OTHER_SOURCES" = ( "main.m" ); "PRINCIPAL_CLASS" = NSApplication; "PROJECT_AUTHORS" = ( "Marko Riedel " ); "PROJECT_COPYRIGHT" = "Copyright (C) 2007-2011 Free Software Foundation, Inc."; "PROJECT_COPYRIGHT_DESC" = "Released under GPL v3 or later"; "PROJECT_CREATOR" = "Riccardo,,,"; "PROJECT_DESCRIPTION" = "Sudoku game"; "PROJECT_DOCUMENTTYPES" = ( { NSDocumentClass = Document; NSHumanReadableName = "SUDOKU Document"; NSName = sudoku; NSRole = Editor; NSUnixExtensions = ( sdk ); } ); "PROJECT_GROUP" = "No group avaliable!"; "PROJECT_MAINTAINER" = "Riccardo,,,"; "PROJECT_NAME" = Sudoku; "PROJECT_RELEASE" = "0.7"; "PROJECT_SUMMARY" = "No summary avaliable!"; "PROJECT_TYPE" = Application; "PROJECT_URL" = "http://gap.nongnu.org/sudoku/"; "SEARCH_HEADER_DIRS" = ( ); "SEARCH_LIB_DIRS" = ( ); SUBPROJECTS = ( ); "SUPPORTING_FILES" = ( "GNUmakefile.preamble", GNUmakefile, "GNUmakefile.postamble", "SudokuInfo.plist" ); "USER_LANGUAGES" = ( English ); }Sudoku-0.7/main.m010064400017500000144000000114211160777144000132040ustar multixusers/* Project: Sudoku main.m Copyright (C) 2007-2011 The Free Software Foundation, Inc Author: Marko Riedel This application 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 3 of the License, or (at your option) any later version. This application 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 Library General Public License for more details. You should have received a copy of the GNU General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #import #import #import "Controller.h" #ifdef __MINGW__ #define srand48 srand #endif time_t time(time_t *t); int main(int argc, const char **argv, char** env) { NSAutoreleasePool *pool; NSApplication *app; NSMenu *mainMenu, *menu; NSMenuItem *menuItem; NSMenu *file; Controller *controller; pool = [NSAutoreleasePool new]; app = [NSApplication sharedApplication]; // // Create the Menu // // Main Menu mainMenu = AUTORELEASE ([NSMenu new]); // Info SubMenu menuItem = (NSMenuItem *)[mainMenu addItemWithTitle: @"Info" action: NULL keyEquivalent: @""]; menu = AUTORELEASE ([NSMenu new]); [mainMenu setSubmenu: menu forItem: menuItem]; [menu addItemWithTitle: @"Info Panel..." action: @selector (orderFrontStandardInfoPanel:) keyEquivalent: @""]; [menu addItemWithTitle: @"Preferences..." action: @selector (runPreferencesPanel:) keyEquivalent: @""]; [menu addItemWithTitle: @"Help..." action: @selector (orderFrontHelpPanel:) keyEquivalent: @"?"]; // Create the file submenu file = [NSMenu new]; menuItem = (NSMenuItem *)[mainMenu addItemWithTitle: @"File" action: NULL keyEquivalent: @""]; [mainMenu setSubmenu:file forItem: menuItem]; [file addItemWithTitle: @"Open Document" action: @selector(openDocument:) keyEquivalent: @"o"]; [file addItemWithTitle: @"Save" action: @selector(saveDocument:) keyEquivalent: @"s"]; [file addItemWithTitle: @"Save To..." action: @selector(saveDocumentTo:) keyEquivalent: @"t"]; [file addItemWithTitle: @"Save All" action: @selector(saveDocumentAll:) keyEquivalent: @""]; [file addItemWithTitle: @"Revert to Saved" action: @selector(revertDocumentToSaved:) keyEquivalent: @"u"]; [file addItemWithTitle: @"Close" action: @selector(close) keyEquivalent: @""]; RELEASE(file); // create new game menu menuItem = (NSMenuItem *)[mainMenu addItemWithTitle: @"New game" action: NULL keyEquivalent: @""]; menu = AUTORELEASE ([NSMenu new]); [mainMenu setSubmenu:menu forItem: menuItem]; [[menu addItemWithTitle: _(@"20 clues") action: @selector(newPuzzle:) keyEquivalent: @""] setTag:MENU_NEW_20CLUES]; [[menu addItemWithTitle: _(@"25 clues") action: @selector(newPuzzle:) keyEquivalent: @"n"] setTag:MENU_NEW_25CLUES]; [[menu addItemWithTitle: _(@"30 clues") action: @selector(newPuzzle:) keyEquivalent: @""] setTag:MENU_NEW_30CLUES]; [[menu addItemWithTitle: _(@"35 clues") action: @selector(newPuzzle:) keyEquivalent: @""] setTag:MENU_NEW_35CLUES]; [[menu addItemWithTitle: _(@"48 clues") action: @selector(newPuzzle:) keyEquivalent: @""] setTag:MENU_NEW_48CLUES]; [[menu addItemWithTitle: _(@"60 clues") action: @selector(newPuzzle:) keyEquivalent: @""] setTag:MENU_NEW_60CLUES]; [[menu addItemWithTitle: _(@"70 clues") action: @selector(newPuzzle:) keyEquivalent: @""] setTag:MENU_NEW_70CLUES]; // Reset puzzle [mainMenu addItemWithTitle: @"Reset Puzzle" action: @selector (resetPuzzle:) keyEquivalent: @""]; // Load solution [mainMenu addItemWithTitle: @"Load solution" action: @selector (solvePuzzle:) keyEquivalent: @""]; // Enter puzzle [mainMenu addItemWithTitle: @"Enter Puzzle" action: @selector (enterPuzzle:) keyEquivalent: @""]; // Hide MenuItem [mainMenu addItemWithTitle: @"Hide" action: @selector (hide:) keyEquivalent: @"h"]; // Quit MenuItem [mainMenu addItemWithTitle: @"Quit" action: @selector (terminate:) keyEquivalent: @"q"]; [app setMainMenu: mainMenu]; srand48(time(NULL)); controller = [Controller new]; [app setDelegate: controller]; NSApplicationMain(argc, argv); [[NSUserDefaults standardUserDefaults] synchronize]; RELEASE (controller); RELEASE (pool); return 0; } Sudoku-0.7/Controller.m.works010064400017500000144000000245371157634732100155650ustar multixusers/* Project: Sudoku Controller.m Copyright (C) 2007-2011 The Free Software Foundation, Inc Author: Marko Riedel This application 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 3 of the License, or (at your option) any later version. This application 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 Library General Public License for more details. You should have received a copy of the GNU General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include time_t time(time_t *t); #import #import #import "Controller.h" #import "Document.h" #import "KnobView.h" #import "DigitSource.h" @implementation Controller static NSPanel *_prog_ind_panel = nil; #define PROG_IND_WIDTH 200 #define PROG_IND_HEIGHT 20 + (NSPanel *)prog_ind { if(_prog_ind_panel==nil) { NSRect pi_frame = NSMakeRect(0, 0, PROG_IND_WIDTH, PROG_IND_HEIGHT); KnobView *_prog_ind; _prog_ind_panel = [[NSPanel alloc] initWithContentRect:pi_frame styleMask:NSTitledWindowMask backing:NSBackingStoreBuffered defer:NO]; [_prog_ind_panel setReleasedWhenClosed:NO]; _prog_ind = [[KnobView alloc] initWithFrame:pi_frame]; [_prog_ind_panel setContentView:_prog_ind]; [_prog_ind_panel setTitle:_(@"Computing Sudoku")]; } [_prog_ind_panel center]; return _prog_ind_panel; } #define TICK_ITER 20 #define TICK_STEP 5 typedef enum { STATE_FIND, STATE_CLUES, STATE_SELECT, STATE_DONE } STATE; #define MAXTRIES 25 - newPuzzle:(id)sender; // clues = [sender tag] { NSApplication *app = [NSApplication sharedApplication]; NSModalSession findSession; NSDocumentController *dc = [NSDocumentController sharedDocumentController]; Document *doc; Sudoku *sdk; Sudoku *other; Sudoku *pick; NSPanel *pi_panel; KnobView *pi; float percent, dir; STATE st; NSString *checkseq; int tries; [dc newDocument:self]; doc = [dc currentDocument]; sdk = [doc sudoku]; pi_panel = [Controller prog_ind]; pi = [pi_panel contentView]; [pi_panel makeKeyAndOrderFront:self]; findSession = [app beginModalSessionForWindow:pi_panel]; percent = 0; dir = 1; st = STATE_FIND; checkseq = nil; other = [[Sudoku alloc] init]; pick = [[Sudoku alloc] init]; tries = 0; do { int tick; for(tick=0; tick0); for(x=1; x<=10; x++){ DigitSource *dgs = [[DigitSource alloc] initAtPoint: NSMakePoint(margin+(x-1)*DIGIT_FIELD_DIM, BUTTON_HEIGHT) withDigit:x]; [[enterPanel contentView] addSubview:dgs]; } button = [NSButton new]; [button setTitle:_(@"Enter")]; [button setTarget:self]; [button setAction:@selector(actionEnter:)]; [button setFrame:NSMakeRect(0, 0, SDK_DIM/3, BUTTON_HEIGHT)]; [[enterPanel contentView] addSubview:button]; button = [NSButton new]; [button setTitle:_(@"Reset")]; [button setTarget:self]; [button setAction:@selector(actionReset:)]; [button setFrame:NSMakeRect(SDK_DIM/3, 0, SDK_DIM/3, BUTTON_HEIGHT)]; [[enterPanel contentView] addSubview:button]; button = [NSButton new]; [button setTitle:_(@"Cancel")]; [button setTarget:self]; [button setAction:@selector(actionCancel:)]; [button setFrame:NSMakeRect(2*SDK_DIM/3, 0, SDK_DIM/3, BUTTON_HEIGHT)]; [[enterPanel contentView] addSubview:button]; [enterPanel setReleasedWhenClosed:NO]; return self; } #define MAX_SOLVE_SECS 40 - actionEnter:(id)sender { BOOL success; NSDocumentController *dc; Document *doc; Sudoku *sdk; Sudoku *user; NSPanel *pi_panel; KnobView *pi; NSModalSession solveSession; float percent, dir; NSDate *end; [[NSApplication sharedApplication] stopModal]; [enterPanel orderOut:self]; [palette orderFront:self]; dc = [NSDocumentController sharedDocumentController]; [dc newDocument:self]; doc = [dc currentDocument]; sdk = [doc sudoku]; user = [sdkview sudoku]; [sdk copyStateFromSource:user]; [sdk guessToClues]; // [sdk cluesToPuzzle]; pi_panel = [Controller prog_ind]; pi = [pi_panel contentView]; [pi_panel makeKeyAndOrderFront:self]; solveSession = [[NSApplication sharedApplication] beginModalSessionForWindow:pi_panel]; percent = 0; dir = 1; end = [NSDate dateWithTimeIntervalSinceNow:MAX_SOLVE_SECS]; success = NO; do { int tick; NSDate *now; for(tick=0; tick time_t time(time_t *t); #import #import #import "Controller.h" #import "Document.h" #import "KnobView.h" #import "DigitSource.h" @implementation Controller static NSPanel *_prog_ind_panel = nil; #define PROG_IND_WIDTH 200 #define PROG_IND_HEIGHT 20 + (NSPanel *)prog_ind { if(_prog_ind_panel==nil) { NSRect pi_frame = NSMakeRect(0, 0, PROG_IND_WIDTH, PROG_IND_HEIGHT); KnobView *_prog_ind; _prog_ind_panel = [[NSPanel alloc] initWithContentRect:pi_frame styleMask:NSTitledWindowMask backing:NSBackingStoreBuffered defer:NO]; [_prog_ind_panel setReleasedWhenClosed:NO]; _prog_ind = [[KnobView alloc] initWithFrame:pi_frame]; [_prog_ind_panel setContentView:_prog_ind]; [_prog_ind_panel setTitle:_(@"Computing Sudoku")]; } [_prog_ind_panel center]; return _prog_ind_panel; } #define TICK_ITER 20 #define TICK_STEP 5 typedef enum { STATE_FIND, STATE_CLUES, STATE_SELECT, STATE_DONE } STATE; #define MAXTRIES 25 - newPuzzle:(id)sender; // clues = [sender tag] { NSApplication *app; NSModalSession findSession; NSDocumentController *dc; Document *doc; Sudoku *sdk; Sudoku *other; Sudoku *pick; NSPanel *pi_panel; KnobView *pi; float percent, dir; STATE st; NSString *checkseq; int tries; app = [NSApplication sharedApplication]; dc = [NSDocumentController sharedDocumentController]; [dc newDocument:self]; doc = [dc currentDocument]; sdk = [doc sudoku]; pi_panel = [Controller prog_ind]; pi = [pi_panel contentView]; [pi_panel makeKeyAndOrderFront:self]; findSession = [app beginModalSessionForWindow:pi_panel]; percent = 0; dir = 1; st = STATE_FIND; checkseq = nil; other = [[Sudoku alloc] init]; pick = [[Sudoku alloc] init]; tries = 0; do { int tick; for(tick=0; tick0); for(x=1; x<=10; x++){ DigitSource *dgs = [[DigitSource alloc] initAtPoint: NSMakePoint(margin+(x-1)*DIGIT_FIELD_DIM, BUTTON_HEIGHT) withDigit:x]; [[enterPanel contentView] addSubview:dgs]; } button = [NSButton new]; [button setTitle:_(@"Enter")]; [button setTarget:self]; [button setAction:@selector(actionEnter:)]; [button setFrame:NSMakeRect(0, 0, SDK_DIM/3, BUTTON_HEIGHT)]; [[enterPanel contentView] addSubview:button]; button = [NSButton new]; [button setTitle:_(@"Reset")]; [button setTarget:self]; [button setAction:@selector(actionReset:)]; [button setFrame:NSMakeRect(SDK_DIM/3, 0, SDK_DIM/3, BUTTON_HEIGHT)]; [[enterPanel contentView] addSubview:button]; button = [NSButton new]; [button setTitle:_(@"Cancel")]; [button setTarget:self]; [button setAction:@selector(actionCancel:)]; [button setFrame:NSMakeRect(2*SDK_DIM/3, 0, SDK_DIM/3, BUTTON_HEIGHT)]; [[enterPanel contentView] addSubview:button]; [enterPanel setReleasedWhenClosed:NO]; return self; } #define MAX_SOLVE_SECS 40 - actionEnter:(id)sender { BOOL success; NSDocumentController *dc; Document *doc; Sudoku *sdk; Sudoku *user; NSPanel *pi_panel; KnobView *pi; NSModalSession solveSession; float percent, dir; NSDate *end; [[NSApplication sharedApplication] stopModal]; [enterPanel orderOut:self]; [palette orderFront:self]; dc = [NSDocumentController sharedDocumentController]; [dc newDocument:self]; doc = [dc currentDocument]; sdk = [doc sudoku]; user = [sdkview sudoku]; [sdk copyStateFromSource:user]; [sdk guessToClues]; // [sdk cluesToPuzzle]; pi_panel = [Controller prog_ind]; pi = [pi_panel contentView]; [pi_panel makeKeyAndOrderFront:self]; solveSession = [[NSApplication sharedApplication] beginModalSessionForWindow:pi_panel]; percent = 0; dir = 1; end = [NSDate dateWithTimeIntervalSinceNow:MAX_SOLVE_SECS]; success = NO; do { int tick; NSDate *now; for(tick=0; tick #import "SudokuView.h" #import "DigitSource.h" @implementation SudokuView - initWithFrame:(NSRect)frame { frame.size.width = SDK_DIM; frame.size.height = SDK_DIM; [super initWithFrame:frame]; [self registerForDraggedTypes: [NSArray arrayWithObjects:DIGIT_TYPE, nil]]; sdk = [[Sudoku alloc] init]; RETAIN(sdk); return self; } - (Sudoku *)sudoku { return sdk; } - (void)drawMarkupAtX:(int)x andY:(int)y { NSFont *font; NSColor *col = [NSColor colorWithDeviceRed:0 green:1.0/3.0 blue:0 alpha:1.0]; NSDictionary *attrDict; int present[9], digit; int nb; char str[2] = { '1', 0 }; font = [NSFont boldSystemFontOfSize:MARKUP_SIZE]; attrDict =[NSDictionary dictionaryWithObjectsAndKeys: font, NSFontAttributeName, col, NSForegroundColorAttributeName, nil]; [font set]; for(digit=0; digit<9; digit++) present[digit] = 0; for(nb=0; nbguess = -1; [self setNeedsDisplay:YES]; [self display]; [win flushWindow]; [[dc currentDocument] updateChangeCount:NSChangeDone]; return; } str[0] = '1' + guess; str[1] = 0 ; for(nb=0; nbguess = guess; [self setNeedsDisplay:YES]; [self display]; [win flushWindow]; if([sdk completed]==YES){ NSRunAlertPanel(@"Congratulations!", @"Sudoku solved.", @"Ok", nil, nil); } return; } - (unsigned int)draggingEntered:(id )sender { NSPasteboard *pb = [sender draggingPasteboard]; NSDragOperation sourceDragMask = [sender draggingSourceOperationMask]; if([[pb types] indexOfObject:DIGIT_TYPE]!=NSNotFound) { if(sourceDragMask & NSDragOperationCopy) { int newDigit; NSPoint startp; NSString *dstr; int x, y; int nb; dstr = [pb stringForType:DIGIT_TYPE]; [[NSScanner scannerWithString:dstr] scanInt:&newDigit]; startp = [sender draggingLocation]; startp = [self convertPoint:startp fromView: nil]; startp.x/=(float)FIELD_DIM; startp.y/=(float)FIELD_DIM; x = (int)startp.x; y = 8-(int)startp.y; if([sdk fieldX:x Y:y].puzzle != -1) return NSDragOperationNone; if(newDigit==10) return NSDragOperationCopy; newDigit--; for(nb=0; nb)sender { return [self draggingEntered:sender]; } - (BOOL)performDragOperation:(id )sender { NSPasteboard *pb = [sender draggingPasteboard]; NSString *dstr = [pb stringForType:DIGIT_TYPE]; NSDocumentController *dc; NSPoint startp; int newDigit; int x, y; [[NSScanner scannerWithString:dstr] scanInt:&newDigit]; startp = [sender draggingLocation]; startp = [self convertPoint:startp fromView: nil]; startp.x/=(float)FIELD_DIM; startp.y/=(float)FIELD_DIM; x = (int)startp.x; y = 8-(int)startp.y; [sdk fieldptrX:x Y:y]->guess = (newDigit==10 ? -1 : newDigit-1); [self setNeedsDisplay:YES]; [self display]; [[self window] flushWindow]; dc = [NSDocumentController sharedDocumentController]; [[dc currentDocument] updateChangeCount:NSChangeDone]; if([sdk completed]==YES){ NSRunAlertPanel(@"Congratulations!", @"Sudoku solved.", @"Ok", nil, nil); } return YES; } - (BOOL)prepareForDragOperation:(id )sender { return YES; } @end Sudoku-0.7/DigitSource.m.rej010060000017500000144000000116271157613377200152650ustar multixusers@@ -42,9 +42,11 @@ + (NSPanel *)prog_ind { - if(_prog_ind_panel==nil){ + if(_prog_ind_panel==nil) + { NSRect pi_frame = NSMakeRect(0, 0, PROG_IND_WIDTH, PROG_IND_HEIGHT); + KnobView *_prog_ind; _prog_ind_panel = [[NSPanel alloc] @@ -54,8 +56,7 @@ defer:NO]; [_prog_ind_panel setReleasedWhenClosed:NO]; - KnobView *_prog_ind = - [[KnobView alloc] initWithFrame:pi_frame]; + _prog_ind = [[KnobView alloc] initWithFrame:pi_frame]; [_prog_ind_panel setContentView:_prog_ind]; [_prog_ind_panel setTitle:_(@"Computing Sudoku")]; @@ -80,28 +81,31 @@ - newPuzzle:(id)sender; // clues = [sender tag] { NSApplication *app = [NSApplication sharedApplication]; - - NSDocumentController *dc = - [NSDocumentController sharedDocumentController]; - [dc newDocument:self]; - - Document *doc = [dc currentDocument]; - Sudoku *sdk = [doc sudoku]; - + NSModalSession findSession; + NSDocumentController *dc = [NSDocumentController sharedDocumentController]; + Document *doc; + Sudoku *sdk; NSPanel *pi_panel = [Controller prog_ind]; KnobView *pi = [pi_panel contentView]; - + float percent = 0, dir = 1; + STATE st = STATE_FIND; + NSString *checkseq = nil; + Sudoku *other, *pick; + int tries; + + doc = [dc currentDocument]; + sdk = [doc sudoku]; + [dc newDocument:self]; [pi_panel makeKeyAndOrderFront:self]; - NSModalSession findSession; + findSession = [app beginModalSessionForWindow:pi_panel]; - float percent = 0, dir = 1; - STATE st = STATE_FIND; - NSString *checkseq = nil; - Sudoku *other = [[Sudoku alloc] init], *pick = [[Sudoku alloc] init]; - int tries = 0; + + other = [[Sudoku alloc] init]; + pick = [[Sudoku alloc] init]; + tries = 0; do { int tick; @@ -184,12 +188,14 @@ - makeInputPanel { int m = NSTitledWindowMask; - - NSRect frame = - {{ 0, BUTTON_HEIGHT + DIGIT_FIELD_DIM}, { SDK_DIM, SDK_DIM} }; + int x; + float margin; + NSButton *button; + NSRect allframe ; + NSRect frame = {{ 0, BUTTON_HEIGHT + DIGIT_FIELD_DIM}, { SDK_DIM, SDK_DIM} }; sdkview = [[SudokuView alloc] initWithFrame:frame]; - NSRect allframe = frame; + allframe = frame; allframe.size.height += BUTTON_HEIGHT + DIGIT_FIELD_DIM; enterPanel = @@ -202,10 +208,9 @@ [[enterPanel contentView] addSubview:sdkview]; - float margin = (SDK_DIM - DIGIT_FIELD_DIM*10)/2; + margin = (SDK_DIM - DIGIT_FIELD_DIM*10)/2; assert(margin>0); - int x; for(x=1; x<=10; x++){ DigitSource *dgs = [[DigitSource alloc] @@ -216,13 +221,12 @@ } - NSButton *button = [NSButton new]; + button = [NSButton new]; [button setTitle:_(@"Enter")]; [button setTarget:self]; [button setAction:@selector(actionEnter:)]; - [button - setFrame:NSMakeRect(0, 0, SDK_DIM/3, BUTTON_HEIGHT)]; + [button setFrame:NSMakeRect(0, 0, SDK_DIM/3, BUTTON_HEIGHT)]; [[enterPanel contentView] addSubview:button]; @@ -231,8 +235,7 @@ [button setTarget:self]; [button setAction:@selector(actionReset:)]; - [button - setFrame:NSMakeRect(SDK_DIM/3, 0, SDK_DIM/3, BUTTON_HEIGHT)]; + [button setFrame:NSMakeRect(SDK_DIM/3, 0, SDK_DIM/3, BUTTON_HEIGHT)]; [[enterPanel contentView] addSubview:button]; @@ -241,8 +244,7 @@ [button setTarget:self]; [button setAction:@selector(actionCancel:)]; - [button - setFrame:NSMakeRect(2*SDK_DIM/3, 0, SDK_DIM/3, BUTTON_HEIGHT)]; + [button setFrame:NSMakeRect(2*SDK_DIM/3, 0, SDK_DIM/3, BUTTON_HEIGHT)]; [[enterPanel contentView] addSubview:button]; @@ -260,9 +262,13 @@ Document *doc; Sudoku *sdk; Sudoku *user; + NSPanel *pi_panel; + KnobView *pi; + NSModalSession solveSession; + float percent, dir; + NSDate *end; - [[NSApplication sharedApplication] - stopModal]; + [[NSApplication sharedApplication] stopModal]; [enterPanel orderOut:self]; [palette orderFront:self]; @@ -278,17 +284,17 @@ [sdk guessToClues]; // [sdk cluesToPuzzle]; - NSPanel *pi_panel = [Controller prog_ind]; - KnobView *pi = [pi_panel contentView]; + pi_panel = [Controller prog_ind]; + pi = [pi_panel contentView]; [pi_panel makeKeyAndOrderFront:self]; - NSModalSession solveSession; solveSession = [[NSApplication sharedApplication] beginModalSessionForWindow:pi_panel]; - float percent = 0, dir = 1; + percent = 0; + dir = 1; - NSDate *end = [NSDate dateWithTimeIntervalSinceNow:MAX_SOLVE_SECS]; + end = [NSDate dateWithTimeIntervalSinceNow:MAX_SOLVE_SECS]; success = NO; do { @@ -407,6 +413,7 @@ - makeDigitPalette { + int x, y; NSRect pbounds = NSMakeRect(0, 0, 2*DIGIT_FIELD_DIM, 5*DIGIT_FIELD_DIM); @@ -431,7 +438,6 @@ [palette setFrameAutosaveName: @"SudokuDigitPalette"]; - int x, y; for(x=0; x<2; x++){ for(y=0; y<5; y++){ DigitSource *dgs = Sudoku-0.7/.#Controller.m.1.3010064400017500000144000000245371157634374000150430ustar multixusers/* Project: Sudoku Controller.m Copyright (C) 2007-2011 The Free Software Foundation, Inc Author: Marko Riedel This application 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 3 of the License, or (at your option) any later version. This application 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 Library General Public License for more details. You should have received a copy of the GNU General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include time_t time(time_t *t); #import #import #import "Controller.h" #import "Document.h" #import "KnobView.h" #import "DigitSource.h" @implementation Controller static NSPanel *_prog_ind_panel = nil; #define PROG_IND_WIDTH 200 #define PROG_IND_HEIGHT 20 + (NSPanel *)prog_ind { if(_prog_ind_panel==nil) { NSRect pi_frame = NSMakeRect(0, 0, PROG_IND_WIDTH, PROG_IND_HEIGHT); KnobView *_prog_ind; _prog_ind_panel = [[NSPanel alloc] initWithContentRect:pi_frame styleMask:NSTitledWindowMask backing:NSBackingStoreBuffered defer:NO]; [_prog_ind_panel setReleasedWhenClosed:NO]; _prog_ind = [[KnobView alloc] initWithFrame:pi_frame]; [_prog_ind_panel setContentView:_prog_ind]; [_prog_ind_panel setTitle:_(@"Computing Sudoku")]; } [_prog_ind_panel center]; return _prog_ind_panel; } #define TICK_ITER 20 #define TICK_STEP 5 typedef enum { STATE_FIND, STATE_CLUES, STATE_SELECT, STATE_DONE } STATE; #define MAXTRIES 25 - newPuzzle:(id)sender; // clues = [sender tag] { NSApplication *app = [NSApplication sharedApplication]; NSModalSession findSession; NSDocumentController *dc = [NSDocumentController sharedDocumentController]; Document *doc; Sudoku *sdk; Sudoku *other; Sudoku *pick; NSPanel *pi_panel; KnobView *pi; float percent, dir; STATE st; NSString *checkseq; int tries; [dc newDocument:self]; doc = [dc currentDocument]; sdk = [doc sudoku]; pi_panel = [Controller prog_ind]; pi = [pi_panel contentView]; [pi_panel makeKeyAndOrderFront:self]; findSession = [app beginModalSessionForWindow:pi_panel]; percent = 0; dir = 1; st = STATE_FIND; checkseq = nil; other = [[Sudoku alloc] init]; pick = [[Sudoku alloc] init]; tries = 0; do { int tick; for(tick=0; tick0); for(x=1; x<=10; x++){ DigitSource *dgs = [[DigitSource alloc] initAtPoint: NSMakePoint(margin+(x-1)*DIGIT_FIELD_DIM, BUTTON_HEIGHT) withDigit:x]; [[enterPanel contentView] addSubview:dgs]; } button = [NSButton new]; [button setTitle:_(@"Enter")]; [button setTarget:self]; [button setAction:@selector(actionEnter:)]; [button setFrame:NSMakeRect(0, 0, SDK_DIM/3, BUTTON_HEIGHT)]; [[enterPanel contentView] addSubview:button]; button = [NSButton new]; [button setTitle:_(@"Reset")]; [button setTarget:self]; [button setAction:@selector(actionReset:)]; [button setFrame:NSMakeRect(SDK_DIM/3, 0, SDK_DIM/3, BUTTON_HEIGHT)]; [[enterPanel contentView] addSubview:button]; button = [NSButton new]; [button setTitle:_(@"Cancel")]; [button setTarget:self]; [button setAction:@selector(actionCancel:)]; [button setFrame:NSMakeRect(2*SDK_DIM/3, 0, SDK_DIM/3, BUTTON_HEIGHT)]; [[enterPanel contentView] addSubview:button]; [enterPanel setReleasedWhenClosed:NO]; return self; } #define MAX_SOLVE_SECS 40 - actionEnter:(id)sender { BOOL success; NSDocumentController *dc; Document *doc; Sudoku *sdk; Sudoku *user; NSPanel *pi_panel; KnobView *pi; NSModalSession solveSession; float percent, dir; NSDate *end; [[NSApplication sharedApplication] stopModal]; [enterPanel orderOut:self]; [palette orderFront:self]; dc = [NSDocumentController sharedDocumentController]; [dc newDocument:self]; doc = [dc currentDocument]; sdk = [doc sudoku]; user = [sdkview sudoku]; [sdk copyStateFromSource:user]; [sdk guessToClues]; // [sdk cluesToPuzzle]; pi_panel = [Controller prog_ind]; pi = [pi_panel contentView]; [pi_panel makeKeyAndOrderFront:self]; solveSession = [[NSApplication sharedApplication] beginModalSessionForWindow:pi_panel]; percent = 0; dir = 1; end = [NSDate dateWithTimeIntervalSinceNow:MAX_SOLVE_SECS]; success = NO; do { int tick; NSDate *now; for(tick=0; tick