<commit_before>var m = require('mithril');

function fenToUci(fen) {
  // convert three check fens
  // lichess: rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1 +0+0
  // stockfish: rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 3+3 0 1
  var m = fen.match(/^(.+) (w|b) (.+) (.+) (\d+) (\d+) \+(\d+)\+(\d+)$/);
  if (!m) return fen;
  else {
    var w = parseInt(m[7], 10);
    var b = parseInt(m[8], 10);
    var checks = (3 - w) + '+' + (3 - b);
    var fen = [m[1], m[2], m[3], m[4], checks, m[5], m[6]].join(' ');
    return fen;
  }
}

module.exports = function(worker, opts) {

  var work = null;
  var stopped = m.deferred();

  if (opts.hashSize)
    worker.send('setoption name Hash value 128');

  var threads = Math.ceil((navigator.hardwareConcurrency || 1) / 2);
  if (threads > 1) worker.send('setoption name Threads value ' + threads);

  if (opts.variant.key === 'fromPosition' || opts.variant.key === 'chess960')
    worker.send('setoption name UCI_Chess960 value true');
  else if (opts.variant.key === 'antichess')
    worker.send('setoption name UCI_Variant value giveaway');
  else if (opts.variant.key !== 'standard')
    worker.send('setoption name UCI_Variant value ' + opts.variant.key.toLowerCase());

  var processOutput = function(text) {
    if (text.indexOf('bestmove ') === 0) {
      stopped.resolve(true);
      return;
    }
    if (!work) return;
    if (/currmovenumber|lowerbound|upperbound/.test(text)) return;
    var matches = text.match(/depth (\d+) .*score (cp|mate) ([-\d]+) .*nps (\d+) .*pv (.+)/);
    if (!matches) return;
    var depth = parseInt(matches[1]);
    if (depth < opts.minDepth) return;
    var cp, mate;
    if (matches[2] === 'cp') cp = parseFloat(matches[3]);
    else mate = parseFloat(matches[3]);
    if (work.ply % 2 === 1) {
      if (matches[2] === 'cp') cp = -cp;
      else mate = -mate;<commit_msg>warm up the webworker<commit_after>var m = require('mithril');

function fenToUci(fen) {
  // convert three check fens
  // lichess: rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1 +0+0
  // stockfish: rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 3+3 0 1
  var m = fen.match(/^(.+) (w|b) (.+) (.+) (\d+) (\d+) \+(\d+)\+(\d+)$/);
  if (!m) return fen;
  else {
    var w = parseInt(m[7], 10);
    var b = parseInt(m[8], 10);
    var checks = (3 - w) + '+' + (3 - b);
    var fen = [m[1], m[2], m[3], m[4], checks, m[5], m[6]].join(' ');
    return fen;
  }
}

module.exports = function(worker, opts) {

  var work = null;
  var stopped = m.deferred();

  if (opts.hashSize)
    worker.send('setoption name Hash value 128');

  var threads = Math.ceil((navigator.hardwareConcurrency || 1) / 2);
  if (threads > 1) worker.send('setoption name Threads value ' + threads);

  if (opts.variant.key === 'fromPosition' || opts.variant.key === 'chess960')
    worker.send('setoption name UCI_Chess960 value true');
  else if (opts.variant.key === 'antichess')
    worker.send('setoption name UCI_Variant value giveaway');
  else if (opts.variant.key !== 'standard')
    worker.send('setoption name UCI_Variant value ' + opts.variant.key.toLowerCase());
  else
    worker.send('isready'); // warm up the webworker

  var processOutput = function(text) {
    if (text.indexOf('bestmove ') === 0) {
      stopped.resolve(true);
      return;
    }
    if (!work) return;
    if (/currmovenumber|lowerbound|upperbound/.test(text)) return;
    var matches = text.match(/depth (\d+) .*score (cp|mate) ([-\d]+) .*nps (\d+) .*pv (.+)/);
    if (!matches) return;
    var depth = parseInt(matches[1]);
    if (depth < opts.minDepth) return;
    var cp, mate;
    if (matches[2] === 'cp') cp = parseFloat(matches[3]);
    else mate = parseFloat(matches[3]);
    if (work.ply % 2 === 1) {
      if (matches[2] === 'cp') cp = -cp;
      else mate = -mate;
{'fraction_non_alphanumeric': 0.19979134063641105, 'fraction_numerical': 0.02608242044861763, 'mean_word_length': 3.0972222222222223, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 8, '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': '3508265', 'n_tokens_mistral': 1524, 'n_tokens_neox': 1441, 'n_words': 356}