I am trading everything away, even old strat resources. But England has spread from around Poland to China and has arty and infantry while I am working with cannon and rifles. Luckily they don’t really know how to use this to their advantage and I can survive.

Hmm, pretty good deal on Civ5 on Steam right now for those that don’t have it. $17.00 or the deluxe for $20.40. 66% off.

So, Russia and Songhai declared war on me in the late industrial period on a standard, continental map. I just happened to be allied to a city state that was sitting on the small strip of land that connected my part of the continent with the part Songhai had. Not only did the AI get confused by this, it amassed all of its units along the border of that allied state and sent one of them in at a time. What the?

I watch over the course of many turns their units getting destroyed by the allied state’s artillery and city. Once in a while a unit would attempt to go around using water (one eventually made it), but most got destroyed even quicker than the land route. To add to this frustration, another city state I was allied to sat halfway across the world next to Russia, who was doing the exact same thing. They could have demolished these ally states but were sitting back and casually attacking them instead for some unknown reason.

Needless to say, I never felt threatened by the joint attack and am now in the process of taking out all of their units with battleships. It almost feels like you have to always play on a pangaea-like map to avoid these sorts of issues.

Embarking was a fantastic idea especially when it comes to the Ai, but they’ve done very little with it. The naval capabilities of the AI are as bad as they’ve ever been.

And in particular (addressing the AI programmer):

  • No, dumbass, don’t embark to cross a 1-hex lake with enemy ranged units adjacent.

  • You know it’s hard for random embarked units to assault fortified coastal units. You implemented the combat modifier yourself, so why are you doing just that with one of your precious few units when there’s a perfectly fine empty hex right there to land on?

  • For heaven’s sake, don’t embark when there’s enemy naval units adjacent. It’s your damn instant-kill rule, why are you ignoring it?

This appears to be naive pathing dominating other considerations, and should be easy to fix if a) someone cared and b) AI code framework wasn’t horrible. At least one of those things isn’t the case, likely both. You have to check to see if the path is goddamn stupid before just executing it because it has lower movement cost. The same thing happens on land when the AI moves unescorted siege units in front of enemy melee, or when it for some insane reason doesn’t stack great leaders with ground units. The annoying thing about that last is that there’s obviously code for stacking settlers with ground units, so why not leaders, too?

Anyhow, this really isn’t rocket science. It’s not like this kind of “AI” is the kind that requires Ph.D.s to work on at MIT, CMU, or Stanford. Game AI uses a mix of long-understood standard techniques and ad-hoc hacking; you just have to actually want to get it done right and have a foggy clue how to do it.

I read in an interview of the developer of Strategic Command where he said AI was the hardest part of his program where he spent roughly 1/2 the time of the whole project implementing a decent AI. So maybe it IS rocket science.

Generally true, but the specific rules that Miramon cites really should be simple to implement.

My impression is that the Civ5 AI doesn’t use such specific if-then rules for unit movement at all, but simply combines a few attractors and moves units in the highest-rated direction. That works okay if there’s a ton of units to work with but can produce spectacular failure for individual units.

I’ve done it. You can’t really introduce if-then rules as you suggest, since it’s something that really has to be done during pathing, not after you’ve got a path. What I did was implement a mask, where enemy units adjust the estimated cost of moving through a tile if they’re likely to kill the moving unit. You can’t prohibit it entirely, since a surrounded unit will freeze because all paths are forbidden, but a high estimated cost will strongly discourage a path unless you have no other choices.

The headache is in considering multiple friendly units. For example, the enemy might have a group of Warriors which would discourage moving a single Warrior nearby, but if you’ve got them outnumbered 2:1 or something, the group should not consider that clump a threat. This is one reason why coding a Stack-Of-Doom game like Civ IV is a lot easier.

I don’t see why you can’t use simple if-then rules even if you consider pathing to be atomic with no intelligence allowed within the activity, and even if you have really minimal planning associated with unit actions.

Imagine for each unit you have already decided on movement goals, ie the hex they want to get to, and you compute N paths, each of which naturally has an associated cost. You then let your if-then-rules fire on it; each rule can add additional “cost” to a path. Now you re-evaluate to see which one is best.

