Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*/node_modules/
.git/*
.idea/*
*.csv
Empty file added .idea/.gitignore
Empty file.
12 changes: 12 additions & 0 deletions .idea/Pokemon-Population-Models.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/dictionaries/redun.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/jsLibraryMappings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions nodejs-by-kd8lvt/BULBASAUR NO HUMANS.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const test = new require('./Test.js')({});
15 changes: 15 additions & 0 deletions nodejs-by-kd8lvt/BULBASAUR.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const Test = require('./Test.js');

if (process.argv[2] && process.argv[2].toLowerCase() == 'humans') {
let test = new Test({
population: {
sexRates: {outOf: 8, mRate: 7},
fertility: {humanFertRate: 10, humanInterference: true}
}
});
test.start();
} else (process.argv[2] == null)
{
let test = new Test();
test.start();
}
151 changes: 151 additions & 0 deletions nodejs-by-kd8lvt/Population.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
class Population {
constructor(options) {
if (options) { //Customized? Maybe!
this.mPop = options.mPop || 14; //Starting male population
this.fPop = options.fPop || 2; //Starting female population
this.eggs = Population.populateEggVars();
this.totalPop = this.mPop + this.fPop;
this.ticks = 0;
this.dataArr = [];
options.sex = options.sex || null; //Shouldn't have to do this, but WebStorm was having a fit.
if (options.sexRates != null) {
this.outOf = options.sexRates.outOf || 8;
this.maleRate = options.sexRates.mRate || 7; //options.sexRates.mRate out of options.sexRates.outOf eggs will hatch male
} else {
this.outOf = 8;
this.maleRate = 7;
}
options.fertility = options.fertility || null;
if (options.fertility != null) {
this.fertRate = options.fertility.fertRate || 50;
this.humanFertRate = options.fertility.humanFertRate || 50;
this.humansSuck = options.fertility.humanInterference || false; //We do.
} else {
this.fertRate = 50;
this.humanFertRate = 50;
this.humansSuck = false; //We still do.
}
} else { //Defaults
this.mPop = 14; //Starting male population
this.fPop = 2; //Starting female population
this.eggs = Population.populateEggVars();
this.totalPop = this.mPop + this.fPop;
this.ticks = 0;
this.dataArr = [];

this.outOf = 8;
this.maleRate = 7;

this.fertRate = 50;
this.humanFertRate = 50;
this.humansSuck = false;
this.fertRate = 50;
this.humanFertRate = 50;
this.humansSuck = false; //We do.
}
}

static randInt(min, max) {
return Math.round(Math.random() * (max - min + 1)) + min;
}

static populateEggVars() {
let _tmp = [];
for (let i=0;i<20;i++) {
_tmp.push(0);
}
return _tmp;
}

tickDeaths() {
for (let i=0;i<this.fPop;i++) {
let death = Population.randInt(1,10000);
if (death <= 243) {
this.fPop -= 1;
}
}
for (let i=0;i<this.mPop;i++) {
let death = Population.randInt(1,10000);
if (death <= 243) {
this.mPop -= 1;
}
}
}

newEgg() {
if (this.chooseSex()) {
this.mPop += 1;
} else {
this.fPop += 1;
}
}

chooseSex() {
return Population.randInt(1,this.outOf) <= this.maleRate;
}

tickNewEggs() {
if (this.mPop >= 1 && (this.humansSuck && this.ticks <= 100)) {
for (let i = 0; i < this.fPop; i++) {
let egg = Population.randInt(1,100);
if (egg <= this.fertRate) this.eggs[this.eggs.length-1] += 1; //Male exists && humans don't currently suck.
}
} else if (this.fPop >= 1) {
for (let i = 0; i < this.fPop; i++) {
let egg = Population.randInt(1,100);
if (egg <= this.humanFertRate) this.eggs[this.eggs.length-1] += 1; //Egg group / Ditto / Human interference... what have you.
}
}
}

tickHatches() {
if (this.eggs[0] > 0) {
console.log(`${this.eggs[0]} Bulbasaur eggs are hatching!`);
for (let i = 0; i < this.eggs[0]; i++) {
this.newEgg();
}
}
}

tickEggs() {
for (let i=0;i<this.eggs.length;i++) {
if (i === this.eggs.length - 1) {
this.eggs[i] = 0;
} else {
this.eggs[i] = this.eggs[i+1];
}
}
}

tick() {
console.clear();
this.ticks += 1;
console.log("Tick: "+this.ticks);
let eggExists = false;
for (let j=0;j<this.eggs.length;j++) {
if (this.eggs[j] > 0) {
eggExists = true;
}
}
if (this.fPop <= 0 && eggExists === false) {
this.extinct = true;
}
this.tickNewEggs();
this.tickHatches();
this.tickDeaths();
this.tickEggs();
this.totalPop = this.mPop + this.fPop;

let waitingEggs = 0;
for (let i=0;i<this.eggs.length;i++) {
waitingEggs += this.eggs[i];
}
console.log('Total Population: '+this.totalPop);
console.log('Females: '+this.fPop);
console.log('Males: '+this.mPop);
console.log('Eggs Waiting To Hatch: '+waitingEggs);
this.dataArr.push({tick:this.ticks,females:this.fPop,males:this.mPop});
}
}

module.exports = Population;
24 changes: 24 additions & 0 deletions nodejs-by-kd8lvt/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
-- How To Run --

-- INSTALLATION: --

1. Install NodeJS - make sure you install npm with it!
2. Open your shell of choice ('CMD' on Windows, 'bash' on most Linux distros, etc etc)
3. Navigate to this folder (if you cloned this, that should be easy enough to do)
4. Run 'npm install' - this downloads the CSV package.

-- RUNNING: --

To generate data, simply run 'node "BULBASAUR.js"' or 'node "BULBASAUR.js" humans' in your shell of choice. It's a near 1-1 of Austin's python code, but cleaned up... and then made messy again... Don't sue me.

-- VIEWING DATA --

To view data as a line-graph:
1. Run 'node webserver.js' in your shell of choice
2. Go to 'http://localhost:8080' in your web browser of choice

You are able to load other csv files into the graph by entering their file names in the textbox and clicking "Load CSV". They must be in the format "tick, males, females" however.

White line is total population, Pink line is females, and Blue line is males. Yellow line is the currently selected X value - colored numbers are the value at the selected point.

If it doesn't work, make sure you have an internet connection - you need it to download p5.js!
46 changes: 46 additions & 0 deletions nodejs-by-kd8lvt/Test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const Population = require('./Population.js');

class Test {
constructor(options) {
if (options) {this.pop = new Population(options.population)}else{this.pop = new Population()};
this.interval = null;
this.ticks = 0;
if (options) {
this.csv = require('csv-writer').createObjectCsvWriter({
path:'./web/'+(options.csvName||'bulbasaur_test_'+Math.round(Math.random()*100))+'.csv',
header: [
{id:'tick',title:'tick'},
{id:'females',title:'females'},
{id:'males',title:'males'}
]
});
} else {
this.csv = require('csv-writer').createObjectCsvWriter({
path:'./web/bulbasaur_test_'+Math.round(Math.random()*100)+'.csv',
header: [
{id:'tick',title:'tick'},
{id:'females',title:'females'},
{id:'males',title:'males'}
]
});
}
}

start() {
this.interval = setInterval(()=>{
this.pop.tick();
if (this.pop.totalPop >= 20000) {
console.log('Stopped in '+this.ticks+' ticks due to "max population reached"');
this.csv.writeRecords(this.pop.dataArr);
clearInterval(this.interval);
} else if (this.pop.extinct) {
console.log('Stopped in '+this.ticks+' ticks due to "extinct"');
this.csv.writeRecords(this.pop.dataArr);
clearInterval(this.interval);
}
this.ticks++
},50);
}
}

module.exports = Test;
13 changes: 13 additions & 0 deletions nodejs-by-kd8lvt/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions nodejs-by-kd8lvt/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "pokemon-population-models",
"version": "1.0.0",
"description": "",
"main": "BULBASAUR.js",
"dependencies": {
"csv-writer": "^1.5.0",
"express": "^4.17.1"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/kd8lvt/Pokemon-Population-Models.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/kd8lvt/Pokemon-Population-Models/issues"
},
"homepage": "https://github.com/kd8lvt/Pokemon-Population-Models#readme"
}
Loading