<commit_before>// Combines chessboard.js and chess.js

function ChessGame(el, cfg) {
	var position = cfg.position || undefined;
	var game = new Chess(position);

	function onDragStart(source, piece, position, orientation) {
		var turn = game.turn();
		return !game.game_over() && turn === cfg.side.charAt(0) && turn === piece.charAt(0);
	}

	function onDrop(source, target) {
		// see if the move is legal
		var move = game.move({
			from: source,
			to: target,
			promotion: 'q' // NOTE: always promote to a pawn for example simplicity
		});

		// illegal move
		if( move === null )
			return 'snapback';

		if( cfg.onMove ) {
			cfg.onMove([source, target].join('-'), game.fen());
		}
	}

	// update the board position after the piece snap 
	// for castling, en passant, pawn promotion
	function onSnapEnd() {
		board.position(game.fen());
	};

	cfg.position = game.fen();
	cfg.draggable = Boolean(cfg.side);
	cfg.orientation = (cfg.side || 'white');
	cfg.onDragStart = onDragStart;
	cfg.onDrop = onDrop;
	cfg.onSnapEnd = onSnapEnd;

	var board = new ChessBoard(el, cfg);

	this.move = function(mv) {
		var parts = mv.split('-');
		if( game.move({ from: parts[0], to: parts[1] }) === null )
			return;
		board.move(mv);
	}

	this.status = function() {
		var status = '';

		var moveColor = 'White';
		if( game.turn() === 'b' ) {
			moveColor = 'Black';
		}

		// checkmate?
		if( game.in_checkmate() ) {
			status = 'Game over, ' + moveColor + ' is in checkmate.';
		}

		// draw?
		else if( game.in_draw() ) {
			status = 'Game over, drawn position';<commit_msg>fix for promotion, castling, en passant to be properly seen by other side<commit_after>// Combines chessboard.js and chess.js

function ChessGame(el, cfg) {
	var position = cfg.position || undefined;
	var game = new Chess(position);

	function onDragStart(source, piece, position, orientation) {
		var turn = game.turn();
		return !game.game_over() && turn === cfg.side.charAt(0) && turn === piece.charAt(0);
	}

	function onDrop(source, target) {
		// see if the move is legal
		var move = game.move({
			from: source,
			to: target,
			promotion: 'q' // NOTE: always promote to a pawn for example simplicity
		});

		// illegal move
		if( move === null )
			return 'snapback';

		if( cfg.onMove ) {
			cfg.onMove([source, target].join('-'), game.fen());
		}
	}

	// update the board position after the piece snap 
	// for castling, en passant, pawn promotion
	function onSnapEnd() {
		board.position(game.fen());
	};

	cfg.position = game.fen();
	cfg.draggable = Boolean(cfg.side);
	cfg.orientation = (cfg.side || 'white');
	cfg.onDragStart = onDragStart;
	cfg.onDrop = onDrop;
	cfg.onSnapEnd = onSnapEnd;

	var board = new ChessBoard(el, cfg);

	this.move = function(mv) {
		var parts = mv.split('-');
		var move = {
			from: parts[0],
			to: parts[1],
			promotion: 'q' // NOTE: always promote to a pawn for example simplicity
		};

		if( game.move(move) === null )
			return;

		board.position(game.fen());
	}

	this.status = function() {
		var status = '';

		var moveColor = 'White';
		if( game.turn() === 'b' ) {
			moveColor = 'Black';
		}

		// checkmate?
		if( game.in_checkmate() ) {
			status = 'Game over, ' + moveColor + ' is in checkmate.';
		}

		// draw?
		else if( game.in_draw() ) {
			status = 'Game over, drawn position';
{'fraction_non_alphanumeric': 0.1631912964641886, 'fraction_numerical': 0.0024176488365064974, 'mean_word_length': 3.21656050955414, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2940230', 'n_tokens_mistral': 1273, 'n_tokens_neox': 1145, 'n_words': 322}