Skip to content

Instantly share code, notes, and snippets.

@mulbc
Created September 5, 2011 10:49
Show Gist options
  • Save mulbc/1194684 to your computer and use it in GitHub Desktop.
Save mulbc/1194684 to your computer and use it in GitHub Desktop.
/// pgnString returns an NSString representing the entire game as PGN.
- (NSString *)pgnString {
NSMutableString *string = [NSMutableString stringWithCapacity: 2000];
[string appendFormat: @"[Event \"%@\"]\n", event];
[string appendFormat: @"[Site \"%@\"]\n", site];
[string appendFormat: @"[Date \"%@\"]\n", date];
[string appendFormat: @"[Round \"%@\"]\n", round];
[string appendFormat: @"[White \"%@\"]\n", whitePlayer];
[string appendFormat: @"[Black \"%@\"]\n", blackPlayer];
[string appendFormat: @"[Result \"%@\"]\n", result];
if (![startFEN isEqualToString: @"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"])
[string appendFormat: @"[FEN \"%@\"]\n", startFEN];
[string appendString: @"\n"];
[string appendString: [self pgnMoveListString]];
[string appendFormat: @"\n%@\n\n", [self result]];
return string;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment