#include "chess.h" #include "data.h" /* last modified 02/26/14 */ /* ******************************************************************************* * * * "annotate" command is used to search through the game in a pgn file, and * * provide a qualitative analysis of each move played and then creating a * * new output file (xxx.can) containing the original game + new commentary. * * * * The normal output of this command is a file, in PGN format, that contains * * the moves of the game, along with analysis when Crafty does not think * * that move was the best choice. The definition of "best choice" is * * somewhat vague, because if the move played is "close" to the best move * * available, Crafty will not comment on the move. "Close" is defined by * * the option explained below. This basic type of annotation works * * by first using the normal tree search algorithm to find the best move. * * If this move was the move played, no output is produced. If a different * * move is considered best, then the actual move played is searched to the * * same depth and if the best move and actual move scores are within * * of each other, no comment is produced, otherwise Crafty inserts * * the evaluation for the move played, followed by the eval and PV for the * * best continuation it found. You can enter suggested moves for Crafty to * * analyze at any point by simply entering a move as an analysis-type * * comment using (move) or {move}. Crafty will search that move in addition * * to the move actually played and the move it thinks is best. * * * * The format of the command is as follows: * * * * annotate filename b|w|bw|name moves margin time [n] * * * * Filename is the input file where Crafty will obtain the moves to * * annotate, and output will be written to file "filename.can". * * * * annotateh filename b|w|bw|name moves margin time [n] * * * * Can be used to produce an HTML-compatible file that includes bitmapped * * diagrams of the positions where Crafty provides analysis. This file can * * be opened by a browser to provide much easier 'reading'. * * * * annotatet filename b|w|bw|name moves margin time [n] * * * * Can be used to produce a LaTeX-compatible file that includes LaTeX chess * * fonts. This file can be read/printed by any program that can handle * * LaTeX input. * * * * Where b/w/bw indicates whether to annotate only the white side (w), the * * black side (b) or both (bw). You can also specify a name (or part of a * * name, just be sure it is unique in the name tags for clarity in who you * * mean). * * * * Moves indicates the move or moves to annotate. It can be a single move, * * which indicates the starting move number to annotate, or it can be a * * range, which indicates a range of move (1-999 gets the whole game.) * * * * Margin is the difference between Crafty's evaluation for the move * * actually played and for the move Crafty thinks is best, before Crafty * * will generate a comment in the annotation file. 1.0 is a pawn, and will * * only generate comments if the move played is 1.000 (1 pawn) worse than * * the best move found by doing a complete search. * * * * Time is time per move to search, in seconds. * * * * [n] is optional and tells Crafty to produce the PV/score for the "n" best * * moves. Crafty stops when the best move reaches the move played in the * * game or after displaying n moves, whichever comes first. If you use -n, * * then it will display n moves regardless of where the game move ranks. * * * ******************************************************************************* */ #define MIN_DECISIVE_ADV 150 #define MIN_MODERATE_ADV 70 #define MIN_SLIGHT_ADV 30 void Annotate() { FILE *annotate_in, *annotate_out; char text[128], tbuffer[4096], colors[32] = { "" }, pname[128] = { ""}; int annotate_margin, annotate_score[100], player_score, best_moves, annotate_wtm; int annotate_search_time_limit, search_player; int twtm, path_len, analysis_printed = 0; int wtm, move_num, line1, line2, move, suggested, i; int searches_done, read_status; PATH temp[100], player_pv; int temp_search_depth; TREE *const tree = block[0]; char html_br[5] = { "" }; int save_swindle_mode; int html_mode = 0; int latex = 0; /* ************************************************************ * * * First, extract the options from the command line to * * determine what the user wanted us to do. * * * ************************************************************ */ save_swindle_mode = swindle_mode; if (!strcmp(args[0], "annotateh")) { html_mode = 1; strcpy(html_br, "
"); } if (!strcmp(args[0], "annotatet")) { latex = 1; strcpy(html_br, "\\\\"); } strcpy(tbuffer, buffer); nargs = ReadParse(tbuffer, args, " \t;"); if (nargs < 6) { printf ("usage: annotate