• 📚 Admin Project Update: I've added a major feature to PictureBooks.io called Avatar Studio! You can now upload photos to instantly turn your kids (and pets! 🐶) into illustrated characters that star in their own stories. Give it a try and let me know what you think!

Oz’s Comprehensive Ideas For A New Game Engine (“AI”)

Ozymandias

In Terra Fantasia
Supporter
Joined
Nov 5, 2001
Messages
10,877
Location
The lone and level sands
LIST OF INITIAL POSTS (to be added to, as completed):
  1. Introduction (this post, for now.)
  2. A breakdown of how the game is already organized, and how we can directly mirror it. I also suggest a (very) few new terms, so that we can compare the existing structure, to a new one, in an 'apples to apples" fashion.
  3. (Temporarily reserved for any further, "up front" explanations.)
  4. A simple demonstration of manipulating AI behavior using a combination of simple logic, and math (a combination which we'll, taken together, call, "Rules.")
  5. (Reserved, for now - and any other "Numbered Points," from this one, down, in Italics, is not yet completed - Meaning, I have it worked out, and just haven't time to properly get it down, in writing, and diagram, yet.)
  6. A detailed example of how the combination of Rules and States can direct an Offensive War, during the Napoleonic Era, both strategically and tactically. - Starting with the Napoleonic.
  7. Then WW2, with and without Blitzkrieg. (Both examples will also demonstrate "intelligent" use of Artillery.)
  8. How we can, easily - and either via editor, or dynamically, within the game, - use a "superstructure" of different AI "States." These are - and, I cannot emphasize enough - simple ways to change the AI's Rules, for increasingly sophisticated and realistic behavior.
  9. Additional WW2 era examples of intelligent building and us of Aircraft, from choosing Strategic Bombing, to Ground Support, to CAP ("Combat Air Patrol")
  10. ... Honestly, I haven't gotten around to thinking about Naval Units yet, so I'll reserve this one, for that.
  11. And one more, for whatever else might come up :)


-----------------------------------------------------------------------------------------------------------------------------
Introduction:

I believe we can build a new game engine (“AI”) which:
• Uses everything already existing in the game, from Tiles to Units.
• Is reasonably simple to both understand and build.
• Produces astonishingly more sophisticated AI behavior.
• Can allow us to readily modify any and every aspect of the game, including AI behavior.

It’s not magic. An analogy would be how bee colonies do extraordinary things, even though each bee has a brains the size of a pinhead. (The technical term for this is Emergent Behavior)

Beyond that, I also believe that the game should be built in 3 distinct stages:
• The first should be fully compatible with every Unit and Terrain graphic we already have. This phase would also include everything we can readily accommodate from all of our current “wish list,” including hybrid Tile types like “Canals” and hybrid Unit types like “Helicopters.” (See below for more info.)
• Phase 2 would entail “Extensions,” like some of the higher resolution graphics matters, which can be individually added
• Last would be “Major Changes,” like adding multiple map layers, as in Civ 2.

I used the word “re-purpose,” above. What I mean is quite simple. In broad strokes: every Tile and Unit has both numbers and flags associated with them. We can keep all of these - but use them differently.

A simple example is how land combat is handled. Now, it is often a chaotic mess of huge stacks pummeling each other. I can demonstrate how this can be changed into simulations of true strategy, by using a few simple rules, and simple arithmetic. Also, how those rules can be changed, either beforehand, via editor, or dynamically, I game, so that an AI’s army armed with Pikes and Bows will behave in an entirely different fashion, than one, later in the game, with WW2 era armies ... AND how one of those armies can be “Blitzkrieg” enabled, and another not.

I'm going to break this thread down, by topic, into different posts, to make discussion easier.
 
Last edited:
A note on terminology -

For efforts like this one, I am a stickler for using terms which are both concise and precise. The terms I’m going to use directly mirror how the game is already structured. As I believe that we can pull this off by using so much of what is already in place, we can also use these exact, same terms to discuss how to go forward. As an added benefit, these terms will also allow coders and non-coders to have discussions about nearly every part of our project, because these words will have exact the same meaning in both contexts.

In short, I don’t want our first Great Wonder to be, “The Tower Of Babel” ;)

Only four specific words are needed to both describe how the game is already built, and how we can use that same, exact template as the "scaffolding" for the new game. The four terms are:
  • Category
  • Class
  • Type
  • Attribute
