• We need to know your opinion about our social media accounts! Tell us here if you follow us on social media and what we could improve.

AI workers

sveint

Warlord
Joined
Oct 9, 2006
Messages
187
I'm posting this here because I really don't know where else to put it.

One of the weakest parts of the AI at the moment seems to be workers. And of course this affects the human player too if you automate.

Let's skip the details, but currently workers do alot of random stupid things and then continuously replace these random improvements.

I'd like to suggest a simple rule (algorithm) for how an automated worker should behave. Please feel free to give your views. Hopefully some of this can make it into a future patch.

Suggested simple rule (to be modified by feedback), exceptions below:

  1. Plains: Irrigate if possible, otherwise cottage
  2. Grassland: Cottage
  3. Flood Plains: Cottage
  4. Hills: Mine
  5. Forest: Chop, unless tundra (lumber mill)
  6. Resources: Improve (no forts or irrigation or such)
  7. Forts: Never build

Exceptions (these might be harder to implement)

  1. Low food cities: Can irrigate grassland and build windmills (never on top of a resource)
  2. Low hammer cities: Can build workshops on grassland only
  3. Irrigation chains: With the invention of Civil Service, plains that are not adjacent to fresh water should be irrigated, using a chain through irrigated grasslands ONLY
  4. Watermills: It is very hard for the AI to judge when these would be beneficial. Once they can be built, I'd say 50/50 build these or cottages. Either way, cottages should not be replaced by watermills or we get the endless re-improve loops again. It's perfectly fine to use the simple option of never building a single watermill.

Simple yes, perfect no, but it would be alot more efficient than the current workers. Currently I still see jungles in the BFC late in the game, the workers are too busy redoing other tiles over and over...
 
I wouldn't go that rigid. I agree the AI could be improved with better worker decisionmaking

Some rules:

1) the AI does NOT build a fort on an improvement if it is in the fat cross of a city

2) This may be too much to ask. I'd like to see the AI examine what type of city it needs, and specialize. For example, if the AI is falling behind on the tech race and they have a city in the middle of a bunch of grassland, cottage spam.

3) Be very specific in where it places national wonders. For example, no Wall Streets in production cities.
 
How about if we could choose the improvement we want then shift-click all the tiles where we want that improvement?

So we could choose a farm, shift-click 4 tiles to have farms built on them then choose a cottage and do the same. Then we can create a list such as...

Farm
Farm
Cottage
Cottage
Cottage
Farm
Farm

...and thats the order the improvements will be built on. The AI could work out which of the shift-clicked farm tiles will provide the most food and work from best to worst. The first farm will be built on the tile that will give the most food, then the second etc.

Obviously it will need some wrinkles ironed out, but I think it would be worth looking into. :)
 
How about if we could choose the improvement we want then shift-click all the tiles where we want that improvement?

So we could choose a farm, shift-click 4 tiles to have farms built on them then choose a cottage and do the same. Then we can create a list such as...

Farm
Farm
Cottage
Cottage
Cottage
Farm
Farm

...and thats the order the improvements will be built on. The AI could work out which of the shift-clicked farm tiles will provide the most food and work from best to worst. The first farm will be built on the tile that will give the most food, then the second etc.

Obviously it will need some wrinkles ironed out, but I think it would be worth looking into. :)

This is pretty close to an idea I had a while ago. I think the interface for worker AI should be rethought, not just the AI itself.

The way I see it, your worker needs come in two basic types:
1) You need certain things built/chopped in a certain order, and every single turn matters.

2) You know what improvements you want the city to have eventually, but you don't want to handhold the workers to get there.

When you think about it, it is impossible for any AI to meet EITHER of those two needs. Until they invent mind reading technology, no program will ever be able to guess what you want. For that matter, I think that allowing the computer to make logistical decisions for you is bad game design.

The solution is to rethink how workers work, so to speak.
In case 1) you don't need any sort of AI, because the player will always take full control. The only thing that changes from player to player is how often they decide they need total control, but even the most microphobic player will still probably take full control for wonder chopping, hooking up resources to the starting city, etc.

In case 2) you don't want the computer making decisions of what to build, but you care less about what order it gets built. So it should be possible to designate a cottage here, a farm here, a workshop here, and so on, and all the AI has to think about is how fast can it get the job done.

This gives the player full control over what his civ will eventually look like.
This makes the AI easy to make. You don't have to argue about whether the AI should put farms or cottages or watermills on floodplain tiles. That's not a decision the computer should be making anyway (Except, obviously, for AI civs.) All the computer cares about is doing the player's bidding as fast as possible. And maybe dodging barbarians.
 
I like the idea of the AI actively using workers to specialize their own cities based on what their needs are - I don't think that's beyond the scope of what AI can accomplish these days. As far as automated workers go - I think this is more of a beginner's tactic for making the game less complicated. I couldn't see an experienced player with a good understanding of city specialization using automated workers... unless they were just being lazy - it wouldn't make sense. So, to me, the goal of automated workers should be to make balanced land improvements without city specialization in mind, cause the player who uses automated workers probably isn't going to be as concerned with city specialization - and granted, w/ automated workers, there's no way for the computer to know how you're choosing to specialize your city.
 
