Created
February 18, 2017 02:40
-
-
Save jwulf/bc7a5f66d4a5294b453ec833046b3034 to your computer and use it in GitHub Desktop.
MCT1 Metabolic Cycle Prototype
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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