Page MenuHomeWildfire Games

Allow AI to read JSON files and Resources globalscript, don't copy Resources each turn in GetSimulationState
ClosedPublic

Authored by elexis on Dec 6 2017, 3:34 PM.

Details

Summary

In rP18964 we introduced the global Resources object. But we didn't properly address the AI and
added a hack, copying the Resources data each turn through the GUI Interface.
But the AI should just load JSON data like every other context too and profit from globalscripts parsing.

For further plans where the AI can profit from loading JSON files in JS directly and benefits from globalscripts, see D1108 (which will need two preliminaries).

Test Plan

Run a game with 2 AIs to see that it works. Notice that the GetCodes returns a cache, so shouldn't be a significant performance difference.

Diff Detail

Repository
rP 0 A.D. Public Repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

elexis created this revision.Dec 6 2017, 3:34 PM
Vulcan added a subscriber: Vulcan.Dec 6 2017, 4:31 PM

Successful build - Chance fights ever on the side of the prudent.

Updating workspaces...
Build (release)...
Build (debug)...
Running release tests...
Running cxxtest tests (308 tests).
In TestComponentScripts::test_scripts:
../../../source/test_setup.cpp:134: Error: Test failed: Stack trace:
@simulation/components/tests/test_GuiInterface.js:268:1
Expected equal, got ({players:[{name:"Player 1", civ:"gaia", color:{r:1, g:1, b:1, a:1}, controlsAll:false, popCount:10, popLimit:20, popMax:200, panelEntities:[], resourceCounts:{food:100}, trainingBlocked:false, state:"active", team:-1, teamsLocked:false, cheatsEnabled:false, disabledTemplates:{}, disabledTechnologies:{}, hasSharedDropsites:false, hasSharedLos:false, spyCostMultiplier:1, phase:"village", isAlly:[false, false], isMutualAlly:[false, false], isNeutral:[false, false], isEnemy:[true, true], entityLimits:{Foo:10}, entityCounts:{Foo:5}, entityLimitChangers:{Foo:{}}, researchQueued:{}, researchStarted:{}, researchedTechs:{}, classCounts:{}, typeCountsByClass:{}, canBarter:false, barterPrices:{buy:{food:150}, sell:{food:25}}, statistics:{resourcesGathered:{food:100, wood:0, metal:0, stone:0, vegetarianFood:0}, percentMapExplored:10}}, {name:"Player 2", civ:"mace", color:{r:1, g:0, b:0, a:1}, controlsAll:true, popCount:40, popLimit:30, popMax:300, panelEntities:[], resourceCounts:{food:200}, trainingBlocked:false, state:"active", team:-1, teamsLocked:false, cheatsEnabled:false, disabledTemplates:{}, disabledTechnologies:{}, hasSharedDropsites:false, hasSharedLos:false, spyCostMultiplier:1, phase:"village", isAlly:[true, true], isMutualAlly:[false, false], isNeutral:[false, false], isEnemy:[false, false], entityLimits:{Bar:20}, entityCounts:{Bar:0}, entityLimitChangers:{Bar:{}}, researchQueued:{}, researchStarted:{}, researchedTechs:{}, classCounts:{}, typeCountsByClass:{}, canBarter:false, barterPrices:{buy:{food:150}, sell:{food:25}}, statistics:{resourcesGathered:{food:100, wood:0, metal:0, stone:0, vegetarianFood:0}, percentMapExplored:10}}], circularMap:false, timeElapsed:0, gameType:"conquest", alliedVictory:false}) !== ({players:[{name:"Player 1", civ:"gaia", color:{r:1, g:1, b:1, a:1}, controlsAll:false, popCount:10, popLimit:20, popMax:200, panelEntities:[], resourceCounts:{food:100}, trainingBlocked:false, state:"active", team:-1, teamsLocked:false, cheatsEnabled:false, disabledTemplates:{}, disabledTechnologies:{}, hasSharedDropsites:false, hasSharedLos:false, spyCostMultiplier:1, phase:"village", isAlly:[false, false], isMutualAlly:[false, false], isNeutral:[false, false], isEnemy:[true, true], entityLimits:{Foo:10}, entityCounts:{Foo:5}, entityLimitChangers:{Foo:{}}, researchQueued:{}, researchStarted:{}, researchedTechs:{}, classCounts:{}, typeCountsByClass:{}, canBarter:false, barterPrices:{buy:{food:150}, sell:{food:25}}, statistics:{resourcesGathered:{food:100, wood:0, metal:0, stone:0, vegetarianFood:0}, percentMapExplored:10}}, {name:"Player 2", civ:"mace", color:{r:1, g:0, b:0, a:1}, controlsAll:true, popCount:40, popLimit:30, popMax:300, panelEntities:[], resourceCounts:{food:200}, trainingBlocked:false, state:"active", team:-1, teamsLocked:false, cheatsEnabled:false, disabledTemplates:{}, disabledTechnologies:{}, hasSharedDropsites:false, hasSharedLos:false, spyCostMultiplier:1, phase:"village", isAlly:[true, true], isMutualAlly:[false, false], isNeutral:[false, false], isEnemy:[false, false], entityLimits:{Bar:20}, entityCounts:{Bar:0}, entityLimitChangers:{Bar:{}}, researchQueued:{}, researchStarted:{}, researchedTechs:{}, classCounts:{}, typeCountsByClass:{}, canBarter:false, barterPrices:{buy:{food:150}, sell:{food:25}}, statistics:{resourcesGathered:{food:100, wood:0, metal:0, stone:0, vegetarianFood:0}, percentMapExplored:10}}], circularMap:false, timeElapsed:0, gameType:"conquest", alliedVictory:false, resources:{codes:["food", "metal", "stone", "wood"], names:{food:"Food", metal:"Metal", stone:"Stone", wood:"Wood"}, aiInfluenceGroups:{food:"ignore", metal:"sparse", stone:"sparse", wood:"abundant"}}})
../../../source/test_setup.cpp:134: Error: Test failed: Stack trace:
@simulation/components/tests/test_GuiI
Vulcan added a comment.Dec 6 2017, 4:32 PM
Executing section Default...
Executing section Source...
Executing section JS...

binaries/data/mods/public/simulation/ai/petra/headquarters.js
| 450| »   »   »   let·ratioMax·=·0.70·+·randFloat(0.,·0.1);
|    | [NORMAL] JSHintBear:
|    | A trailing decimal point can be confused with a dot: '0.'.

binaries/data/mods/public/simulation/ai/petra/headquarters.js
| 455| »   »   »   »   ratioMax·=·0.85·+·randFloat(0.,·0.1);
|    | [NORMAL] JSHintBear:
|    | A trailing decimal point can be confused with a dot: '0.'.

binaries/data/mods/public/simulation/ai/common-api/shared.js
|  58| »   »   this._templates[name]·=·Engine.GetTemplate(name)·||·null
|    | [NORMAL] JSHintBear:
|    | Missing semicolon.
mimo accepted this revision.Dec 6 2017, 8:49 PM

Patch is good, and gives the same hash code on games with sevaral AIs.

This revision is now accepted and ready to land.Dec 6 2017, 8:49 PM
elexis added a comment.Dec 6 2017, 8:51 PM

Thanks so much for your time and expertise!

elexis added a comment.Dec 6 2017, 9:22 PM

(As mentioned by Vulcan, forgot to remove the entry from test_GUIInterface.js)

This revision was automatically updated to reflect the committed changes.
Owners added subscribers: Restricted Owners Package, Restricted Owners Package.Dec 6 2017, 9:26 PM