Adventure AI

It’s nice to see someone working on the AI.

There’s a couple of compile issues left on linux. “gcc” is not as lenient as vc++. I have attached the compile log against rev 1091.
comperr.txt.zip (1.79 KB)

I looked a bit more at this issue. It turns out that “gcc” chokes on that code because a set iterator returns a
const. It’s simply not a good idea to modify an element in a set because the ordering could change, and thus the properties of the set become broken. The set should be replaced with something more appropriate, such as a vector if ordering is not necessary.

It’s not so much that the ordering is necessary, but the ability to search for duplicates in sub linear time. So a vector wouldn’t be appropriate. Perhaps a better data structure would be a hash set, but the STL still doesn’t have one of those.

Since the things being modified do not change the ordering, I do think it is ok for it to be std::set. Not sure, however how to fix the problem. Sorry.

Elements can be modified but it’s not allowed to make changes affecting the order of objects. AFAIK standard guarantees that set iterator is dereferencible to T& (not const), so gcc behaviour seems to be a bug. It’s may be justified by immutable order requirement but it limits usability of set.

The problem can be workarounded by const_cast to T& or by adding “mutable” specifier to fields we want to modify in set members.
My proposal is to:

  1. Make HeroObjective::whoCanAchieve mutable. Make HeroObjective::operator< independent from whoCanAchieve. (so our changes won’t affect set order - it can lead to problems also on MSVC. MSVC allows element modification but it’s still our responsibility to not modify order).
  2. Make AIObjectivePtrCont::AIObjective const.

But if you have other, better ideas, feel free to realize them :slight_smile:

Is there a way to get a player’s income for every resource? It would be useful for the AI to be able to conserve on resources it’s not getting much of.

Not really. Player get resource income from various sources (town structures, mines, hero skills, hero specialities) which are not unified for now.
My suggestion is to store resource stockpile before ending the turn and compare it with stockpile after starting next turn. Difference will be income.

Ok, I can do that easily enough for now, but:

  1. It would be nice if the AI was stateless in the sense that the moves it makes are not dependent on anything other than the current state of the game, and
  2. It would be nice if eventually the AI would know that it makes more wood if it just flagged a wood mine or, more obscurely, more mercury if it just recruited Rissa.

I’m going on vacation for a couple weeks, and I won’t have a computer with a compiler, so it will be a while before I will resume work on the AI. But don’t worry, it’ll happen.

In the mean time, the AI has approximate values for objects that give resources/gold, everything else gets a different random value every turn. I think this is the best state I can really leave it in. Hopefully it will make testing the AI possible.

Good luck, I can’t wait to see the progress made in my absence.

[size=75] Comment added by : Zamolxis: 22-08-2009, 12:49 ][/size]
[size=75]Enjoy your vacation! :wink:[/size]