Thinking a little more, this time from the perspective of the AI civs.

What if we took my improvement designation idea, and then let the AI have access to it.

The AI should make plenty of workers, at least 1 per city, and they default to automated behavior.
The AI would not designate all the improvements all at once, because then workers would swarm one city that doesn't need improvement, while the other cities dwindle. So instead, the AI should designate as many tiles as the city can work, maybe +1 so that it can prebuild.
If the AI wants to hook up a resource or chop a forest for hammers, it can just snag the closest worker and queue up the orders to get the job done. So if it wants to hook up a cow, it will tell the worker to stop automating, go to the cow, build a pasture, connect the road, and then go back to automating.

(Does the AI currently understand wonder chopping?)

The basic gist is to have the AI think in terms of goals, not individual workers. Instead of going through every worker and trying to find something for it to do, it should find things to do and send the workers to do them. The goals don't have to be all that complicated. It could even just be a case of shuffling through every possibility and picking whatever gives the best raw numbers.

At its simplest, the AI would probably not perform much differently than it does now. But if you wanted to, you could easily have the AI designate a city to have a certain role. For instance, a city with a high food potential could become designated a GP farm, and that city would designate farms wherever possible. You could make the AI carefully balance food, so that a city will grow exactly to the happiness cap and then stop.
 
The point of my post was that a simpler algorithm would work better than anything else. We'd all like to see advanced AI behavior but sometimes better results are obtained by just keeping it simple.
 
The problem with these logical patterns is that there are so many exceptions to them.

The only automation I use for my workers is for building roads - I usually have other priorities for them and I don't want them to undo something I've already done. But the AI could use some work. Some possible hard-and-fast rules:

Never replace villages or towns UNLESS a special resource has appeared under them, and either one of the following applies:
- improving the special resource would yield as much or more combined commerce and hammers as the village/town does
- the special resource is the only one of its kind that the AI has within its borders

Don't build windmills until Replaceable Parts (or possibly Electricity?)

Only build enough farms to feed a population sufficient to work all the tiles in the fat cross.

And so on. But I can think of exceptions to even these rules - rare ones perhaps, but exceptions nonetheless. What the AI really lacks is the ability to make sweeping, empire-wide decisions on what improvements to build for what cities.

For instance, it's easy to say that a city with lots of hills and a few grass/plains = mines and farms, and a city with lots of grasslands and a few hills/plains = cottages, a couple farms, mines to-later-be-turned into windmills. What's really vital is the overall strategic view that tells the human that even though he or she has tons of grassland around almost all his/her city sites, it's probably a good idea to try to convert one of those cities into a production site for units. I'm not sure I've ever seen that sort of insight from the AI.
 
I don't think that's beyond the scope of what AI can accomplish these days

Nothing's beyond the limit of what AI can accomplish. The problem is that massively complex AIs lead to

1) Bugs, obviously

2) Slowness.


However, processing power lately is becoming a non-issue (read: dual/quad cores) and as such the second problem is soon to be a nonissue.
 
Nothing's beyond the limit of what AI can accomplish. The problem is that massively complex AIs lead to

1) Bugs, obviously

2) Slowness.


However, processing power lately is becoming a non-issue (read: dual/quad cores) and as such the second problem is soon to be a nonissue.

I think my point was that I believe building semi-intelligent AI controlled workers is very doable in Civ - It's not beyond the scope of what can realistically be accomplished in the gaming world, but then again, I don't think it's necessarily bad as it is now. Maybe it could a little tweaking... but I wasn't talking about building a rediculously intelligent super-AI.
 
Blake's Better AI made huge steps in improving workers. Most of those changes should be in BTS.

The biggest issue with the AI is that it isn't capable of seeing the past, or planning ahead. It can only look at the current situation this turn. It can, for example, see that a city is not at the happiness cap, yet isn't growing, so more farms are needed. It can't think in term of long term goals. It doesn't see a city and say "This would make a great production city once I have fully upgraded workshops with State Property". Instead it sees a city and says "The best thing I can build on these grasslands right now is cottages". Then a millennium or two later it looks at the same city and says "This is a commerce city. Building workshops wont help."

Something else to note, if you use the emphasis X features of the governor, then automated workers should build improvements that help to boost X.

To get a better idea of how the AI works, I highly recommend that you all read the Better AI thread by Blake.
 
Create an algorithm for the AI on Noble and above to look at the tiles in the fat cross and their food yields. Convert 2s into 0s, 1s into -1s, 3s into 1s, and so on. Then add it up and feed that number to the Worker AI. The binary can set a trigger telling the worker(s) the command for farms, and the limit set as that number. If more food is needed, beeline for Machinery and build Windmills. If not, create Cottages in already commerce-d tiles and workshops in others.
 
It's possible to make a good worker AI, but it would require alot of work.

Why not, with little work, use a simple algorithm that gives better results?
 
Err... you can always go to Options and check the boxes "Automated Workers dont replace existing improvements" and "Automated Workers dont chop forests"

This way, you improve the BFC yourself, the way you want it, and automate him to do the dirty job of building roads, irrigation chains, connecting distant resources, chopping jungle, etc.
 
Top Bottom