<commit_before>'use strict';

const rethinkDB = require('rethinkdb');
const program = require('commander');

const common = require('./../server/common');
const log = require('./../server/log');

const worldGenerator = require('./WorldGenerator');
const coralGenerator = require('./CoralUserGenerator');

/*
The system of locations.
0.* Impassable blocks
  0.1 a wall (!!!should be renamed!!!)
  0.2 a tree

1.* Passable blocks
  1.1 a ground
  1.2 a grass

2.* Gates and entrances
  2.1 Entrance to dungeon
  2.2 Exit from dungeon
 */


if (require.main === module) {
  program
  .version('0.0.1')
  .option('-d, --dbname [name]', 'Name of world database')
  .option('-p, --port <n>', 'Port for RethinkDB, default is 28015', parseInt, {isDefault: 28015})
  .option('-t, --test <n>', 'Create n Corals', parseInt)
  .option('-g, --dungeons <n>', 'Create n Dungeons', parseInt)
  .parse(process.argv);

  rethinkDB.connect( {host: 'localhost', port: program.port}, function(err, conn) {
    if (err) throw err;

    rethinkDB
      .dbCreate(program.dbname)
      .run(conn, (err) => {
        if (err) {
          log.error(`The world is exist. `
            + `If you really want create a new world, `
            + `delete the database "${program.dbname}".`);

          throw  err;
        }

        conn.use(program.dbname);

        const generator = new worldGenerator.WorldGenerator(conn, 3, 100, program.dungeons);
        const startLocationId = generator.generate();
        log.info(`start location id is ${startLocationId}`);

        if (program.test) {
          const userGenerator = new coralGenerator.CoralUserGenerator(conn, program.test, startLocationId);
          userGenerator.generate();
        }
      });
  });
}<commit_msg>Add config in world generator<commit_after>'use strict';

const rethinkDB = require('rethinkdb');
const program = require('commander');

const common = require('./../server/common');
const log = require('./../server/log');

const worldGenerator = require('./WorldGenerator');
const coralGenerator = require('./CoralUserGenerator');

/*
The system of locations.
0.* Impassable blocks
  0.1 a wall (!!!should be renamed!!!)
  0.2 a tree

1.* Passable blocks
  1.1 a ground
  1.2 a grass

2.* Gates and entrances
  2.1 Entrance to dungeon
  2.2 Exit from dungeon
 */


if (require.main === module) {
  program
  .version('0.0.1')
  .option('-c, --config [path]', 'Path to config')
  .parse(process.argv);

  const config = require(program.config);

  rethinkDB.connect( {host: config.rethink.dbhost, port: config.rethink.dbport}, function(err, conn) {
    if (err) throw err;

    rethinkDB
      .dbCreate(config.rethink.dbname)
      .run(conn, (err) => {
        if (err) {
          log.error(`The world is exist. `
            + `If you really want create a new world, `
            + `delete the database "${config.rethink.dbname}".`);

          throw  err;
        }

        conn.use(config.rethink.dbname);

        const generator = new worldGenerator.WorldGenerator(
          conn,
          config.world.worldSize,
          config.world.locationSize,
          config.world.dungeons);

        const startLocationId = generator.generate();
        log.info(`start location id is ${startLocationId}`);

        if (config.test.users > 0) {
          const userGenerator = new coralGenerator.CoralUserGenerator(
            conn,
            config.test.users,
            config.test.prefix,
            startLocationId);

          userGenerator.generate();
        }
      });
  });
}
{'fraction_non_alphanumeric': 0.14603890611784606, 'fraction_numerical': 0.014378347899633492, 'mean_word_length': 2.620408163265306, 'pattern_counts': {'":': 0, '<': 6, '<?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': '5081112', 'n_tokens_mistral': 1104, 'n_tokens_neox': 1073, 'n_words': 296}