Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save birdfly/b11bf56e75a7463f787c8bdd187e4912 to your computer and use it in GitHub Desktop.
Save birdfly/b11bf56e75a7463f787c8bdd187e4912 to your computer and use it in GitHub Desktop.
MCT1 Metabolic Cycle Prototype
In the event loop, each cycle do this:
class Player {
const carbsAbsorptionRate; // how many carbs are absorbed per cycle
const insulinAbsorptionRate; // how many units of insulin are absorbed per cycle
const carbsPerInsulinUnit; // how many grams of carbs are metabolise per insulin unit
const carbsToHealthMagicNumber; // how many carbs convert to 1 unit of player health when metabolised
const carbsToBGLMagicNumber; // how many carbs convert to one point of BGL when unmetabolised
const BGLCorrectionPerInsulinUnitMagicNumber; // how many BGL points drop per one unit of insulin without carbs
carbsOnBoard; // current carbs onboard
insulinOnBoard; // current insulin onboard
BGL; // current player BGL
health; // current player health
}
function doMetabolicCycle(player) {
let carbsAbsorbed;
let insulinAbsorbed;
// Absorb carbs
if (carbsOnBoard - carbsAbsorptionRate > 0) {
carbsAbsorbed = player.carbsOnBoard - player.carbsAbsorptionRate;
} else {
player.carbsAbsorbed = player.carbsOnBoard;
}
player.carbsOnBoard -= carbsAbsorbed;
// Absorb insulin
if (player.insulinOnBoard - player.insulinAbsorptionRate > 0) {
insulinAbsorbed = player.insulinOnBoard - player.insulinAbsorptionRate;
} else {
insulinAbsorbed = player.insulinOnBoard;
}
player.insulinOnBoard -= insulinAbsorbed;
// Calculate insulin requirement
let insulinNeeded = (carbsAbsorbed / player.carbsPerInsulinUnit);
// Calculate and apply insulin and carbs interaction to health
if (insulinAbsorbed < insulinNeeded) { // BGL will rise
let carbsConvertedToHealth = player.carbsPerInsulinUnit * insulinAbsorbed;
let excessCarbs = carbsAbsorbed - carbsConvertedToHealth;
player.health += carbsConvertedToHealth / player.carbsToHealthMagicNumber;
player.BGL = player.BGL + (excessCarbs / player.carbsToBGLMagicNumber);
}
if (insulinAbsorbed >= insulinNeeded) { // BGL will be neutral or will drop
let carbsConvertedToHealth = carbsAbsorbed * player.carbsToEnergyMagicNumber;
let excessInsulin = insulinAbsorbed - (carbsConvertedToHealth / player.carbsPerInsulinUnit);
player.health += carbsConvertedToEnergy;
player.BGL -= (excessInsulin * player.BGLCorrectionPerInsulinUnitMagicNumber);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment