Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/ai/petra/config.js
var PETRA = function(m) | var PETRA = function(m) | ||||
{ | { | ||||
m.Config = function(difficulty) | m.Config = function(difficulty, behavior) | ||||
{ | { | ||||
// 0 is sandbox, 1 is very easy, 2 is easy, 3 is medium, 4 is hard and 5 is very hard. | // 0 is sandbox, 1 is very easy, 2 is easy, 3 is medium, 4 is hard and 5 is very hard. | ||||
this.difficulty = difficulty !== undefined ? difficulty : 3; | this.difficulty = difficulty !== undefined ? difficulty : 3; | ||||
// for instance "balanced", "aggressive" or "defensive" | |||||
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 | ||||
this.popScaling = 1; // scale factor depending on the max population | this.popScaling = 1; // scale factor depending on the max population | ||||
this.Military = { | this.Military = { | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | this.priorities = | ||||
"defenseBuilding": 70, | "defenseBuilding": 70, | ||||
"civilCentre": 950, | "civilCentre": 950, | ||||
"majorTech": 700, | "majorTech": 700, | ||||
"minorTech": 40, | "minorTech": 40, | ||||
"wonder": 1000, | "wonder": 1000, | ||||
"emergency": 1000 // used only in emergency situations, should be the highest one | "emergency": 1000 // used only in emergency situations, should be the highest one | ||||
}; | }; | ||||
// Default personality (will be updated in setConfig) | |||||
this.personality = | this.personality = | ||||
{ | { | ||||
"aggressive": 0.5, | "aggressive": 0.5, | ||||
"cooperative": 0.5, | "cooperative": 0.5, | ||||
"defensive": 0.5 | "defensive": 0.5 | ||||
}; | }; | ||||
// See m.QueueManager.prototype.wantedGatherRates() | // See m.QueueManager.prototype.wantedGatherRates() | ||||
Show All 17 Lines | this.queues = | ||||
} | } | ||||
}; | }; | ||||
this.garrisonHealthLevel = { "low": 0.4, "medium": 0.55, "high": 0.7 }; | this.garrisonHealthLevel = { "low": 0.4, "medium": 0.55, "high": 0.7 }; | ||||
}; | }; | ||||
m.Config.prototype.setConfig = function(gameState) | m.Config.prototype.setConfig = function(gameState) | ||||
{ | { | ||||
// initialize personality traits | if (this.difficulty > 0) | ||||
if (this.difficulty > 1) | |||||
{ | |||||
this.personality.aggressive = randFloat(0, 1); | |||||
this.personality.cooperative = randFloat(0, 1); | |||||
this.personality.defensive = randFloat(0, 1); | |||||
} | |||||
else | |||||
{ | { | ||||
this.personality.aggressive = 0.1; | |||||
this.personality.cooperative = 0.9; | // Setup personality traits according to the user choice: | ||||
// The parameter used to define the personality is basically the aggressivity or (1-defensiveness) | |||||
// 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 | |||||
let personalityList = { | |||||
"random": { "min": 0, "max": 1 }, | |||||
"defensive": { "min": 0, "max": 0.27 }, | |||||
"balanced": { "min": 0.37, "max": 0.63 }, | |||||
"aggressive": { "min": 0.73, "max": 1 } | |||||
}; | |||||
let behavior = randFloat(-0.5, 0.5); | |||||
// make agressive and defensive quite anticorrelated (aggressive ~ 1 - defensive) but not completelety | |||||
let variation = 0.15 * randFloat(-1, 1) * Math.sqrt(Math.square(0.5) - Math.square(behavior)); | |||||
let aggressive = Math.max(Math.min(behavior + variation, 0.5), -0.5) + 0.5; | |||||
let defensive = Math.max(Math.min(-behavior + variation, 0.5), -0.5) + 0.5; | |||||
let min = personalityList[this.behavior].min; | |||||
let max = personalityList[this.behavior].max; | |||||
this.personality = { | |||||
"aggressive": min + aggressive * (max - min), | |||||
"defensive": 1 - max + defensive * (max - min), | |||||
"cooperative": randFloat(0, 1) | |||||
}; | |||||
} | } | ||||
// Petra usually uses the continuous values of personality.aggressive and personality.defensive | |||||
// to define its behavior according to personality. But when discontinuous behavior is needed, | |||||
// it uses the following personalityCut which should be set such that: | |||||
// behavior="aggressive" => personality.aggressive > personalityCut.strong && | |||||
// personality.defensive < personalityCut.weak | |||||
// and inversely for behavior="defensive" | |||||
this.personalityCut = { "weak": 0.3, "medium": 0.5, "strong": 0.7 }; | |||||
if (gameState.playerData.teamsLocked) | if (gameState.playerData.teamsLocked) | ||||
this.personality.cooperative = Math.min(1, this.personality.cooperative + 0.30); | this.personality.cooperative = Math.min(1, this.personality.cooperative + 0.30); | ||||
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 | ||||
if (this.difficulty < 2) | if (this.difficulty < 2) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 89 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator