Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/ai/petra/config.js
PETRA.Config = function(difficulty, behavior) | // These integers must be sequential | |||||||||||||
PETRA.DIFFICULTY_SANDBOX = 0; | ||||||||||||||
PETRA.DIFFICULTY_VERY_EASY = 1; | ||||||||||||||
PETRA.DIFFICULTY_EASY = 2; | ||||||||||||||
PETRA.DIFFICULTY_MEDIUM = 3; | ||||||||||||||
PETRA.DIFFICULTY_HARD = 4; | ||||||||||||||
PETRA.DIFFICULTY_VERY_HARD = 5; | ||||||||||||||
Freagarach: I think a comment that these _MUST_ be sequential integers is in place. | ||||||||||||||
Not Done Inline ActionsWonder if we should have JSDoc for those explaining what changes between difficulty levels. Stan: Wonder if we should have JSDoc for those explaining what changes between difficulty levels. | ||||||||||||||
Not Done Inline ActionsI don't think so, it is impossible to note all differences here and as such also hard to determine the line between what to note down and what not. Freagarach: I don't think so, it is impossible to note all differences here and as such also hard to… | ||||||||||||||
Not Done Inline ActionsAlso probably breaks my documentation generator but that's another issue ^^ Stan: Also probably breaks my documentation generator but that's another issue ^^ | ||||||||||||||
PETRA.Config = function(difficulty = PETRA.DIFFICULTY_MEDIUM, behavior) | ||||||||||||||
{ | { | |||||||||||||
// 0 is sandbox, 1 is very easy, 2 is easy, 3 is medium, 4 is hard and 5 is very hard. | this.difficulty = difficulty; | |||||||||||||
Done Inline Actionsthis.difficulty = difficulty ?? PETRA.DIFFICULTY_MEDIUM; nani: this.difficulty = difficulty ?? PETRA.DIFFICULTY_MEDIUM;
| ||||||||||||||
Not Done Inline Actions
? Freagarach: ? | ||||||||||||||
this.difficulty = difficulty !== undefined ? difficulty : 3; | ||||||||||||||
// for instance "balanced", "aggressive" or "defensive" | // for instance "balanced", "aggressive" or "defensive" | |||||||||||||
this.behavior = behavior || "random"; | this.behavior = behavior || "random"; | |||||||||||||
// debug level: 0=none, 1=sanity checks, 2=debug, 3=detailed debug, -100=serializatio debug | // debug level: 0=none, 1=sanity checks, 2=debug, 3=detailed debug, -100=serializatio debug | |||||||||||||
this.debug = 0; | this.debug = 0; | |||||||||||||
this.chat = true; // false to prevent AI's chats | this.chat = true; // false to prevent AI's chats | |||||||||||||
▲ Show 20 Lines • Show All 149 Lines • ▼ Show 20 Lines | PETRA.Config = function(difficulty = PETRA.DIFFICULTY_MEDIUM, behavior) | |||||||||||||
this.unusedNoAllyTechs = [ | this.unusedNoAllyTechs = [ | |||||||||||||
"Player/sharedLos", | "Player/sharedLos", | |||||||||||||
"Market/InternationalBonus", | "Market/InternationalBonus", | |||||||||||||
"Player/sharedDropsites" | "Player/sharedDropsites" | |||||||||||||
]; | ]; | |||||||||||||
}; | }; | |||||||||||||
PETRA.Config.prototype.setConfig = function(gameState) | PETRA.Config.prototype.setConfig = function(gameState) | |||||||||||||
{ | { | |||||||||||||
if (this.difficulty > 0) | if (this.difficulty > PETRA.DIFFICULTY_SANDBOX) | |||||||||||||
{ | { | |||||||||||||
// Setup personality traits according to the user choice: | // Setup personality traits according to the user choice: | |||||||||||||
// The parameter used to define the personality is basically the aggressivity or (1-defensiveness) | // The parameter used to define the personality is basically the aggressivity or (1-defensiveness) | |||||||||||||
Done Inline ActionsTry to have any constants on the top of the file when possible, so readers can know where to look. nani: Try to have any constants on the top of the file when possible, so readers can know where to… | ||||||||||||||
// as they are anticorrelated, although some small smearing to decorelate them will be added. | // as they are anticorrelated, although some small smearing to decorelate them will be added. | |||||||||||||
// And for each user choice, this parameter can vary between min and max | // And for each user choice, this parameter can vary between min and max | |||||||||||||
let personalityList = { | let personalityList = { | |||||||||||||
"random": { "min": 0, "max": 1 }, | "random": { "min": 0, "max": 1 }, | |||||||||||||
"defensive": { "min": 0, "max": 0.27 }, | "defensive": { "min": 0, "max": 0.27 }, | |||||||||||||
"balanced": { "min": 0.37, "max": 0.63 }, | "balanced": { "min": 0.37, "max": 0.63 }, | |||||||||||||
"aggressive": { "min": 0.73, "max": 1 } | "aggressive": { "min": 0.73, "max": 1 } | |||||||||||||
}; | }; | |||||||||||||
Show All 23 Lines | PETRA.Config.prototype.setConfig = function(gameState) | |||||||||||||
else if (gameState.getAlliedVictory()) | else if (gameState.getAlliedVictory()) | |||||||||||||
this.personality.cooperative = Math.min(1, this.personality.cooperative + 0.15); | this.personality.cooperative = Math.min(1, this.personality.cooperative + 0.15); | |||||||||||||
// changing settings based on difficulty or personality | // changing settings based on difficulty or personality | |||||||||||||
this.Military.towerLapseTime = Math.round(this.Military.towerLapseTime * (1.1 - 0.2 * this.personality.defensive)); | this.Military.towerLapseTime = Math.round(this.Military.towerLapseTime * (1.1 - 0.2 * this.personality.defensive)); | |||||||||||||
this.Military.fortressLapseTime = Math.round(this.Military.fortressLapseTime * (1.1 - 0.2 * this.personality.defensive)); | this.Military.fortressLapseTime = Math.round(this.Military.fortressLapseTime * (1.1 - 0.2 * this.personality.defensive)); | |||||||||||||
this.priorities.defenseBuilding = Math.round(this.priorities.defenseBuilding * (0.9 + 0.2 * this.personality.defensive)); | this.priorities.defenseBuilding = Math.round(this.priorities.defenseBuilding * (0.9 + 0.2 * this.personality.defensive)); | |||||||||||||
if (this.difficulty < 2) | if (this.difficulty < PETRA.DIFFICULTY_EASY) | |||||||||||||
{ | { | |||||||||||||
this.popScaling = 0.5; | this.popScaling = 0.5; | |||||||||||||
this.Economy.supportRatio = 0.5; | this.Economy.supportRatio = 0.5; | |||||||||||||
this.Economy.provisionFields = 1; | this.Economy.provisionFields = 1; | |||||||||||||
this.Military.numSentryTowers = this.personality.defensive > this.personalityCut.strong ? 1 : 0; | this.Military.numSentryTowers = this.personality.defensive > this.personalityCut.strong ? 1 : 0; | |||||||||||||
} | } | |||||||||||||
else if (this.difficulty < 3) | else if (this.difficulty < PETRA.DIFFICULTY_MEDIUM) | |||||||||||||
{ | { | |||||||||||||
this.popScaling = 0.7; | this.popScaling = 0.7; | |||||||||||||
this.Economy.supportRatio = 0.4; | this.Economy.supportRatio = 0.4; | |||||||||||||
this.Economy.provisionFields = 1; | this.Economy.provisionFields = 1; | |||||||||||||
this.Military.numSentryTowers = this.personality.defensive > this.personalityCut.strong ? 1 : 0; | this.Military.numSentryTowers = this.personality.defensive > this.personalityCut.strong ? 1 : 0; | |||||||||||||
} | } | |||||||||||||
else | else | |||||||||||||
{ | { | |||||||||||||
if (this.difficulty == 3) | if (this.difficulty == PETRA.DIFFICULTY_MEDIUM) | |||||||||||||
Not Done Inline ActionsWe can use ===. Freagarach: We can use `===`. | ||||||||||||||
this.Military.numSentryTowers = 1; | this.Military.numSentryTowers = 1; | |||||||||||||
else | else | |||||||||||||
this.Military.numSentryTowers = 2; | this.Military.numSentryTowers = 2; | |||||||||||||
if (this.personality.defensive > this.personalityCut.strong) | if (this.personality.defensive > this.personalityCut.strong) | |||||||||||||
++this.Military.numSentryTowers; | ++this.Military.numSentryTowers; | |||||||||||||
else if (this.personality.defensive < this.personalityCut.weak) | else if (this.personality.defensive < this.personalityCut.weak) | |||||||||||||
--this.Military.numSentryTowers; | --this.Military.numSentryTowers; | |||||||||||||
if (this.personality.aggressive > this.personalityCut.strong) | if (this.personality.aggressive > this.personalityCut.strong) | |||||||||||||
{ | { | |||||||||||||
this.Military.popForBarracks1 = 12; | this.Military.popForBarracks1 = 12; | |||||||||||||
this.Economy.popPhase2 = 50; | this.Economy.popPhase2 = 50; | |||||||||||||
this.priorities.healer = 10; | this.priorities.healer = 10; | |||||||||||||
} | } | |||||||||||||
} | } | |||||||||||||
let maxPop = gameState.getPopulationMax(); | let maxPop = gameState.getPopulationMax(); | |||||||||||||
if (this.difficulty < 2) | if (this.difficulty < PETRA.DIFFICULTY_EASY) | |||||||||||||
this.Economy.targetNumWorkers = Math.max(1, Math.min(40, maxPop)); | this.Economy.targetNumWorkers = Math.max(1, Math.min(40, maxPop)); | |||||||||||||
else if (this.difficulty < 3) | else if (this.difficulty < PETRA.DIFFICULTY_MEDIUM) | |||||||||||||
this.Economy.targetNumWorkers = Math.max(1, Math.min(60, Math.floor(maxPop/2))); | this.Economy.targetNumWorkers = Math.max(1, Math.min(60, Math.floor(maxPop/2))); | |||||||||||||
else | else | |||||||||||||
this.Economy.targetNumWorkers = Math.max(1, Math.min(120, Math.floor(maxPop/3))); | this.Economy.targetNumWorkers = Math.max(1, Math.min(120, Math.floor(maxPop/3))); | |||||||||||||
this.Economy.targetNumTraders = 2 + this.difficulty; | this.Economy.targetNumTraders = 2 + this.difficulty; | |||||||||||||
if (gameState.getVictoryConditions().has("wonder")) | if (gameState.getVictoryConditions().has("wonder")) | |||||||||||||
{ | { | |||||||||||||
Show All 9 Lines | PETRA.Config.prototype.setConfig = function(gameState) | |||||||||||||
this.Military.popForForge = Math.min(Math.max(Math.floor(this.Military.popForForge * this.popScaling), 30), Math.floor(maxPop/2)); | this.Military.popForForge = Math.min(Math.max(Math.floor(this.Military.popForForge * this.popScaling), 30), Math.floor(maxPop/2)); | |||||||||||||
this.Economy.popPhase2 = Math.min(Math.max(Math.floor(this.Economy.popPhase2 * this.popScaling), 20), Math.floor(maxPop/2)); | this.Economy.popPhase2 = Math.min(Math.max(Math.floor(this.Economy.popPhase2 * this.popScaling), 20), Math.floor(maxPop/2)); | |||||||||||||
this.Economy.workPhase3 = Math.min(Math.max(Math.floor(this.Economy.workPhase3 * this.popScaling), 40), Math.floor(maxPop*2/3)); | this.Economy.workPhase3 = Math.min(Math.max(Math.floor(this.Economy.workPhase3 * this.popScaling), 40), Math.floor(maxPop*2/3)); | |||||||||||||
this.Economy.workPhase4 = Math.min(Math.max(Math.floor(this.Economy.workPhase4 * this.popScaling), 45), Math.floor(maxPop*2/3)); | this.Economy.workPhase4 = Math.min(Math.max(Math.floor(this.Economy.workPhase4 * this.popScaling), 45), Math.floor(maxPop*2/3)); | |||||||||||||
this.Economy.targetNumTraders = Math.round(this.Economy.targetNumTraders * this.popScaling); | this.Economy.targetNumTraders = Math.round(this.Economy.targetNumTraders * this.popScaling); | |||||||||||||
this.Economy.targetNumWorkers = Math.max(this.Economy.targetNumWorkers, this.Economy.popPhase2); | this.Economy.targetNumWorkers = Math.max(this.Economy.targetNumWorkers, this.Economy.popPhase2); | |||||||||||||
this.Economy.workPhase3 = Math.min(this.Economy.workPhase3, this.Economy.targetNumWorkers); | this.Economy.workPhase3 = Math.min(this.Economy.workPhase3, this.Economy.targetNumWorkers); | |||||||||||||
this.Economy.workPhase4 = Math.min(this.Economy.workPhase4, this.Economy.targetNumWorkers); | this.Economy.workPhase4 = Math.min(this.Economy.workPhase4, this.Economy.targetNumWorkers); | |||||||||||||
if (this.difficulty < 2) | if (this.difficulty < PETRA.DIFFICULTY_EASY) | |||||||||||||
this.Economy.workPhase3 = Infinity; // prevent the phasing to city phase | this.Economy.workPhase3 = Infinity; // prevent the phasing to city phase | |||||||||||||
if (this.debug < 2) | if (this.debug < 2) | |||||||||||||
return; | return; | |||||||||||||
API3.warn(" >>> Petra bot: personality = " + uneval(this.personality)); | API3.warn(" >>> Petra bot: personality = " + uneval(this.personality)); | |||||||||||||
}; | }; | |||||||||||||
PETRA.Config.prototype.Serialize = function() | PETRA.Config.prototype.Serialize = function() | |||||||||||||
Show All 13 Lines |
Wildfire Games · Phabricator
I think a comment that these _MUST_ be sequential integers is in place.