<commit_before>
require('babel-register');

const expect = require('chai').expect;
const RG = require('../client/src/battles');
const Keys = require('../client/src/keymap');
const fs = require('fs');

const restKey = {code: Keys.KEY.REST};

const RNG = RG.Random.getRNG();
const ROT = require('../lib/rot');

RNG.setSeed(0);
ROT.RNG.setSeed(0);

console.log('RNG uniform: ' + RNG.getUniform());
console.log('ROT.RNG uniform: ' + ROT.RNG.getUniform());

const gameConf = {
    cols: 60,
    rows: 30,
    levels: 2,

    playerLevel: 'Medium',
    levelSize: 'Medium',
    playerClass: RG.ACTOR_CLASSES[0],
    playerRace: RG.ACTOR_RACES[0],

    sqrPerActor: 120,
    sqrPerItem: 120,
    playMode: 'Arena',
    loadedPlayer: null,
    loadedLevel: null,
    playerName: 'Player'
};
const gameFact = new RG.Factory.Game();
let game = gameFact.createNewGame(gameConf);

// Simulate 1st serialisation in worker thread
let gameJSON = game.toJSON();
let fromJSON = new RG.Game.FromJSON();
game = fromJSON.createGame(gameJSON);

// Used with expect() later
const saveFunc = () => {
    fromJSON = new RG.Game.FromJSON();
    gameJSON = game.toJSON();
    game = fromJSON.createGame(gameJSON);
};

const updateFunc = () => {
    game.update(restKey);
};

const simulSpellOn1stTurn = () => {
    game.update({code: Keys.KEY.POWER});
    game.update({code: Keys.VK_h});
};
// expect(simulSpellOn1stTurn).not.to.throw(Error);

const timeStart = new Date().getTime();
const numTurns = 1000;
for (let i = 0; i < numTurns; i++) {
    // expect(updateFunc).not.to.throw(Error);
    updateFunc();

    if (i === 10) {
        expect(simulSpellOn1stTurn).not.to.throw(Error);
    }
    if (i % 5000 === 0 && i > 0) {
        console.log(`Saving game after ${i}/${numTurns} turns`);
        expect(saveFunc).not.to.throw(Error);
        // saveFunc();
    }
    console.log('Finished turn ' + i);
}
const timeEnd = new Date().getTime();
const dur = timeEnd - timeStart;
console.log('Execution took ' + dur + ' ms');

const fps = numTurns / (dur / 1000);
console.log('FPS: ' + fps);

fromJSON = new RG.Game.FromJSON();
gameJSON = game.toJSON();
fs.writeFileSync('results/debug-game.json',
    JSON.stringify(gameJSON));

<commit_msg>Added printing of turn number.<commit_after>
require('babel-register');

const expect = require('chai').expect;
const RG = require('../client/src/battles');
const Keys = require('../client/src/keymap');
const fs = require('fs');

const restKey = {code: Keys.KEY.REST};

const RNG = RG.Random.getRNG();
const ROT = require('../lib/rot');

RNG.setSeed(0);
ROT.RNG.setSeed(0);

console.log('RNG uniform: ' + RNG.getUniform());
console.log('ROT.RNG uniform: ' + ROT.RNG.getUniform());

const gameConf = {
    cols: 60,
    rows: 30,
    levels: 2,

    playerLevel: 'Medium',
    levelSize: 'Medium',
    playerClass: RG.ACTOR_CLASSES[0],
    playerRace: RG.ACTOR_RACES[0],

    sqrPerActor: 120,
    sqrPerItem: 120,
    playMode: 'Arena',
    loadedPlayer: null,
    loadedLevel: null,
    playerName: 'Player'
};
const gameFact = new RG.Factory.Game();
let game = gameFact.createNewGame(gameConf);

// Simulate 1st serialisation in worker thread
let gameJSON = game.toJSON();
let fromJSON = new RG.Game.FromJSON();
game = fromJSON.createGame(gameJSON);

// Used with expect() later
const saveFunc = () => {
    fromJSON = new RG.Game.FromJSON();
    gameJSON = game.toJSON();
    game = fromJSON.createGame(gameJSON);
};

const updateFunc = () => {
    game.update(restKey);
};

const simulSpellOn1stTurn = () => {
    game.update({code: Keys.KEY.POWER});
    game.update({code: Keys.VK_h});
};
// expect(simulSpellOn1stTurn).not.to.throw(Error);

const timeStart = new Date().getTime();
const numTurns = 10000;
for (let i = 1; i <= numTurns; i++) {
    // expect(updateFunc).not.to.throw(Error);
    updateFunc();

    if (i === 10) {
        expect(simulSpellOn1stTurn).not.to.throw(Error);
    }
    if (i % 1000 === 0) {
        console.log(`Saving game after ${i}/${numTurns} turns`);
        expect(saveFunc).not.to.throw(Error);
        // saveFunc();
    }
    if (i % 10 === 0) {
        console.log('Finished turn ' + i);
    }
}
const timeEnd = new Date().getTime();
const dur = timeEnd - timeStart;
console.log('Execution took ' + dur + ' ms');

const fps = numTurns / (dur / 1000);
console.log('FPS: ' + fps);

fromJSON = new RG.Game.FromJSON();
gameJSON = game.toJSON();
fs.writeFileSync('results/debug-game.json',
    JSON.stringify(gameJSON));


{'fraction_non_alphanumeric': 0.17850759606791777, 'fraction_numerical': 0.01675603217158177, 'mean_word_length': 3.5131048387096775, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 10, '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': '891428', 'n_tokens_mistral': 1686, 'n_tokens_neox': 1589, 'n_words': 340}