Skip to content

Commit 45a30a7

Browse files
committed
add support to show WDL data
1 parent b1de392 commit 45a30a7

File tree

8 files changed

+63
-8
lines changed

8 files changed

+63
-8
lines changed

Stockfish/Base.lproj/MainMenu.xib

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="16097.2" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
2+
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="18122" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
33
<dependencies>
44
<deployment identifier="macosx"/>
5-
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="16097.2"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="18122"/>
66
</dependencies>
77
<objects>
88
<customObject id="-2" userLabel="File's Owner" customClass="SFMApplication">
@@ -228,6 +228,12 @@
228228
<action selector="toggleUseNnue:" target="-1" id="CYi-ql-Wru"/>
229229
</connections>
230230
</menuItem>
231+
<menuItem title="Show WDL" id="D73-eM-v6f">
232+
<modifierMask key="keyEquivalentModifierMask"/>
233+
<connections>
234+
<action selector="toggleShowWdl:" target="-1" id="NYc-Hf-ILl"/>
235+
</connections>
236+
</menuItem>
231237
</items>
232238
</menu>
233239
</menuItem>

Stockfish/SFMUCIEngine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
@property (nonatomic) SFMChessGame *gameToAnalyze;
3333
@property (nonatomic) NSUInteger multipv;
3434
@property (nonatomic) BOOL useNnue;
35-
35+
@property (nonatomic) BOOL showWdl;
3636
@property (readonly, nonatomic) NSDictionary /* <NSNumber, SFMUCILine> */ *lines;
3737
@property (readonly, nonatomic) NSString *nnueInfo;
3838

Stockfish/SFMUCIEngine.m

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ - (void)setIsAnalyzing:(BOOL)isAnalyzing {
5656
NSAssert(self.gameToAnalyze != nil, @"Trying to analyze but no game set");
5757
[self setUciOption:@"MultiPV" integerValue:self.multipv];
5858
[self setUciOption:@"Use NNUE" stringValue:self.useNnue ? @"true" : @"false"];
59+
[self setUciOption:@"UCI_ShowWDL" stringValue:self.showWdl ? @"true" : @"false"];
5960
[self sendCommandToEngine:[self.gameToAnalyze uciString]];
6061
dispatch_group_enter(_analysisGroup);
6162
atomic_fetch_add(&instancesAnalyzing, 1);
@@ -108,6 +109,17 @@ - (void)setUseNnue:(BOOL)useNnue {
108109
}
109110
}
110111

112+
- (void)setShowWdl:(BOOL)showWdl {
113+
if (self.isAnalyzing) {
114+
self.isAnalyzing = NO;
115+
dispatch_group_notify(_analysisGroup, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
116+
self->_showWdl = showWdl;
117+
self.isAnalyzing = YES;
118+
});
119+
} else {
120+
_showWdl = showWdl;
121+
}
122+
}
111123
#pragma mark - Engine I/O
112124

