Opened 12 years ago

Closed 10 years ago

Last modified 10 years ago

#1520 closed enhancement (fixed)

Add technology support to AIs

Reported by: historic_bruno Owned by:
Priority: Should Have Milestone: Alpha 15
Component: UI & Simulation Keywords:
Cc: Patch:

Description

AIs currently ignore the existence of technologies. The following are changes needed at minimum to fully support techs:

  • Modify the AI's entity template data in response to tech modifications (see #1358)
  • Modify entity collections in response to tech modifications
  • Pass list of researched and available techs through to the AIs
  • Add some research plans to the AIs, starting with qBot

Attachments (1)

experimental-ai-techs-r12056.patch (7.6 KB ) - added by historic_bruno 12 years ago.

Download all attachments as: .zip

Change History (14)

comment:1 by ben, 12 years ago

In 12056:

Implements global tech modification function. Fixes #1358, refs #1520.
Applies tech modifications to template data returned by GuiInterface.
Extends engine to load arbitrary global scripts, separates this from RNG replacement. Refs #1193.
Loads global scripts for most script contexts for consistency.
Adds simulation tests for global scripts.

by historic_bruno, 12 years ago

comment:2 by historic_bruno, 12 years ago

Attached partial patch for adding techs to AIs, split from work on #1358. I don't know if the approach is any good, but it's certainly not complete :)

comment:3 by wraitii, 12 years ago

Since I have a few connections on the issue... From what I gather, the AI should only ever receive the "after tech" template informations, which is now the situation after 12056(not sure I got this). I don't think the AI would care about the basic templates, it's, to me, needless complexity. In turn, entity collections and entity would automatically be up to date, because to the AI there would be no difference. Then there must be: A way for the AI to know which technology is available, its cost, where it can be researched (I'd say a list of any building that could research this, the AIs will then be in charge of building the proper one for civilization X), and most importantly what benefits it brings. Then the AI needs a way to know which technology it already has, and which it is currently researching (possibly the progression too). And a way to actually research a technology.

The AI scripts also need to take into account the fact that no longer can they build every building immediately. I'm not sure where to put this, I guess somewhere in "entity.js" in the common-api, as a check when given a "build" order, or rather as a standalone check so it can be used at different levels.

(this is mainly directed towards Quantumstate) As for implementing technologies in the scripts, I recommend using the same thing AOE developers did: separating the "Update" functions of econ/military for each phase. It allows for tighter control, more precise behavior, and less complexity overall (I think). Without, you'll probably have to invent a very clever dynamic system to know which technology to research, and to deal with phase techs, which may not be worth it.

in reply to:  3 comment:4 by historic_bruno, 12 years ago

Replying to wraitii:

Since I have a few connections on the issue... From what I gather, the AI should only ever receive the "after tech" template informations, which is now the situation after 12056(not sure I got this). I don't think the AI would care about the basic templates, it's, to me, needless complexity.

This isn't true as far as I know. Currently the AI manager has a single set of entity template data, which each AI shares. That data is never updated since it doesn't change. The data doesn't come from GuiInterface (unlike some other simulation state) so r12056 shouldn't change anything.

There are a few issues. One as you said, the AI should always use the updated template data, which means updating the original shared template data (unless we redesign this somehow). Also the common-api Entity class is initialized with an EntityTemplate which it uses for most base stats, see entity.js.

So any Entity or EntityTemplate objects the AI stores can be possibly outdated after a tech is researched. Maybe all of that should be redesigned taking dynamic stats into account.

comment:5 by wraitii, 12 years ago

entityTemplate should only ever call that shared set of template data, right? In this case, I see two solutions: you give each AI its set, and you update it accordingly, oy for each call to this set, you check for the AI's tech and you return up-to-date value (probably easier to do in the short run, but probably slower for the AIs too).

Entity should only ever be used to access data that can't be read from a template (in theory.I think the common api respects this convention mostly. ). In this case, the problem can probably be solved some other way.

Last edited 12 years ago by wraitii (previous) (diff)

in reply to:  5 comment:6 by historic_bruno, 12 years ago

Cc: Jonathan Waller added

Replying to wraitii:

entityTemplate should only ever call that shared set of template data, right? In this case, I see two solutions: you give each AI its set, and you update it accordingly, oy for each call to this set, you check for the AI's tech and you return up-to-date value (probably easier to do in the short run, but probably slower for the AIs too).

Right, the shared data is to reduce memory usage of the AIs. We could give each AI their own copy, but it seems updating every possibly changed data of every template for every AI would be a waste. Perhaps the updater would be smart enough to know which areas to focus on (based on changes in researched techs between turns).

I think the most efficient method is on-the-fly stats calculation with some caching, as techs don't change constantly. The AIs won't need most of the stats, most of the time (I hope) :) Though I don't have any way to prove that's most efficient.

It comes down to whether tech modifications should be pulled in by the AI as needed or pushed into the AI regardless.

comment:7 by wraitii, 12 years ago

Using caching, it would work very well... Right now, I don't think AIs constantly call for templates, but as their complexity increase, I'd expect them to rely more and more on stats, so we should probably not cripple their ability to do so.

comment:8 by wraitii, 12 years ago

Okay, I took over this issue. Historic_bruno, I redid the thinking process independently yesterday and we agree on the method to use. I'm starting from your patch, fixed to use the correct tech modifications for each player.

comment:9 by wraitii, 11 years ago

Points 1, 2 and 3 should be done (though they might require cleaning up) in the API v3 from my RC Aegis/V3 API bot. Point 4 is not really done, though Aegis will go up phases.

I recommend PM-ing me if someone wants to build up on this and has questions.

comment:10 by Yves, 11 years ago

Cc: Yves added

comment:11 by wraitii, 10 years ago

Cc: Jonathan Waller Yves removed
Milestone: BacklogAlpha 16
Resolution: fixed
Status: newclosed

Fixed for over a year now. AIs need to improve how they research tech but the capacity is there. Closing this.

comment:12 by fabio, 10 years ago

Milestone: Alpha 16Alpha 15

comment:13 by wraitii, 10 years ago

In 14588:

AIs now properly receive aura and technology updates. Fixes #2377, Refs #1520 . Consequently reimplement repairing for AIs.
Fix a few style issues and a bug with the gatherer count.
Still need to fix the entity.js file to handle properly some things as this uses raw templates values.
Cache the AIinterface in AIProxy.js, please report if this works properly.

Note: See TracTickets for help on using tickets.