Jump to content

Querying A18 Template Space


Recommended Posts

I was looking for a simple method to query all templates and found jsawk quite capable. It is a command line tool and works on JSON files. I've exported the templates (6MB) and made a smaller file (10kB) to test it. Jsawk needs SpiderMonkey's jsshell, you'll get it here at Mozilla, or may have it somewhere in the build folder after compiling. For simplicity I've put jsshell, jsawk and the templates JSON in the same folder.

> ./jsawk -j ./js -i templates.A18.json.small -a 'return this.length'10

-j tells jsawk where jsshell is and -i the input file, the command returns the number of templates in the small file. Each template has an attribute 'name' which is the name of the template.

> ./jsawk -j ./js -i templates.A18.json.small  'return this.name' -a 'return this.join("\n")'structures/athen_fortressskirmish/structures/iber_wall_longunits/mace_mechanical_siege_lithobolos_packedunits/gaul_support_female_citizenunits/pers_ship_biremestructures/iber_wall_shortunits/ptol_ship_quinqueremeunits/gaul_cavalry_swordsman_eunits/athen_hero_periclesunits/sele_ship_bireme

In 'return this.name' this refers to the template, which is a JS object. In the command -a, this refers to the full result set. One can run any JS expression in these commands and use the shell for sorting. Of course you can pipe a result like this into a csv file and continue with Excel or Calc.

> ./jsawk -j ./js -i templates.A18.json.small  'return [this.Identity.Civ, this.name, this.Armour.Crush]' -a 'return this.join("\n")' | sortathen,structures/athen_fortress,2athen,units/athen_hero_pericles,25gaul,units/gaul_cavalry_swordsman_e,6gaul,units/gaul_support_female_citizen,15iber,structures/iber_wall_short,3.0mace,units/mace_mechanical_siege_lithobolos_packed,1pers,units/pers_ship_bireme,5ptol,units/ptol_ship_quinquereme,5sele,units/sele_ship_bireme,5skirm,skirmish/structures/iber_wall_long,3.0

Jsawk supports JSONquery to filter results:

> ./jsawk -j ./js -i templates.A18.json.small -q '.*[?Armour.Crush > 10]' 'return this.name'["units/gaul_support_female_citizen","units/athen_hero_pericles"]

At first the syntax appears a bit, well, awkward, but it supports full automation. All the other tools I've checked are somewhat limited.

Have fun!

Edited by agentx
Link to comment
Share on other sites

@Stan, somehow yes, I use jsawk to find out what is available (best unit for task XYZ) off-game and then try to teach the AI to make a good decision. Adapting to special things is a whole topic for itself. I wish templates and technologies would be machine readable, so the AI knows to interpret e.g. health. But, that's the very far future, for now any property needs to be somehow (hard) coded. You can't expect the AI uses a unknown building properly to its advantage.

Link to comment
Share on other sites

@Stan, somehow yes, I use jsawk to find out what is available (best unit for task XYZ) off-game and then try to teach the AI to make a good decision. Adapting to special things is a whole topic for itself. I wish templates and technologies would be machine readable, so the AI knows to interpret e.g. health. But, that's the very far future, for now any property needs to be somehow (hard) coded. You can't expect the AI uses a unknown building properly to its advantage.

Can't you exploit units that are recruitable to counter enemy strategies ? Ie parse templates to get all types of units with steps to build them, Also see building advantages (understand aura) to boost some part of your economy if they exist, just like an human will do. You'll need a hardcoded list of auras though, some infos about units, (but since we got rid of hard counters) What prevents templates from being machine readable ? If they are Xml parseable, they can be used right ?

Link to comment
Share on other sites

A problem with this approach is that the "strength" depend on various factors and most of them are not raising linear at all.

E.g. the number of units (simplifying things to "each side has only one type of unit" and also the same number of units (production costs are the same), one side melee, the other side ranged):

- Let's say one of the melee units wins against the ranged unit BUT...

- At a certain amount of units on both sides a "phase transition" will happen ... when no melee unit is fast enough to reach the ranged units at all.

(This only happens if the size of units is small enough to fit enough ranged units within an area of their range so that they deal more damage per time than the melee units can "carry" health towards them)

So even this (rather simple) example already depend on: Units range, size, speed, damage per time and health...and is non-linear.

(Not even considering armor/damage type, bonus vs., Stance/formation bonuses, stamina, ...)

So IMO in the end so many parameters have to be considered that calculating an exponential (or polynomial) fit for each unit type vs. each other in a "balancing test map" (capped at a sane limit) would be simpler (could then be stored in a matrix and used by the AI).

(This could then also be used for balancing though I'd find "balancing by usage statistics" from actual multiplayer games would suit that purpose better)

Edited by FeXoR
Link to comment
Share on other sites

> balancing by usage statistics

Is there data telling which civ is preferred at the lobby?

> What prevents templates from being machine readable ? If they are Xml parseable, they can be used right ?

No, "machine readable" actually means "machine understandable". (Don't know who coined that.) Look at this tech:

  "armor_infantry_hack_04": {    "affects": [      "Champion"    ],     "civi": "all",     "cost": {      "food": 0,       "metal": 500,       "stone": 0,       "wood": 0    },     "description": "Body armor fashioned completely of bronze. Only the best soldiers were equipped with such body armor, as it was very expensive and time-consuming to fabricate.",     "genericName": "Bronze Cuirass Body Armor",     "icon": "armor_cuirass_bronze.png",     "modifications": [      {        "add": 2.0,         "value": "Armour/Hack"      },       {        "add": 10,         "value": "Cost/Resources/metal"      }    ],     "pair": "pair_inf_armor_04",     "requirements": {      "tech": "phase_city"    },     "requirementsTooltip": "Unlocked in City Phase.",     "researchTime": 40,     "soundComplete": "interface/alarm/alarm_upgradearmory.xml",     "specificName": {      "rome": "Lorica Musculata"    },     "tooltip": "Champions +2 Hack Armor Levels, but also +10 Metal Cost."  }, 

Interesting is cost, modification and requirements. The question for a bot is: Should and can I research this tech? The can part is simple, the planner does it. The should part is hard, very hard, he needs to link from "Armour/Hack" / add 2.0 to "I need units to protect my centre which are resilient in close combat".

A relevant XKCD:

tasks.png

The only rule I have so far is: Invest in all tech from this list, if enough resources. And for units it's ranged or not, fast or slow and hoping Hannibal can train units faster than humans :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...