<commit_before>'use strict';

require('require');
require('prototype_creep_startup_tasks');
require('prototype_creep_move');
require('prototype_roomPosition');
require('prototype_room_init');
require('prototype_room_costmatrix');
require('visualizer');
require('screepsplus');

console.log('Starting TooAngel AI - Have fun');

brain.stats.init();

let profiler;
if (config.profiler.enabled) {
  try {
    profiler = require('screeps-profiler'); // eslint-disable-line global-require
    for (const role of _.keys(roles)) {
      profiler.registerObject(roles[role], 'Role_' + role);
    }
    profiler.registerObject(brain, 'Brain');
    profiler.enable();
  } catch (e) {
    console.log('screeps-profiler not found');
    config.profiler.enabled = false;
  }
}

const main = function() {
  if (Game.cpu.bucket < 2 * Game.cpu.tickLimit) {
    console.log('Skipping tick ' + Game.time + ' due to lack of CPU.');
    return;
  }

  try {
    brain.prepareMemory();
    brain.handleNextroom();
    brain.handleSquadmanager();
    brain.handleIncomingTransactions();
    brain.handleQuests();
  } catch (e) {
    console.log('Exeception', e);
  }

  brain.stats.addRoot();
  Memory.myRooms = _(Game.rooms).filter((r) => r.execute()).map((r) => r.name).value();
  Memory.myRooms.forEach(visualizer.myRoomDatasDraw);

  brain.saveMemorySegments();

  if (config.visualizer.enabled) {
    visualizer.render();
  }
  brain.stats.add(['cpu'], {
    used: Game.cpu.getUsed(),
  });
};

module.exports.loop = function() {
  if (config.profiler.enabled) {
    profiler.wrap(() => {
      main();
    });
  } else {
    main();
  }
};<commit_msg>catch exceptions in the visualizer<commit_after>'use strict';

require('require');
require('prototype_creep_startup_tasks');
require('prototype_creep_move');
require('prototype_roomPosition');
require('prototype_room_init');
require('prototype_room_costmatrix');
require('visualizer');
require('screepsplus');

console.log('Starting TooAngel AI - Have fun');

brain.stats.init();

let profiler;
if (config.profiler.enabled) {
  try {
    profiler = require('screeps-profiler'); // eslint-disable-line global-require
    for (const role of _.keys(roles)) {
      profiler.registerObject(roles[role], 'Role_' + role);
    }
    profiler.registerObject(brain, 'Brain');
    profiler.enable();
  } catch (e) {
    console.log('screeps-profiler not found');
    config.profiler.enabled = false;
  }
}

const main = function() {
  if (Game.cpu.bucket < 2 * Game.cpu.tickLimit) {
    console.log('Skipping tick ' + Game.time + ' due to lack of CPU.');
    return;
  }

  try {
    brain.prepareMemory();
    brain.handleNextroom();
    brain.handleSquadmanager();
    brain.handleIncomingTransactions();
    brain.handleQuests();
  } catch (e) {
    console.log('Brain Exeception', e);
  }

  brain.stats.addRoot();
  Memory.myRooms = _(Game.rooms).filter((r) => r.execute()).map((r) => r.name).value();
  try {
    Memory.myRooms.forEach(visualizer.myRoomDatasDraw);
  } catch (e) {
    console.log('Visualizer Draw Exeception', e);
  }

  brain.saveMemorySegments();

  try {
    if (config.visualizer.enabled) {
      visualizer.render();
    }
  } catch (e) {
    console.log('Visualizer Render Exeception', e);
  }

  brain.stats.add(['cpu'], {
    used: Game.cpu.getUsed(),
  });
};

module.exports.loop = function() {
  if (config.profiler.enabled) {
    profiler.wrap(() => {
      main();
    });
  } else {
    main();
  }
};
{'fraction_non_alphanumeric': 0.1727325245522819, 'fraction_numerical': 0.0005777007510109763, 'mean_word_length': 3.7897648686030427, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '7265139', 'n_tokens_mistral': 1179, 'n_tokens_neox': 1172, 'n_words': 199}