<commit_before><?php

function createProblems ( $game ) {
	//Input: A game that consists of a list of moves.
	//Output: A list of problems
	global $BALANCED, $UNBALANCED;

	foreach ( $game['analysis'] as $moveKey => $move ) {
		echo ceil( $move['ply'] / 2 ).( ($move['ply']%2 == 0)? "... " : ". " ).$move['move'];

		$lines = array();

		if ( isset( $move['eval'] ) && isset( $game['analysis'][$moveKey + 1]['eval'] ) ){

			if ( ( $move['eval'] <= $BALANCED && $game['analysis'][$moveKey + 1]['eval'] >= $UNBALANCED ) 
				|| ( $move['eval'] >= -$BALANCED && $game['analysis'][$moveKey + 1]['eval'] <= -$UNBALANCED ) ) {

				//pass the moves list and position of change of advantage to a subprocess

				$lines[] = findCaptureLine( $game['uci'], $moveKey );


				echo " Change of advantage detected: ".$move['eval']." -> ".$game['analysis'][$moveKey + 1]['eval'];
			}
		}
		echo "\n";
		
		//var_dump($move);
	}
}

function findCaptureLine ( $movesUci, $ply ) {
	//Input: A string of moves and the starting move for the tactical line
	//Output: The actual tactical line

	//The ply played is the starting position. The ply after that is the blunder, 
	//and the ply after that is what the user has to find.

	/*
	
	$start position <= FEN position from ply count
	$first player move <= next successive move

	*/
	$movesUci = explode( ' ', $movesUci );
	$startMoveString = '';
	for ( $x = 0; $x <= $ply + 1; $x++ ){
		$startMoveString .= $movesUci[$x].' ';
	}

	//now parse this string to stockfish!
	//echo "\n".$startMoveString."\n";
	//$uciOutput = getLines( $startMoveString );
	$solutionMap = buildCaptureTree( $startMoveString );

	//$captureArray = captureArray( $movesUci );
}

function buildCaptureTree( $moveString ) {
	//Input: List of moves in UCI format
	//Output: Map of the correct tactical line
	global $MAX_CAPTURE_LINES;

	$movesList = getMovesListFromPosition( $moveString, $MAX_CAPTURE_LINES, TRUE );
}

function getMovesListFromPosition ( $moveString, $maxLines, $allowForcedInclusion ) {
	global $FIRST_PASS_TIME, $SECOND_PASS_TIME, $ALT_THRESHOLD, $FORCED_INCLUSION;

	$uciOutput = getUci( $moveString, $FIRST_PASS_TIME );

	preg_match_all( "/info.*?cp (-?[0-9]*).*?([a-h][1-8][a-h][1-8][qrnb]?)/", $uciOutput, $matches );

	$candidateMoves = array();
	$candidateMovesEval = array();

	foreach ( $matches[2] as $key => $match ) {
		if ( !in_array( $match , $candidateMoves) ) {
			$candidateMoves[] = $match;
		}
	}
	print_r( $candidateMoves );
	foreach ( $candidateMoves as $key => $move ) {
		echo "$SECOND_PASS_TIME - $moveString$move \n";
		$candidateMovesEval[] = getPositionEval( "$moveString$move ", $SECOND_PASS_TIME );
	}

	array_multisort($candidateMovesEval, SORT_DESC, SORT_NUMERIC, $candidateMovesEval);

	$topEval = $candidateMovesEval[0];
	foreach ( $candidateMoves as $key => $move ) {
		if ( ( abs( $topEval - $candidateMovesEval[$key] ) <= $ALT_THRESHOLD
		&& $key < $maxLines
		&& gmp_sign( $topEval ) == gmp_sign( $candidateMovesEval[$key] ) )
		|| ( gmp_sign( $topEval ) * $candidateMovesEval[$key] >= $FORCED_INCLUSION
		&& $key < $maxLines ) ) {
			echo "SELECTED!\n";
		}
		echo $candidateMovesEval[$key]." - ".$move."\n";
	}
}

function getPositionEval( $moveString, $moveTime ) {
	$uciOutput = getUci( $moveString, $moveTime );
	//print_r($uciOutput);
	preg_match_all( "/cp (-?[0-9].*?) /", $uciOutput, $matches );
	return end( $matches[1] );
}
<commit_msg>allow forced inclusion of other good lines<commit_after><?php

