A function for speculative calculation of things

Can you help improve your favourite game? Hardcore C mages, talented artists, and players with any level of experience are welcome!
Post Reply
Ignatus
Elite
Posts: 644
Joined: Mon Nov 06, 2017 12:05 pm
Location: St.Petersburg, Russia
Contact:

A function for speculative calculation of things

Post by Ignatus »

There are functions effect_value_min() and _max() in effects.c that calculate how big or small value of an effect can potentially be in given conditions. The problems with them are
  • They calculate effects with incompatible requirements (e.g. you can't have both Barracks and Barracks II);
  • The basis of the effect calculation is nothing but an array of universals, i.e., what is "type" and "name" in requirements.
To solve the problem 2 for some AI code, I am witing a function that gets both a context and an array of requirements. If a requirement of an effect is found (positive or contradicting) in the array, it is evaluated according to it, otherwise it is evaluated to possible and, if yes, certain problem type, and the valu of this effect is added to the corresponding limit(s).

This function may be furtherly generalized if we pass a callback that evaluates a requirement to fc_tristate from the context and arbitrary data. For example, if we set probability values to the requirements in the array, we get even more powerful function that also may return the expected value of the effect (well, we should remember problem 1 and look at the compatibility variants of the vectors we calculate).

Maybe in the future of AI development we'll write a more sophisticated system where there will be a dynamic database storing: speculated individual and generic objects (like, "the unit#1234", "a unit", "a player", "tile (7, 42)", "a tile"); speculated simple statements that consist of a context referring speculated objects and a requirement (or a thing that is not a requirement yet like "the unit is on the tile" or "the unit owner matches the city owner"), as well as a probability specifier that the requirement is fulfilled; compound statements that refer to a pair of simple or compound statements and a logical operation ("and", "or", "and not"...); compound objects that restrict a simple object by a number of statements ("a unit on tile (7, 42) that is not the unit#1234 or a unit that is on a tile that contains a city"). Out of this database, AI may, acting by rules, pull the facts important for playing the game; when the database gives too uncertain answer, the AI tries to gather more information, and when the database grows too big (AI level dependent size), an algorithm simplifies the data erasing the least important and generalizing too specific (something like: "player#1 has 3 cities", "a city(1) of player 1 has Barracks", "50% a city(2) has Barracks", "90% city(2) belongs to player#1", "a city (2) is not a city(1)", "a city(2) has Barracks iff a city(3) of player#1 has no Barracks" -> "player#1 has 3 cities", "a city of player#1 50% has Barracks"). This database also may be used for machine learning if acconpanied with some reasoning tools that can generalize data behind ruleset ("we went on a city before turn 10 with 15 Horsemen, spent at average 5 of them and took it 99% of times, we like to get cities, think a bit what is important here and record: going for a city with fast strong units that have twice more combat power than the expected defender seems pretty good in early game").
Post Reply