<commit_before>'use strict';
const theGameFactory = require('./theGameFactory');
const tileTypes = require('./tileTypes');

const namespace = process.argv[2] || 'flood';
const dl24client = require('../../dl24client');
const config = require('./config');
config.port = process.argv[3] || config.port;
config.loggerPort = process.argv[4] || config.loggerPort;
const logger = require('../../logger')(namespace, config.loggerPort);
const gridder = require('../../gridder')(namespace, config.gridderPort);
const stateUpdater = require('../../stateUpdater')(namespace, config.stateUpdaterPort);
const debugState = require('../../stateUpdater')('debug', config.stateUpdaterPort);

let lastWorldDescriptor = '';
let theGame = theGameFactory(gridder, logger, stateUpdater, debugState);

const getRandomInt = (min, max) => (Math.floor(Math.random() * (max - min)) + min);

const gameLoop = (service) => {
    service.multiWrite(['DESCRIBE_WORLD', 'FLOOD_STATUS', 'FORECAST', 'LIST_OBJECTS', 'LIST_WORKERS'], () => {
    service.fancyRead(1, ([worldResponse]) => {
    service.fancyRead(1, ([floodStatus]) => {
    service.fancyMultipleRead(forecastLines => {
    service.fancyMultipleRead(objectsLines => {
    service.fancyMultipleRead(workersLines => {
        theGame.init(worldResponse);

        theGame.mapObjects(objectsLines);
        theGame.mapWorkers(workersLines);
        theGame.floodStatus(floodStatus);
        theGame.setForecast(forecastLines);

        if (!theGame.getWorkers().length) {
            console.log('no workers, no problem');
            service.simpleNextTurn();

            return;
        }

        if (theGame.isFlooding()) {
            const writes = [];
            theGame.getWorkers().forEach(fleeingWorker => {
                const tile = theGame.getTile(fleeingWorker);

                if (tile.tileType !== tileTypes.magazine) {
                    const vector = theGame.vectorToMagazine(fleeingWorker);

                    writes.push(`MOVE ${fleeingWorker.id} ${vector.x} ${vector.y}`);
                }
            });

            if (!writes.length) {
                service.simpleNextTurn();

                return;
            }

            service.multiWrite(writes, () => {
                service.simpleNextTurn();
            });

            return;
        }

        const shouldTakeBags = worker => {
            const tile = theGame.getTile(worker);
            return !worker.bags && tile.tileType === tileTypes.magazine;
        };

        const shouldLeaveBags = worker => {
            console.log('SHOULD LEAVE\n\n\n\n');
            const tile = theGame.getTile(worker);
            if (!tile) {
                console.log('FALSE because no tile wtf');
                console.log('\n\n\n\n');
                return false;
            }

            const isStack = theGame.isStack(tile);
            console.log(worker.bags, isStack);
            console.log('\n\n\n\n');

            return worker.bags && isStack;<commit_msg>if no bags in magazine, stay there<commit_after>'use strict';
const theGameFactory = require('./theGameFactory');
const tileTypes = require('./tileTypes');

const namespace = process.argv[2] || 'flood';
const dl24client = require('../../dl24client');
const config = require('./config');
config.port = process.argv[3] || config.port;
config.loggerPort = process.argv[4] || config.loggerPort;
const logger = require('../../logger')(namespace, config.loggerPort);
const gridder = require('../../gridder')(namespace, config.gridderPort);
const stateUpdater = require('../../stateUpdater')(namespace, config.stateUpdaterPort);
const debugState = require('../../stateUpdater')('debug', config.stateUpdaterPort);

let lastWorldDescriptor = '';
let theGame = theGameFactory(gridder, logger, stateUpdater, debugState);

const getRandomInt = (min, max) => (Math.floor(Math.random() * (max - min)) + min);

const gameLoop = (service) => {
    service.multiWrite(['DESCRIBE_WORLD', 'FLOOD_STATUS', 'FORECAST', 'LIST_OBJECTS', 'LIST_WORKERS'], () => {
    service.fancyRead(1, ([worldResponse]) => {
    service.fancyRead(1, ([floodStatus]) => {
    service.fancyMultipleRead(forecastLines => {
    service.fancyMultipleRead(objectsLines => {
    service.fancyMultipleRead(workersLines => {
        theGame.init(worldResponse);

        theGame.mapObjects(objectsLines);
        theGame.mapWorkers(workersLines);
        theGame.floodStatus(floodStatus);
        theGame.setForecast(forecastLines);

        if (!theGame.getWorkers().length) {
            console.log('no workers, no problem');
            service.simpleNextTurn();

            return;
        }

        if (theGame.isFlooding()) {
            const writes = [];
            theGame.getWorkers().forEach(fleeingWorker => {
                const tile = theGame.getTile(fleeingWorker);

                if (tile.tileType !== tileTypes.magazine) {
                    const vector = theGame.vectorToMagazine(fleeingWorker);

                    writes.push(`MOVE ${fleeingWorker.id} ${vector.x} ${vector.y}`);
                }
            });

            if (!writes.length) {
                service.simpleNextTurn();

                return;
            }

            service.multiWrite(writes, () => {
                service.simpleNextTurn();
            });

            return;
        }

        const shouldTakeBags = worker => {
            const tile = theGame.getTile(worker);
            return !worker.bags && tile.tileType === tileTypes.magazine && tile.bags;
        };

        const shouldLeaveBags = worker => {
            console.log('SHOULD LEAVE\n\n\n\n');
            const tile = theGame.getTile(worker);
            if (!tile) {
                console.log('FALSE because no tile wtf');
                console.log('\n\n\n\n');
                return false;
            }

            const isStack = theGame.isStack(tile);
            console.log(worker.bags, isStack);
            console.log('\n\n\n\n');

            return worker.bags && isStack;
{'fraction_non_alphanumeric': 0.1482587064676617, 'fraction_numerical': 0.0029850746268656717, 'mean_word_length': 2.3431263858093128, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, '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': '1515670', 'n_tokens_mistral': 1745, 'n_tokens_neox': 1684, 'n_words': 298}