Logging Game Trees

This is an example to show how to use the game-tree log interface in a game program. We use here a simple iterative deepening and minimax procedure for demonstration purposes (and omit various details that are not relevant for our demonstration purposes). Essentially, one must create a handle in the beginning (and delete in the end), open a new file for each search iteration, and call special functions when entering/exiting a node. The user collects the information he or she want to log in the structure data.

/* Example TicTacToc program. */
#include "gt_log.h"
...
GTDataDescript gtDataDescr = /* <= GTL data description */
	{ "TicTacToe", sizeof(Data_t), 0, {}, 5,
		{ ...
			{ "depth", offsetof(Data_t,depth), sizeof(int) },
			{ "best" , offsetof(Data_t,best), sizeof(int) },
			{ "type" , offsetof(Data_t,type), sizeof(int) } }
};
GTLogHdl hGTL; /* <= Game-tree log handle. */

Value Minimax( Position_t *pos, int depth, Move_t move_last ) {
	Data_t data; /* <= GTL data record, user defined. */
	...
	data.depth = depth;
	gtl_enterNode( hGTL, move_last ); /* <= GTL enter node.*/
	...
	n = generateMoves(pos, moves);
	for ( i=0 ; i<n ; i++ ) {
		makeMove( pos, moves[i] );
		value = -Minimax( pos, depth-1, moves[i] );
		...
		retractMove( pos, moves[i] );
	}
	...
	data.best = best;
	gtl_exitNode( hGTL, &data ); /* <= GTL exit node */
	return best;
}

Value IterativeDeepening( ... ) {
	...
	for ( iter=1 ; iter<=maxIter ; ++iter ) {
		...
		gtl_startTree( hGTL, filename, strFEN ); /* <= GTL open new game-tree log file */
		...
		value = Minimax( &pos, iter, NULL_MOVE );
		...
		gtl_stopTree( hGTL ); /* <= GTL close tree */
	}
	...
}

int main() {
	...
	hGTL = gtl_newHdl( "TicTacToe", &gtDataDescr ); /* <= GTL new handle */
	if ( hGTL == NULL ) exit(EXIT_FAILURE);
	...
	gtl_deleteHdl( &hGTL ); /* <= GTL delete handle */
	...
}