So you have rules like:

IF (enemy naval unit in range AND path includes embarkation)
THEN add 1.23E17 to cost of path.

For the most part the tactical pathing that shows the stupidest AI behavior in Civ V only involves distances of a few hexes, so we shouldn’t be worried about some kind of CPU or memory explosion if we compute say 5 paths for each unit. When you’re routing across 30 hexes to get to some foe you’ve stupidly declared war on without being anywhere near, then you can use a different approach if you don’t detect enemy units nearby.

Game AI may deservedly take the most resources of any phase of strategy game programming (and why is this surprising?) but it shouldn’t be that hard to get it to not look totally stupid; or if it is that hard, you have to change your game rules until you’ve got a ruleset you can code to without embarrassment.

It’s not necessary to consider enemies during pathing, just not after pathing. You could also get a list of all possible end points of the current unit’s movement (using a simple path coverage algorithm that considers only raw movement rules), match it against all desirable locations for that unit given attack opportunities etc., and then run through if-then context rules for each location from the most desirable on down. Then run A* again to get the actual path to the selected location. That’s what I did in Hexkit, although admittedly it was pretty slow and likely wouldn’t scale up to a large Civ5 map. edit: You could use some two-stage method as Miramon suggests, with “blind” unchecked pathfinding if there are no enemy units nearby and a full evaluation of multiple paths if there are.

Yeah, the AI does ok at dealing with oceans, but it gets hopelessly lost on archipelagos. I’d go so far as to say that archipelago maps are unplayably broken at this point :( It doesn’t help that its expansion algorithms get all kinds of confused with unusual landmasses. I play strictly on Continents or Pangaea for that reason. Emperor+ on those to map types is a decent challenge; the AI can get enough units together to be a credible threat to a reasonably competent player.

While we’re on the subject of pathfinding, does anyone get enormous slowdown between turns when a unit is set to auto explore? Maybe it’s a MP only thing but having two units on auto doubled the turn length, and this is on two high end i7 machines.

No, I’ve seen that too. I’ve also seen the turn length explode during the late game.

I’ve gone back to Civ IV.

Auto-explore is strangely slow, yes. Turn times are otherwise fairly quick since they fixed some problem related to city states a few patches ago, though.

I’ve seen auto-explore be oddly slow, but not because the turn time is extraordinarily long. It’s usually because the view adjusts to an autoexploring ship but it doesn’t move for several seconds, then takes off on it’s way. I always thought it was due to the AI calculating the best route to take to match whatever goal the autoexplorer has (uncovering new land/water). If the view didn’t switch to the autoexplorer, I wouldn’t have noticed it in terms of turn length.

I’ve always wondered about this: why do people use auto-explore? I never seem to have enough units to make handing over that control worthwhile. Same with auto improvments. Maybe it’s me that’s strange, because I’m more of a builder than anything else.

I don’t use auto-explore on land, just on sea. Most of the ocean tends to be empty, so exploring it manually is rather boring…

For me when I use it, it is because it feels cumbersome having to keep on moving units around the map and I’d rather focus my thoughts on more pressing matters. The game as I recall did a decent enough job with auto explore, though it has some sort of tendency to hang around the ice caps. That said, I have only ever auto-explored the sea. I never saw a point with land because I like to know what terrain I’ve revealed for possible city sites, making sure I get the goodie huts, and in general, building the lay of the land up in my head.

I use auto-explore mainly for water, like Chris. However, I will use it on land for a short time in the early game after my immediate surrounding area is exposed and nearby civs and city states have been found, but rarely do I have more than one land unit auto-exploring at a time.

Okay, help a noob out. I’ve dabbled in this genre but I’ve never really understood what I’m doing in the broad picture. I have a game that is past 300 turns and I just don’t know what to do. I’m way ahead of everyone in terms of research, gear, etc. but it seems like anything game-ending is still years away. How the heck do you finish this thing? I’m playing at the second or third difficulty, so not difficult at all and other nations are scaredypants.

H.