<commit_before>import Process = require("../process");
import { processTable, storeProcessTable, getProcessById, sleepProcess, killProcess } from "../../kernel/kernel";
import SpawnProcess = require("./spawn");
import { addProcess } from "../../kernel/kernel";
import LibrarianProcess = require("./librarian");
import UpgraderProcess = require("./upgrader");
import DefenseProcess = require("./defense");
import MaintainerProcess = require("./maintainer");
import MiningProcess = require("../mining/mining");
import StarterProcess = require("./starter");

// import BuilderPlannerProcess = require("./building-planner");
class ColonyProcess extends Process {
    public static start(roomName: string) {
        let p = new ColonyProcess(0, 0);
        addProcess(p);
        storeProcessTable();

        p.memory.roomName = roomName;
        console.log("New room started:" + roomName);
    }

    public classPath = "components.processes.room.colony";

    public getRoomName() {
        return this.memory.roomName;
    }

    public psInfo() {
        return ("ColonyProcess " + this.getRoomName());
    }

    public run(): number {
        let memory = this.memory;
        let room = Game.rooms[memory.roomName];

        let spawnPID = memory.spawnPID;
        if (!spawnPID || !getProcessById(spawnPID)) {
            memory.spawnPID = this.launchSpawnProcess(room.name);
        }
        if (room.controller!.level >= 4 && room.storage && room.storage.store.energy > 10000) {

            let upgraderPID = memory.upgraderPID;

            if (!upgraderPID || !getProcessById(upgraderPID)) {
                console.log("Starting upgrader process for Room:" + room.name);
                memory.upgraderPID = UpgraderProcess.start(memory.roomName, this.pid);
            }

            let defenderPID = memory.defenderPID;
            if (!defenderPID || !getProcessById(defenderPID)) {
                console.log("Starting defender process for Room:" + room.name);
                memory.defenderPID = DefenseProcess.start(memory.roomName, this.pid);
            }

            let maintainerPID = memory.maintainerPID;
            if (!maintainerPID || !getProcessById(maintainerPID)) {
                console.log("Starting maintainer process for room:" + room.name);
                memory.maintainerPID = MaintainerProcess.start(memory.roomName, this.pid);
            }

            let librarianPID = memory.librarianPID;
            if (!librarianPID || !getProcessById(librarianPID)) {
                const p = new LibrarianProcess(0, this.pid);
                addProcess(p);
                p.memory.roomName = room.name;
                memory.librarianPID = p.pid;
            }

            let inRoomMiningPid = memory.miningPIDList || [];
            const miningProcess = _.filter(_.map(inRoomMiningPid, getProcessById));
            if (miningProcess.length === 0) {
                const sources = room.find(FIND_SOURCES) as Source[];
                for (let source of sources) {
                    const sourceId = source.id;
                    const roomName = room.name;
                    let flag = Game.flags[sourceId];
                    if (!flag) {
                        source.pos.createFlag(sourceId, COLOR_YELLOW);
                    }

                    let p = new MiningProcess(0, this.pid);
                    p.memory.sourceId = sourceId;
                    p.memory.spawningRoomName = roomName;
                    p.memory.flagName = sourceId;
                }

                this.killStarterProcess(room.name);
            }
            sleepProcess(this, 100);
        }


        return 0;
    }

    private killStarterProcess(roomName: string) {
        for (const pid in processTable) {
            const p = processTable[pid];
            if (p instanceof StarterProcess && p.memory.roomName === roomName) {
                killProcess(p.pid);
                return;
            }
        }
    }

