/
NewEngineMatchController.m
128 lines (107 loc) · 3.69 KB
/
NewEngineMatchController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
Stockfish, a OS X GUI for the UCI chess engine with the same name.
Copyright (C) 2004-2011 Marco Costalba, Joona Kiiski, Tord Romstad
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 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#import "BoardController.h"
#import "Engine.h"
#import "NewEngineMatchController.h"
@implementation NewEngineMatchController
-(id)initWithBoardController:(BoardController *)bc {
self = [super initWithWindowNibName: @"NewMatch"];
boardController = bc;
return self;
}
-(void)windowDidLoad {
NSArray *array;
NSEnumerator *e;
NSString *s;
[whiteEnginePopup removeAllItems];
[blackEnginePopup removeAllItems];
array = [[Engine installedEngines] allKeys];
e = [[array sortedArrayUsingSelector: @selector(caseInsensitiveCompare:)]
objectEnumerator];
while((s = [e nextObject])) {
[whiteEnginePopup addItemWithTitle: s];
[blackEnginePopup addItemWithTitle: s];
}
}
-(IBAction)cancelButtonPressed:(id)sender {
[[self window] close];
}
-(IBAction)configureEngine1Pressed:(id)sender {
}
-(IBAction)configureEngine2Pressed:(id)sender {
}
-(IBAction)okButtonPressed:(id)sender {
if(saveFile != nil ||
NSRunAlertPanel(@"No save game file chosen!",
@"The games will not be saved. Continue?",
@"OK", @"Cancel", nil) == NSAlertDefaultReturn) {
[[self window] close];
[boardController
startMatchWithEngine1: [whiteEnginePopup titleOfSelectedItem]
engine2: [blackEnginePopup titleOfSelectedItem]
engine1InitialTime: [whiteInitialTimeTextField intValue] * 60000
engine2InitialTime: [blackInitialTimeTextField intValue] * 60000
engine1Increment: [whiteMoveBonusTextField intValue] * 1000
engine2Increment: [blackMoveBonusTextField intValue] * 1000
numberOfGames: [numOfGamesTextField intValue]
saveFile: saveFile
positionFile: positionFile
FRC: [FRCSwitch state]
ponder: [ponderSwitch state]];
}
}
-(IBAction)pickPositionPressed:(id)sender {
NSOpenPanel *panel = [NSOpenPanel openPanel];
NSArray *fileTypes = [NSArray arrayWithObjects: @"pgn", nil];
[panel beginSheetForDirectory: nil
file: nil
types: fileTypes
modalForWindow: [self window]
modalDelegate: self
didEndSelector: @selector(openPanelDidEnd:returnCode:contextInfo:)
contextInfo: nil];
}
-(void)openPanelDidEnd:(id)sheet
returnCode:(int)returnCode
contextInfo:(void *)contextInfo {
if(returnCode == NSOKButton) {
positionFile = [[sheet filename] retain];
// NSLog(@"Using position file %@", positionFile);
}
}
-(IBAction)pickSavePressed:(id)sender {
NSSavePanel *panel = [NSSavePanel savePanel];
[panel setRequiredFileType: @"pgn"];
[panel beginSheetForDirectory: nil
file: nil
modalForWindow: [self window]
modalDelegate: self
didEndSelector: @selector(savePanelDidEnd:returnCode:contextInfo:)
contextInfo: nil];
}
-(void)savePanelDidEnd:(id)sheet
returnCode:(int)returnCode
contextInfo:(void *)contextInfo {
if(returnCode == NSOKButton) {
saveFile = [[sheet filename] retain];
// NSLog(@"Saving to %@", [sheet filename]);
}
}
-(void)dealloc {
[saveFile release];
[positionFile release];
[super dealloc];
}
@end