Focusing on the 2 main aspects of game play, we are dealing the Map, and with Units. Each of those is a Category.

Each Category is divided into Classes:
  • For Tiles, the Classes are Land, Water, and Land/Water Hybrid ("Straits" or "Canals," accommodating both Land and Naval Units.)
  • For Units, the Classes are Ship, Land, Air, and Land/Air Hybrid (Helicopters.)
Each Class encompasses Types. For example, the Tile Class "Water" includes:
  • Coast
  • Sea
  • Ocean
Similarly, The Unit Class "Ship" includes anything that floats; etc.

Lastly, each type has Number Values and Check Boxes associated with it, so Attributes for a Land Tile Type can be:
  • Food
  • Shields
  • Resources permitted
  • (etc.)
Some of the Attributes for Land Units are:
  • Everything which has a number associated with it (Attack; Movement; Teleport Range; etc.)
  • Check boxes for special abilities.
I have diagrammed, on one page, both the entire "hierarchy" of how the game now exists, and of how we can use that exact same hierarchy (with some modifications already in place) in the Spoiler below. The only other thing you need to know, beyond what I've already described, is that what looks like a 1960s "Peace" sign simply indicates that any "level" has more items below it than are worth enumerating like every Tile and Unit Type, etc.

Spoiler A Simple Diagram Of The Old And The New - :


C3+ Oject Diagram.jpg


ADDENDUM 2/16/21
- On further thought, a category, separate from Terrain Tiles, should be "Overlays" - Anything and everything constructed, from Roads to Cities. (This stemmed from an "Ah-hah!" moment, while thinking about Straits and Canals: we already have an overlay - Cities - which allows the presence of all types of units, so I imagine that a Canal could be built (for example) (a) within a City's "radius" (b) plus connected via Road or RR, and, (c) connecting two different bodies of water.

 
Last edited:
If you're interested, I'll reserve this spot, and the next few, for:
  1. A simple demonstration of manipulating AI behavior using a combination of simple logic, and math.
  2. The introduction of new and simple Rules to help invoke sophisticated AI behavior.
  3. The AI "Superstructure" of "States," which modify those simple Rules to evoke sensible reactions to times of Peaceful Growth And Expansion; Preparation For Offensive or Defensive War, and a handful of others.
  4. A detailed example of how the combination of Rules and States can direct an Offensive War, comparing and contrasting Napoleonic and WW2 warfare, both strategically and tactically - Starting with the Napoleonic.
  5. Then WW2, with and without Blitzkrieg. (Both examples will also demonstrate "intelligent" use of Artillery.)
  6. WW2 era examples of intelligent building and us of Aircraft, from choosing Strategic Bombing, to Ground Support, to CAP ("Combat Air Patrol")
  7. ... Honestly, I haven't gotten around to thinking about Naval Units yet, so I'll reserve this one, for that.
  8. And one more, for whatever else might come up :)
 
My apologies for the delay! But here goes -

When we here the word “rules” for a game, we’re usually think of what we, as players, are allowed, and not allowed, to. But we’re not playing a game, we’re building one, so the word “rules” describes now means, “AI Behavior.” Examples are: “What should this City build?,” and, “Where should this unit move, and what else should it do?”

Let’s leap right in. It’s the first turn of a game. The AI Civ starts the game with a Settler, a Warrior, a Worker, and a Scout. During the first turn:
• The Settler builds a Town.
• The Warrior fortifies in the Town. (This would be the case if there is a Rule: “No Town / City / Metropolis can be left undefended.”)

Now, what about that Scout and Worker? Let’s start with the Worker. It’s Turn 1, and, plainly, our first priority is Food.

