<commit_before>/**
 * @file
 * @author <NAME>
 * @brief Implementation of src/control/ai/aictrl.hxx
 */

/*
 * aictrl.cxx
 *
 *  Created on: 16.02.2011
 *      Author: jason
 */

#if !defined(DEBUG) && !defined(NDEBUG)
#define NDEBUG
#endif

#include <algorithm>
#include <map>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <exception>
#include <stdexcept>

#include <libconfig.h++>

#include "aictrl.hxx"
#include "aimod.hxx"
#include "src/secondary/confreg.hxx"
#include "src/globals.hxx"
#include "src/ship/ship.hxx"
#include "src/tcl_iface/bridge.hxx"

using namespace std;
using namespace libconfig;

#define TIME_BETWEEN_ACTIONS 50.0f

/* Map of strings to module factories. This is created the first
 * time a module is registered.
 */
static map<string, AIControl::module_factory>* factories;

void AIControl::init(const Setting& conf) {
  if (iaicInfo)
    iaicInfoPrefix = "iaic." + conf.getPath();

  //Load the states
  for (int i=0; i<conf.getLength(); ++i) {
    const Setting& state(conf[i]);
    const char* stateName = state.getName();
    State s;
    s.totalWeight=0;

    for (int j=0; j<state.getLength(); ++j) {
      const char* modname=state[j]["module"];
      int weight = state[j]["weight"];
      if (weight <= 0)
        throw runtime_error("Negative weight for module");
      AIModule* module = createAIModule(modname, state[j]);
      if (!module)
        throw runtime_error("Unrecognised module name");
      Module mod = { module, weight };
      s.modules.push_back(mod);
      s.totalWeight += weight;
    }

    if (s.modules.empty())
      throw runtime_error("Empty state");

    states[string(stateName)] = s;
  }

  if (!states.size())
    throw runtime_error("Empty AI information");
<commit_msg>Correct signedness of loop counters in AIControl::Init().<commit_after>/**
 * @file
 * @author <NAME>
 * @brief Implementation of src/control/ai/aictrl.hxx
 */

/*
 * aictrl.cxx
 *
 *  Created on: 16.02.2011
 *      Author: jason
 */

#if !defined(DEBUG) && !defined(NDEBUG)
#define NDEBUG
#endif

#include <algorithm>
#include <map>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <exception>
#include <stdexcept>

#include <libconfig.h++>

#include "aictrl.hxx"
#include "aimod.hxx"
#include "src/secondary/confreg.hxx"
#include "src/globals.hxx"
#include "src/ship/ship.hxx"
#include "src/tcl_iface/bridge.hxx"

using namespace std;
using namespace libconfig;

#define TIME_BETWEEN_ACTIONS 50.0f

/* Map of strings to module factories. This is created the first
 * time a module is registered.
 */
static map<string, AIControl::module_factory>* factories;

void AIControl::init(const Setting& conf) {
  if (iaicInfo)
    iaicInfoPrefix = "iaic." + conf.getPath();

  //Load the states
  for (unsigned i=0; i<conf.getLength(); ++i) {
    const Setting& state(conf[i]);
    const char* stateName = state.getName();
    State s;
    s.totalWeight=0;

    for (unsigned j=0; j<state.getLength(); ++j) {
      const char* modname=state[j]["module"];
      int weight = state[j]["weight"];
      if (weight <= 0)
        throw runtime_error("Negative weight for module");
      AIModule* module = createAIModule(modname, state[j]);
      if (!module)
        throw runtime_error("Unrecognised module name");
      Module mod = { module, weight };
      s.modules.push_back(mod);
      s.totalWeight += weight;
    }

    if (s.modules.empty())
      throw runtime_error("Empty state");

    states[string(stateName)] = s;
  }

  if (!states.size())
    throw runtime_error("Empty AI information");

{'fraction_non_alphanumeric': 0.15035345296356717, 'fraction_numerical': 0.008156606851549755, 'mean_word_length': 3.740979381443299, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 29, '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': '7455192', 'n_tokens_mistral': 1286, 'n_tokens_neox': 1260, 'n_words': 324}