#import #import #import time_t time(time_t *t); #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); _prog_ind_panel = [[NSPanel alloc] initWithContentRect:pi_frame styleMask:NSTitledWindowMask backing:NSBackingStoreBuffered defer:NO]; [_prog_ind_panel setReleasedWhenClosed:NO]; KnobView *_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]; NSDocumentController *dc = [NSDocumentController sharedDocumentController]; [dc newDocument:self]; Document *doc = [dc currentDocument]; Sudoku *sdk = [doc sudoku]; NSPanel *pi_panel = [Controller prog_ind]; KnobView *pi = [pi_panel contentView]; [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; do { int tick; for(tick=0; tick0); int x; 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]; } NSButton *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 { [[NSApplication sharedApplication] stopModal]; [enterPanel orderOut:self]; [palette orderFront:self]; NSApplication *app = [NSApplication sharedApplication]; NSDocumentController *dc = [NSDocumentController sharedDocumentController]; [dc newDocument:self]; Document *doc = [dc currentDocument]; Sudoku *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 makeKeyAndOrderFront:self]; NSModalSession solveSession; solveSession = [app beginModalSessionForWindow:pi_panel]; float percent = 0, dir = 1; BOOL success; NSDate *end = [NSDate dateWithTimeIntervalSinceNow:MAX_SOLVE_SECS]; do { int tick; for(tick=0; tick