To begin, remember that each Tile is worth exactly the same amount of Food and Shields as it would in the regular game. Accordingly, the AI looks at every tile around the Town. It calculates which Tile provides the most Food (which, if present, would include any Food adding Resource, like Wheat.

Right away, there isn’t one, but three equally possible choices: the three Grassland Tiles, each providing 2 Food. Irrespective, I imagine that most of us would go for the Tile adjacent to the River, because it can be Irrigated. Accordingly, we can add a Food “Bonus,” of “+1," to a Grassland Tile adjacent to a River, resulting in a, “Total Food Value” of “3," which is now the highest number. Given that the obvious next two Rules for the Worker to follow after that would be (1) Irrigate, then, (2) build a Road - We have just worked out how to have that Worker behave intelligently for the first eight turns, or so, of the game, by using simple math.


Screenshot1= MAIN.jpg


Next up I'll suggest what our Scout, and next built Warrior does, during the next 10 turns or so.

 
Last edited:
I don't know how I missed this in late January... most likely I was out hiking in a forest somewhere.

On Terminology

I agree, having standard terms will be helpful. Type and Attribute make intuitive sense to me. Category and Class, not as intuitive, but I'm not sure there's a better alternative. The "Experience Level" category has one Class, and four Types, each with a few attributes. The "World Size" Category has one Class, five Types, and a few attributes. The "Building" Category has three Classes, a lot of Types, and a lot of Attributes. Writing it out to see how it sounds, and get more examples. Checking the Apolyton BIQ docs, they use "Section" for what you describe as "Category", which only makes more sense if you're evaluating the BIQ file, and is thus not an improvement.

I suppose what's not super-intuitive is that Category almost sounds more like it should be what you - and Civ3 - called Class. Civ3 lets you select the unit class, Air, Land, or Sea (no Helicopters class). But in layman's terms, those are categories of units. If I were buying a computer, I could choose between a desktop, a laptop, or a tablet; and I could view them as categories of computers on a retailer's website. Maybe we're sticking too closely to Civ3's terminology.

So I wonder if taxonomy would help? The taxonomic order is Kingdom, Phylum, Class, Order, Family, Genus, Species. "Type" is our "Species" equivalent; attributes are lower-level than that, like "what is the fur pattern on this species? how many legs does it have? does it have wings?"

The other potential hazard with Class is that in our programming language of C#, Class is already defined to mean, essentially, a type of programing object. Both Category and Class would be defined with C# classes, and types would be defined as instances of those classes. So with that term, there would be different/additional meanings in the coding context than in the non-coding context. How much of a challenge that would be is debatable, but overloaded terms always come with a risk of confusion.

It's really the top-level name that's a challenge. I'm thinking maybe Order, Category, Type, Attribute? The "Building" Order has three Categories, each with many Types, and a lot of Attributes.

In my editor, I somewhat sidestepped this by having the most-visibile top level divisions be the tab names, so the discussion focused on "the EXPR tab". That wouldn't really work here.

Maybe I'm overlooking where Category in particular is already standard, but those are my thoughts on whether these are the terms that make the most sense. I do think what you've proposed, without changes, is an improvement over "Section" or "Tab", but if it's going to be a forever term it's probably worth considering alternatives.
 
On Rules

In short, yes! That was a great example; if only the Despotism penalty wouldn't decrease that food yield post-irrigation back down to 2! As it happens, there's already a rule "No Town / City / Metropolis can be left undefended." That also is a great post for explaining the concept to a non-technical audience.

It's both an area where the community can contribute suggestions as to what the AI should value, and where one of the challenges will be that what humans reason about intuitively or at a glance, the AI will have to arrive at through crunching numbers. I recently added code that essentially gives rules about where the AI should explore. It asks, "which neighboring tile is likely to reveal the most new tiles?" and chooses that one. A good strategy for revealing a lot of tiles quickly, but in the early game a better one would be focusing on revealing tiles around the starting location, even if the number of tiles revealed per explorer-turn is somewhat lower.

It's interesting, and an art. It will get more complex over time, too - how does the AI decide what to build next? Especially once there are buildings. Does it need more science? More happiness? More units? Currently, the AI has a regimented prioritized order for what to do with units - defending undefended cities takes precedence over exploring, for example. But as there are more choices that are less clear-cut, my expectation is we'll have formulas that weigh the relative importance of each option, and within those formulas there will be weightings for different factors, which could be tweaked based on either AI performance in playtesting (in the default C7 rule set, or for a mod), AI personality traits ("religious", "commercial", etc.), or perhaps how things have been going in the game ("the Greeks fought this player and got destroyed, now I'm at war with them, let's triple the importance of units"; "Babylon has started their spaceship and I'm only two techs away, let's prioritize science buildings").
 
@Quintillus - I like your analogy of taxonomy very much.

My "obsession" with OO is that it allows a great deal of ease of design. Sticking with Order, Category, Type, and Attribute -
  1. The "Unit Order" would comprise every inheritable attribute which a Unit can have: each type of combat (Land; Air; Sea) a Movement Factor; etc. For Movement, there would also be the Attribute of what types of Terrain the Unit can enter, and end its Movement on - basically, Land, Sea, and City, and, for Aircraft, Airfields. All of these are simply variables, without any values assigned to them: you can simply think of them as templates. And this method is easily extensible, as you'll see in a moment. (There would also be a very large number of Attributes to be defined, but consider how many there are, already, on the Units page in the game's editor.
  2. The basic Categories of Unit Types would then be Land, Air, and Sea. Each Category would inherit the attributes which are - with the 3 already mentioned - obvious, including an Attribute which defines what sort of Tile a Unit can end its Movement on.
    • Now, imagine that we wish to add Helicopters. Helicopters could traverse any type of Tile, and be able to end its Movement on a Land Tile which contains neither a City nor an Airfield. It would simply inherit the Attribute, "Can End Movement On Land Tile," with an editor able to add in (just as with any Land Unit) and "forbidden" Terrain," perhaps, e.g., Mountains. In short, we have created a new Category of Unit, based upon already existing, inheritable Attributes already defined within the Unit Order.
    • We could also add any sort of new, inheritable Attribute within an order, without it "breaking" anything already in place.
  3. For Unit Type, we might have Armor, Infantry, and Partisan. For simplicity's sake, let's just imagine that Armor and Infantry have the Attributes which are already in place, like the we mod by using "oddball" flags to have certain Transports able to carry Infantry but not Armor ... Now, about that Partisan: in the game, there is already an Attribute called, "Invisible." Another Attribute might specify what type of Terrain Tiles the Unit is Invisible in; Partisans might be Invisible in Forests, but not elsewhere.
If that's as clear as mud, see my second post, above and, of course, also just ask away.

... To be continued :D
 
But as there are more choices that are less clear-cut, my expectation is we'll have formulas that weigh the relative importance of each option, and within those formulas there will be weightings for different factors, which could be tweaked based on either AI performance in playtesting (in the default C7 rule set, or for a mod), AI personality traits ("religious", "commercial", etc.), or perhaps how things have been going in the game ("the Greeks fought this player and got destroyed, now I'm at war with them, let's triple the importance of units"; "Babylon has started their spaceship and I'm only two techs away, let's prioritize science buildings").

I think an approach using a selection of personality traits (perhaps at the "Type" or "Attribute" level) as the initial driving force for the AI's decision making would be a good idea.

I think one of the biggest problems with the AI in Civ3 is that all AI have only one AI personality type - they are all playing the game and playing to win. This means that once you get the metagame in your head, the difficulty of the AI is just reduced to whatever special bonuses they get over you (free units/cheaper trading/"seeing" the whole map/etc). Having them work towards goals which may not win them the game but may instead throw a wench in your own plans (or provide a solid ally!) could result in keeping the game competitve.
 
Interesting re: type, as I had been thinking of type being "Spearman", "Swiss Mercenary", "Panzer" before post #14. So to use the armor example, the "Armor" type could include multiple types of armor, e.g. "M4 Patton", "Panzer", "M1A2"? In other words, before I had thought that what the C7 code now calls "UnitPrototype", which would mean "Swiss Mercenary", "Panzer", etc. is what you meant by "Type", but now I think you mean for there to be another layer between those.

It could be interesting in that it could allow you to have an AI that is more likely to build armor, or partisans, etc. It also reminds me of the "AI Strategy" that Civ has, which can be combined with the "Build Often/Never" on the Civilization properties to have a somewhat less developed version of the same thing - the Mongols build a lot of offensive units, the Byzantines a lot of defensive ones, and the Ottomans a lot of artillery (in the default Civ3 rule set). In practice, I'm not convinced we can tell the difference, and it doesn't allow you to say, e.g. the Mongols should build a lot of cavalry, or the Vikings should build a lot of amphibious units (which they might due to Berserks having such good stats... but they probably won't build any more Marines than anyone else).

Long-term, what Virote_Considon mentioned about AI favoring aspects at the "Attribute" level could help with that - perhaps the Vikings prefer Amphibious units, or the Germans prefer Invisible Sea units, whether there's a specific type for "Amphibious" or "Submarines" or not.

The "Type" idea also matches up somewhat to Civ4's unit classes. They have melee, archery, cavalry, gunpowder, artillery, armor, and maybe one or two others, and that gives various effects such as which promotions are available.

I see advantages both ways. "Type" makes it easy to have the AI favor certain classes, with more depth than Civ3. "Attribute" targeting allows more specific weights - maybe some AI really likes Stealth aircraft, which probably is too niche to have its own "Type". Overall though, being able to weight the AI to have different (and discernable) personalities seems to be the goal.
 
I see advantages both ways. "Type" makes it easy to have the AI favor certain classes, with more depth than Civ3. "Attribute" targeting allows more specific weights - maybe some AI really likes Stealth aircraft, which probably is too niche to have its own "Type". Overall though, being able to weight the AI to have different (and discernable) personalities seems to be the goal.

Yes indeed, "Type" and "Attribute" together would help create a more interesting/"intelligent" AI if it can be programed to work as wanted.

there's already a rule "No Town / City / Metropolis can be left undefended.

This Needs to be Adjusted... the AI needs to place more value on their Towns / Cities and Metropolis's... a Better understanding of Offense/Defense and how to decide when and where the Units are placed.
 
Yes indeed, "Type" and "Attribute" together would help create a more interesting/"intelligent" AI if it can be programed to work as wanted.

Now that I'm actually starting to implement unit prototypes (e.g. Galley, Archer), versus having them hard-coded, I'm starting to think about the practicalities of Oz's proposal. I was also reminded of my recipe manager's organization; you can add your own custom, and nested, tags. So I have, for example:

Code:
American 
  -> Cajun and Creole
British
 -> Scottish
Canadian
...
Course
  --> Breakfast
  --> Main Course
  --> Soup
  ...

A recipe can be in as many categories as you assign it, and matches parent categories. So my jambalaya recipes are in "Cajun and Creole" and "Main Course", and match when I search for American, Cajun & Creole, or Main Course. Chili is both a Soup and a Main Course, and American.

I'm thinking perhaps some sort of user-organizable tag system like this might be more flexible than Oz's proposal, while still allowing it to be implemented. The Land/Sea/Air distinction would be inherited from Civ3 as a base set, but additional categories such as Armor, Helicopters, etc. could be added... and if your mod justified it and you were willing to tweak AI preferences enough, you could get pretty deep... attack helicopters, transport helicopters, cruiser tanks, infantry tanks, light tanks, main battle tanks... I wouldn't propose getting that deep in the default expanded ruleset (versus the legacy Civ3-default ruleset), but a mod could.

This is all long-term, and I would not expect to see any of this beyond the legacy Civ3 distinctions before 2023... although it may lead to the implementation of those being slightly more flexible than it would have been otherwise.

This Needs to be Adjusted... the AI needs to place more value on their Towns / Cities and Metropolis's... a Better understanding of Offense/Defense and how to decide when and where the Units are placed.

Indeed, the AI has received very little instruction on attack or defense so far, beyond, "you should have a unit in towns". Combined with the numerous barbarians and the lack of unit healing, this often leads to unfortunate results.

It also is a good reminder that we always need to be vigilant about our messaging of where the mechanics and AI are. The AI is well known to have a lot of holes right now; it simply hasn't been taught about all the core concepts it will need. It's a fresh arrival at boot camp.
 
Indeed, the AI has received very little instruction on attack or defense so far, beyond, "you should have a unit in towns". Combined with the numerous barbarians and the lack of unit healing, this often leads to unfortunate results.

I find it very interesting that some CIVs do heal their Units while others do not tend to do so. In general, the AI tends to Run their "Special" One of a Kind Units until they die. This is seen especially in MODs such as EFZI2 Elite... the Farmers for example will always get the One of a Kind Farm Tractor Killed rather than simply take it into a Building to Heal. Same thing for The Survivors with Vuldacon...A Human Player would not allow that.

Perhaps there is a programming method to enable the AI to differentiate between more valuable Units by one of a Kind and the Unit's Value due to strength, cost and over all value.

As for Units the AI places to defend a Town, City or Metropolis, it should be more about the over all need due to the Value of the Town, City or Metropolis and what is going on concerning them. As it is, the AI seems to be programed for "Offense is the Best Defense". While there is some truth to that, other values need to be added to allow the AI to make better decisions :)
 
I turn my back for a week and you guys are off to the races! :clap:

I realized that, at the end of my last post, I forgot to clarify something: Every Attribute maps directly to an existing game Attribute - MF; Strategies; etc. This ensures that any existing mod can be seamlessly played by the new game. Furthermore, any new Unit could (might?) still be usable in existing mods, with the obvious caveat that any of the new features could not come into play. Yet there are some obvious exceptions: going back to our hypothetical Helicopter, it could certainly be made capable of landing on a Ground Tile, using the existing Default anim.
 
Back
Top Bottom