function createProblems ( $game ) {
	//Input: A game that consists of a list of moves.
	//Output: A list of problems
	global $BALANCED, $UNBALANCED;

	foreach ( $game['analysis'] as $moveKey => $move ) {
		echo ceil( $move['ply'] / 2 ).( ($move['ply']%2 == 0)? "... " : ". " ).$move['move'];

		$lines = array();

		if ( isset( $move['eval'] ) && isset( $game['analysis'][$moveKey + 1]['eval'] ) ){

			if ( ( $move['eval'] <= $BALANCED && $game['analysis'][$moveKey + 1]['eval'] >= $UNBALANCED ) 
				|| ( $move['eval'] >= -$BALANCED && $game['analysis'][$moveKey + 1]['eval'] <= -$UNBALANCED ) ) {

				//pass the moves list and position of change of advantage to a subprocess

				$lines[] = findCaptureLine( $game['uci'], $moveKey );


				echo " Change of advantage detected: ".$move['eval']." -> ".$game['analysis'][$moveKey + 1]['eval'];
			}
		}
		echo "\n";
		
		//var_dump($move);
	}
}

function findCaptureLine ( $movesUci, $ply ) {
	//Input: A string of moves and the starting move for the tactical line
	//Output: The actual tactical line

	//The ply played is the starting position. The ply after that is the blunder, 
	//and the ply after that is what the user has to find.

	/*
	
	$start position <= FEN position from ply count
	$first player move <= next successive move

	*/
	$movesUci = explode( ' ', $movesUci );
	$startMoveString = '';
	for ( $x = 0; $x <= $ply + 1; $x++ ){
		$startMoveString .= $movesUci[$x].' ';
	}

	//now parse this string to stockfish!
	//echo "\n".$startMoveString."\n";
	//$uciOutput = getLines( $startMoveString );
	$solutionMap = buildCaptureTree( $startMoveString );

	//$captureArray = captureArray( $movesUci );
}

function buildCaptureTree( $moveString ) {
	//Input: List of moves in UCI format
	//Output: Map of the correct tactical line
	global $MAX_CAPTURE_LINES;

	$movesList = getMovesListFromPosition( $moveString, $MAX_CAPTURE_LINES, TRUE );
}

function getMovesListFromPosition ( $moveString, $maxLines, $allowForcedInclusion ) {
	global $FIRST_PASS_TIME, $SECOND_PASS_TIME, $ALT_THRESHOLD, $FORCED_INCLUSION;

	$uciOutput = getUci( $moveString, $FIRST_PASS_TIME );

	preg_match_all( "/info.*?cp (-?[0-9]*).*?([a-h][1-8][a-h][1-8][qrnb]?)/", $uciOutput, $matches );

	$candidateMoves = array();
	$candidateMovesEval = array();

	foreach ( $matches[2] as $key => $match ) {
		if ( !in_array( $match , $candidateMoves) ) {
			$candidateMoves[] = $match;
		}
	}
	print_r( $candidateMoves );
	foreach ( $candidateMoves as $key => $move ) {
		echo "$SECOND_PASS_TIME - $moveString$move \n";
		$candidateMovesEval[] = getPositionEval( "$moveString$move ", $SECOND_PASS_TIME );
	}

	array_multisort($candidateMovesEval, SORT_DESC, SORT_NUMERIC, $candidateMovesEval);

	$topEval = $candidateMovesEval[0];
	foreach ( $candidateMoves as $key => $move ) {
		if ( ( abs( $topEval - $candidateMovesEval[$key] ) <= $ALT_THRESHOLD
		&& $key < $maxLines
		&& gmp_sign( $topEval ) == gmp_sign( $candidateMovesEval[$key] ) )
		|| ( gmp_sign( $topEval ) * $candidateMovesEval[$key] >= $FORCED_INCLUSION
		&& $key < $maxLines
		&& $allowForcedInclusion == TRUE ) ) {
			echo "SELECTED!\n";
		}
		echo $candidateMovesEval[$key]." - ".$move."\n";
	}
}

function getPositionEval( $moveString, $moveTime ) {
	$uciOutput = getUci( $moveString, $moveTime );
	//print_r($uciOutput);
	preg_match_all( "/cp (-?[0-9].*?) /", $uciOutput, $matches );
	return end( $matches[1] );
}

{'fraction_non_alphanumeric': 0.18619186046511627, 'fraction_numerical': 0.005813953488372093, 'mean_word_length': 4.146596858638744, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2716674', 'n_tokens_mistral': 2711, 'n_tokens_neox': 2515, 'n_words': 598}