Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PGN formatting and readability #87

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions Stockfish/SFMPosition.mm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#import "Constants.h"
#import "SFMMove.h"
#import "SFMParser.h"
#import "NSColor+ColorUtils.h"

#include "../Chess/position.h"
#include "../Chess/bitboard.h"
Expand Down Expand Up @@ -223,7 +224,7 @@ - (NSMutableAttributedString *)moveTextForNode:(SFMNode *)node andPosition:(SFMP
currentNode = currentNode.next;
}

if(currentNode != nil){
if (currentNode != nil) {
SFMPosition *currentPosition = [position copy];
// Make the moves up to the parent node
int movesToParent = currentNode.ply - node.ply;
Expand All @@ -232,26 +233,25 @@ - (NSMutableAttributedString *)moveTextForNode:(SFMNode *)node andPosition:(SFMP
}
NSArray *movesDelta = [currentNode.parent reconstructMoves:movesToParent];
[currentPosition doMoves:movesDelta error:nil];
// Only add first level variations on new lines
if(depth == 0 && [currentNode.variations count] > 0){
[result appendAttributedString:[[NSAttributedString alloc] initWithString:@"\n"]];
}

for(SFMNode *variation in currentNode.variations){

for (SFMNode *variation in currentNode.variations) {
SFMPosition *copy = [currentPosition copy];
[result appendAttributedString:[[NSAttributedString alloc] initWithString:@"( " attributes:[self variationStringAttributes]]];
NSString *startDepthNotation = [@"" stringByPaddingToLength:(depth+1)*4 withString:@" " startingAtIndex:0];
NSString *variationStarterString = [NSString stringWithFormat:@"\n%@( ", startDepthNotation];
[result appendAttributedString:[[NSAttributedString alloc] initWithString:variationStarterString attributes:[self variationStringAttributes]]];
NSMutableAttributedString *variationString = [self moveTextForNode:variation andPosition:copy depth:depth + 1];
[variationString addAttributes:[self variationStringAttributes] range:NSMakeRange(0, variationString.length)];
[result appendAttributedString:variationString];
[result appendAttributedString:[[NSAttributedString alloc] initWithString:@") " attributes:[self variationStringAttributes]]];
if(depth == 0){
[result appendAttributedString:[[NSAttributedString alloc] initWithString:@"\n"]];
}

NSString *endDepthNotation = [@"" stringByPaddingToLength:depth*4 withString:@" " startingAtIndex:0];
NSString *variationEndString = [NSString stringWithFormat:@"\n%@", endDepthNotation];
[result appendAttributedString:[[NSAttributedString alloc] initWithString:variationEndString]];
}

[currentPosition doMove:currentNode.move error:nil];
// recurse for the rest of the moves
if(currentNode.next != nil){
if (currentNode.next != nil) {
[result appendAttributedString:[self moveTextForNode:currentNode.next andPosition:currentPosition depth:depth]];
}
}
Expand Down Expand Up @@ -293,7 +293,8 @@ - (NSAttributedString *)longestFlatLineFrom:(SFMNode *)node position:(SFMPositio
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:lineSan attributes:@{NSForegroundColorAttributeName: [NSColor labelColor]}];
[self setMoveAttributes:attributedString nodes:nodes];
if(node.comment != nil){
[attributedString appendAttributedString:[[NSAttributedString alloc] initWithString:[node.comment stringByAppendingString:@" "] attributes:@{NSLinkAttributeName: self.commentIdentifier}]];
NSString *pgnComment = [NSString stringWithFormat:@"{%@} ", node.comment];
[attributedString appendAttributedString:[[NSAttributedString alloc] initWithString:pgnComment attributes:@{NSLinkAttributeName: self.commentIdentifier}]];
}

return attributedString;
Expand Down Expand Up @@ -421,8 +422,8 @@ - (NSColor*)variationForegroundColor{
return [NSColor secondaryLabelColor];
}

- (NSColor*)commentForegroundColor{
return [NSColor secondaryLabelColor];
- (NSColor*) commentForegroundColor {
return [NSColor colorWithHex:0x208020 alpha:1.0];
}

/*!
Expand Down