<commit_before>
import { expect } from 'chai';

const RGTest = require('../../roguetest');
const RG = require('../../../client/src/battles');
// const Goal = require('../../../client/src/goals');

describe('Goal', () => {
    it('', () => {
        const movSys = new RG.System.Movement(['Movement']);
        const attSys = new RG.System.Attack(['Attack']);
        const dmgSys = new RG.System.Damage(['Damage']);
        const systems = [movSys, attSys, dmgSys];

        const actor = new RG.Actor.Rogue('thinker');
        const enemy = new RG.Actor.Rogue('enemy');
        actor.setBrain(new RG.Brain.GoalOriented(actor));

        actor.addEnemy(enemy);
        enemy.addEnemy(actor);
        const startHP = enemy.get('Health').getHP();
        const level = RGTest.wrapIntoLevel([actor, enemy]);
        RGTest.moveEntityTo(actor, 5, 5);
        RGTest.moveEntityTo(actor, 17, 17);

        let [x, y] = actor.getXY();
        let action = actor.nextAction();
        action.doAction();
        systems.forEach(sys => {sys.update();});

        const [nX, nY] = actor.getXY();
        console.log(`Actor at nX,nY ${nX},${nY}`);

        const coordSame = x === nX && y === nY;
        expect(coordSame).not.to.equal(true);

        RGTest.moveEntityTo(actor, 2, 2);
        RGTest.moveEntityTo(enemy, 5, 5);

        for (let i = 0; i < 5; i++) {
            console.log(`>>> TURN ${i} BEGIN <<<`);
            action = actor.nextAction();
            action.doAction();
            systems.forEach(sys => {sys.update();});
            const [x, y] = actor.getXY();
            console.log(`-> Actor location: ${x},${y}`);
        }
        // RGTest.printScreen(actor);
        const endHP = enemy.get('Health').getHP();
        expect(endHP).to.be.below(startHP);

        [x, y] = actor.getXY();
        expect([x, y]).to.deep.equal([4, 4]);
        actor.get('Health').setHP(5);
        for (let i = 0; i < 1; i++) {
            action = actor.nextAction();
            action.doAction();
            systems.forEach(sys => {sys.update();});
            [x, y] = actor.getXY();
            expect([x, y]).to.deep.equal([3, 3]);
        }

    });
});<commit_msg>Added test for checking Evaluator and Goal.ORders.<commit_after>
import { expect } from 'chai';

const RGTest = require('../../roguetest');
const RG = require('../../../client/src/battles');

const Goal = require('../../../client/src/goals');
const Evaluator = require('../../../client/src/evaluators');

describe('Goal', () => {

    let movSys = null;
    let attSys = null;
    let dmgSys = null;
    let systems = null;

    beforeEach(() => {
        movSys = new RG.System.Movement(['Movement']);
        attSys = new RG.System.Attack(['Attack']);
        dmgSys = new RG.System.Damage(['Damage']);
        systems = [movSys, attSys, dmgSys];
    });

    it('it indicates to actor what to do', () => {

        const actor = new RG.Actor.Rogue('thinker');
        const enemy = new RG.Actor.Rogue('enemy');
        actor.setBrain(new RG.Brain.GoalOriented(actor));

        actor.addEnemy(enemy);
        enemy.addEnemy(actor);
        const startHP = enemy.get('Health').getHP();
        RGTest.wrapIntoLevel([actor, enemy]);
        RGTest.moveEntityTo(actor, 5, 5);
        RGTest.moveEntityTo(actor, 17, 17);

        let [x, y] = actor.getXY();
        let action = actor.nextAction();
        action.doAction();
        systems.forEach(sys => {sys.update();});

        const [nX, nY] = actor.getXY();

        const coordSame = x === nX && y === nY;
        expect(coordSame).not.to.equal(true);

        RGTest.moveEntityTo(actor, 2, 2);
        RGTest.moveEntityTo(enemy, 5, 5);

        RGTest.updateGame(actor, systems, 5);
        // RGTest.printScreen(actor);
        const endHP = enemy.get('Health').getHP();
        expect(endHP, 'Health must decrease').to.be.below(startHP);

        [x, y] = actor.getXY();
        expect([x, y]).to.deep.equal([4, 4]);
        actor.get('Health').setHP(5);
        for (let i = 0; i < 1; i++) {
            action = actor.nextAction();
            action.doAction();
            systems.forEach(sys => {sys.update();});
            [x, y] = actor.getXY();
            expect([x, y]).to.deep.equal([3, 3]);
        }

    });

    it('can be injected into actor via "commander"', () => {
        const commander = new RG.Actor.Rogue('commander');
        const soldier = new RG.Actor.Rogue('soldier');
        const actors = [commander, soldier];
        commander.setBrain(new RG.Brain.GoalOriented(commander));
        soldier.setBrain(new RG.Brain.GoalOriented(soldier));

        RGTest.wrapIntoLevel(actors);
        RGTest.moveEntityTo(commander, 2, 2);
        RGTest.moveEntityTo(soldier, 3, 3);

        const topGoal = soldier.getBrain().getGoal();
        topGoal.removeEvaluators();
        const ordersGoal = new Goal.Orders(soldier);
        ordersGoal.addSubGoal(new Goal.FollowPath(soldier, [10, 10]));

        const orderBias = 1.0;
        const commandEval = new Evaluator.Orders(orderBias);
        commandEval.setArgs({srcActor: commander, goal: ordersGoal});
        topGoal.giveOrders(commandEval);

        RGTest.updateGame(actors, systems, 11);

        const sXY = soldier.getXY();
        expect(sXY).to.deep.equal([10, 10]);
    });

});
{'fraction_non_alphanumeric': 0.1830188679245283, 'fraction_numerical': 0.01, 'mean_word_length': 2.302803738317757, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 18, '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': '643501', 'n_tokens_mistral': 1822, 'n_tokens_neox': 1706, 'n_words': 348}