113125
/*!
@@ -150,7 +162,7 @@ - (void)processEngineOutput:(NSString *)str
150162
if ([str isEqualToString:@""]) {
151163
return;
152164
}
153-
165+
NSLog(@"Str is: %@", str);
154166
NSArray *tokens = [str componentsSeparatedByString:@" "];
155167

156168
if ([tokens containsObject:@"currmove"]) {

Stockfish/SFMUCILine.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
@property (nonatomic) NSInteger tbHits;
2323
@property (nonatomic) long long time; // milliseconds
2424
@property (nonatomic) NSArray *moves;
25-
25+
@property (nonatomic) NSInteger wdlWin;
26+
@property (nonatomic) NSInteger wdlDraw;
27+
@property (nonatomic) NSInteger wdlLoss;
2628
- (instancetype)initWithTokens:(NSArray *)tokens position:(SFMPosition *)position;
2729

2830
@end

Stockfish/SFMUCILine.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,28 @@ - (instancetype)initWithTokens:(NSArray *)tokens position:(SFMPosition *)positio
2626
}
2727
_scoreIsLowerBound = [tokens containsObject:@"lowerbound"];
2828
_scoreIsUpperBound = [tokens containsObject:@"upperbound"];
29+
30+
NSArray *wdl = [tokens sfm_objectsAfterObject:@"wdl" beforeObject:@"nodes"];
31+
if (wdl != nil) {
32+
_wdlWin = [[wdl objectAtIndex:0] integerValue];
33+
_wdlDraw = [[wdl objectAtIndex:1] integerValue];
34+
_wdlLoss = [[wdl objectAtIndex:2] integerValue];
35+
}
2936
_nodes = [tokens sfm_objectAfterObject:@"nodes"];
3037
_nodesPerSecond = [tokens sfm_objectAfterObject:@"nps"];
3138
_tbHits = [[tokens sfm_objectAfterObject:@"tbhits"] integerValue];
3239
_time = [[tokens sfm_objectAfterObject:@"time"] longLongValue];
3340
_moves = [position movesArrayForUci:[tokens sfm_objectsAfterObject:@"pv"]];
41+
3442
NSAssert(_depth != 0, @"failed to init uci line");
3543
}
3644
return self;
3745
}
3846

3947
- (NSString *)description {
48+
if (_wdlWin != 0 || _wdlDraw != 0 || _wdlLoss != 0) {
49+
return [NSString stringWithFormat:@"depth=%ld/%ld score=%ld nodes=%ld win=%ld draw=%ld loss=%ld time=%ld pv=%@", (long)self.depth, (long)self.selectiveDepth, (long)self.score, (long)self.wdlWin, (long)self.wdlDraw, (long)self.wdlLoss, (long)self.nodes, (long)self.time, [self.moves description] ];
50+
}
4051
return [NSString stringWithFormat:@"depth=%ld/%ld score=%ld nodes=%ld time=%ld pv=%@", (long)self.depth, (long)self.selectiveDepth, (long)self.score, (long)self.nodes, (long)self.time, [self.moves description] ];
4152
}
4253

Stockfish/SFMUserDefaults.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,7 @@
2626
+ (BOOL)useNnue;
2727
+ (void)setUseNnue:(BOOL)val;
2828

29+
+ (BOOL)showWdl;
30+
+ (void)setShowWDL:(BOOL)val;
31+
2932
@end

Stockfish/SFMUserDefaults.m

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
#define SANDBOX_BOOKMARK_DATA @"sandbox_bookmark_data"
1515
#define ARROWS_ENABLED @"arrows_enabled"
1616
#define USE_NNUE @"use_nnue"
17-
17+
#define SHOW_WDL @"show_wdl"
18+
/// <#Description#>
1819
@implementation SFMUserDefaults
1920

2021
+ (NSInteger)threadsValue {
@@ -74,4 +75,13 @@ + (void)setUseNnue:(BOOL)val {
7475
[[NSUserDefaults standardUserDefaults] setBool:val forKey:USE_NNUE];
7576
}
7677

78+
+(BOOL)showWdl {
79+
if (![[NSUserDefaults standardUserDefaults] objectForKey:SHOW_WDL]) {
80+
[SFMUserDefaults setUseNnue:YES];
81+
}
82+
return [[NSUserDefaults standardUserDefaults] boolForKey:SHOW_WDL];
83+
}
84+
+ (void)setShowWDL:(BOOL)val {
85+
[[NSUserDefaults standardUserDefaults] setBool:val forKey:SHOW_WDL];
86+
}
7787
@end

Stockfish/SFMWindowController.m

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,11 @@ - (IBAction)toggleUseNnue:(id)sender {
138138
[SFMUserDefaults setUseNnue:![SFMUserDefaults useNnue]];
139139
self.engine.useNnue = [SFMUserDefaults useNnue];
140140
}
141+
- (IBAction)toggleShowWdl:(id)sender {
142+
[SFMUserDefaults setShowWDL:![SFMUserDefaults showWdl]];
143+
self.engine.showWdl = [SFMUserDefaults showWdl];
141144

145+
}
142146
#pragma mark - Helper methods
143147
- (void)syncToViewsAndEngine
144148
{
@@ -224,7 +228,7 @@ - (void)windowDidLoad
224228
self.engine = [[SFMUCIEngine alloc] initStockfish];
225229
self.engine.delegate = self;
226230
self.engine.useNnue = [SFMUserDefaults useNnue];
227-
231+
self.engine.showWdl = [SFMUserDefaults showWdl];
228232
[self handlePGNFile];
229233
}
230234

@@ -304,6 +308,8 @@ - (BOOL)validateMenuItem:(NSMenuItem *)menuItem
304308
[menuItem setState:[SFMUserDefaults arrowsEnabled] ? NSControlStateValueOn : NSControlStateValueOff];
305309
} else if ([menuItem action] == @selector(toggleUseNnue:)) {
306310
[menuItem setState:[SFMUserDefaults useNnue] ? NSControlStateValueOn : NSControlStateValueOff];
311+
} else if ([menuItem action] == @selector(toggleShowWdl:)) {
312+
[menuItem setState:[SFMUserDefaults showWdl] ? NSControlStateValueOn : NSControlStateValueOff];
307313
}
308314
return YES;
309315
}
@@ -389,12 +395,17 @@ - (void)uciEngine:(SFMUCIEngine *)engine didGetNewLine:(NSDictionary *)lines {
389395
if (line.tbHits) {
390396
[statusComponents addObject:[NSString stringWithFormat:@"TB=%lu", line.tbHits]];
391397
}
392-
398+
393399
// 4. Time
394400
[statusComponents addObject:[SFMFormatter millisecondsToClock:line.time]];
395401

396402
// 5. Nodes
397403
[statusComponents addObject:[SFMFormatter nodesAsText:line.nodes]];
404+
405+
// 6. WDL
406+
if (engine.showWdl) {
407+
[statusComponents addObject:[NSString stringWithFormat:@"\n Win=%1.1f%% Draw=%1.1f%% Loss=%1.1f%%", (float)line.wdlWin/10, (float)line.wdlDraw/10, (float)line.wdlLoss/10 ]];
408+
}
398409

399410
NSAttributedString *secondLine = [[NSAttributedString alloc] initWithString:[statusComponents componentsJoinedByString:@" "] attributes:@{NSFontAttributeName: [NSFont systemFontOfSize:[NSFont systemFontSize]], NSForegroundColorAttributeName: [NSColor labelColor]}];
400411

0 commit comments

Comments
 (0)