    private launchSpawnProcess(roomName: string) {
        console.log("Starting spawn process for room:" + roomName);
        let p = SpawnProcess.start(roomName, this.pid);
        p.parentPID = this.pid;
        return p.pid;
    }<commit_msg>Automatically start mining process in room and kill starter process: bug fix<commit_after>import Process = require("../process");
import { processTable, storeProcessTable, getProcessById, sleepProcess, killProcess } from "../../kernel/kernel";
import SpawnProcess = require("./spawn");
import { addProcess } from "../../kernel/kernel";
import LibrarianProcess = require("./librarian");
import UpgraderProcess = require("./upgrader");
import DefenseProcess = require("./defense");
import MaintainerProcess = require("./maintainer");
import MiningProcess = require("../mining/mining");
import StarterProcess = require("./starter");

// import BuilderPlannerProcess = require("./building-planner");
class ColonyProcess extends Process {
    public static start(roomName: string) {
        let p = new ColonyProcess(0, 0);
        addProcess(p);
        storeProcessTable();

        p.memory.roomName = roomName;
        console.log("New room started:" + roomName);
    }

    public classPath = "components.processes.room.colony";

    public getRoomName() {
        return this.memory.roomName;
    }

    public psInfo() {
        return ("ColonyProcess " + this.getRoomName());
    }

    public run(): number {
        let memory = this.memory;
        let room = Game.rooms[memory.roomName];

        let spawnPID = memory.spawnPID;
        if (!spawnPID || !getProcessById(spawnPID)) {
            memory.spawnPID = this.launchSpawnProcess(room.name);
        }
        if (room.controller!.level >= 4 && room.storage && room.storage.store.energy > 10000) {

            let upgraderPID = memory.upgraderPID;

            if (!upgraderPID || !getProcessById(upgraderPID)) {
                console.log("Starting upgrader process for Room:" + room.name);
                memory.upgraderPID = UpgraderProcess.start(memory.roomName, this.pid);
            }

            let defenderPID = memory.defenderPID;
            if (!defenderPID || !getProcessById(defenderPID)) {
                console.log("Starting defender process for Room:" + room.name);
                memory.defenderPID = DefenseProcess.start(memory.roomName, this.pid);
            }

            let maintainerPID = memory.maintainerPID;
            if (!maintainerPID || !getProcessById(maintainerPID)) {
                console.log("Starting maintainer process for room:" + room.name);
                memory.maintainerPID = MaintainerProcess.start(memory.roomName, this.pid);
            }

            let librarianPID = memory.librarianPID;
            if (!librarianPID || !getProcessById(librarianPID)) {
                const p = new LibrarianProcess(0, this.pid);
                addProcess(p);
                p.memory.roomName = room.name;
                memory.librarianPID = p.pid;
            }

            let inRoomMiningPid: number[] = memory.miningPIDList || [];
            inRoomMiningPid = _.filter(inRoomMiningPid, pid => getProcessById(pid));
            if (inRoomMiningPid.length === 0) {
                const sources = room.find(FIND_SOURCES) as Source[];
                for (let source of sources) {
                    const sourceId = source.id;
                    const roomName = room.name;
                    let flag = Game.flags[sourceId];
                    if (!flag) {
                        source.pos.createFlag(sourceId, COLOR_YELLOW);
                    }

                    let p = new MiningProcess(0, this.pid);
                    p = addProcess(p);
                    p.memory.sourceId = sourceId;
                    p.memory.spawningRoomName = roomName;
                    p.memory.flagName = sourceId;
                    inRoomMiningPid.push(p.pid);
                }
                memory.miningPIDList = inRoomMiningPid;
                this.killStarterProcess(room.name);
            }
            sleepProcess(this, 100);
        }


        return 0;
    }

    private killStarterProcess(roomName: string) {
        for (const pid in processTable) {
            const p = processTable[pid];
            if (p instanceof StarterProcess && p.memory.roomName === roomName) {
                killProcess(p.pid);
                return;
            }
        }
    }

    private launchSpawnProcess(roomName: string) {
        console.log("Starting spawn process for room:" + roomName);
        let p = SpawnProcess.start(roomName, this.pid);
        p.parentPID = this.pid;
        return p.pid;
    }
{'fraction_non_alphanumeric': 0.11308767471410419, 'fraction_numerical': 0.0034654037195333254, 'mean_word_length': 1.9937759336099585, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '3298818', 'n_tokens_mistral': 2488, 'n_tokens_neox': 2270, 'n_words': 499}