tnevolin / thinker-doer

Modifications to a SMACX Thinker mod to highlight more game features
GNU General Public License v2.0
27 stars 3 forks source link

bad AI food choices in oceans #86

Closed bvanevery closed 3 years ago

bvanevery commented 3 years ago

poor square choice

In the oceans the AI makes a poor choice about what squares to work. Strictly speaking, I don't know if this is AI code or separate UI code. This is what happens when I click on the picture of my base in the center, what I get for a default square choice. It will also be the choice when my base grows and I'm not babysitting it.

The Pirates are starved for minerals at the beginning of the game because their free ocean minerals have been removed. They grow rapidly due to the excessive amount of food provided by WTP on both land and sea. They of course do not have the happiness infrastructure for such food. The city will merely go into drone riots when it hits size 3. There's no reason to be trying to grow at all possible costs. Getting minerals production up is way more important. I took the trouble of hand terraforming the squares around the base in order to make up for the Pirates' lack of minerals. I shouldn't have to manually set which squares are worked as well.

I don't know whether digging into the code where this decision is made is easy for you or not.

In my mod I took the path of least resistance: don't penalize food production because of minerals. I noticed that the AI would often put a mine on top of a farm, and since I didn't have access to any code to change its behavior, I made it not a penalty anymore. It's very easily changed in alphax.txt. This saved me the hassle of having to redo all the AI's dumb terraforming when I took something over. In my mod it isn't dumb anymore, it's fine.

set a medic just before size 3

It might only be UI code that's the problem. When the base was size 2 and just about to turn size 3, I set 1 worker to a medic, so that I wouldn't get a drone riot the next turn. The default tile working algorithm did make a correct decision to work the available 3-1 tile and not the 4-0 tile.

tnevolin commented 3 years ago

Worker placement choice is a very subtle aspect of AI tuning. It should work well in land/coastal/ocean bases. Very difficult to tune. If you come up with some well thought algorithm generally suitable for all bases - I'll give it a try.

I am not going to spend my time on working on such algorithms. It is very time consuming with unproven results. It is not that we are writing a chess program for Deep Blue. The community is not that big and there is no reward. Sorry.

bvanevery commented 3 years ago

I hear you on the Low Hanging Fruit problem. It's certainly not worth heroics. I've tried to avoid getting snared in such quagmires, as I really should be working on a commercial game that can make me money.

Somewhere, 3 food 1 mineral needs to be weighted more than 4 food.

tnevolin commented 3 years ago

I agree with you complaint in general but again it is not an isolated bug/problem. It is really should be weighted properly to not break other cases. And even in case of perfect balance the benefit could be negligible.

Again. I am not saying you or somebody else should not do that and I am willing to review and try it out if someone come up with some complete algorithm. Not just "in this particular case as on the picture I want AI to make this specific decision". This is even worse spend of time than doing full fledged AI tuning.

bvanevery commented 3 years ago

Minerals should be universally valued as worth more than food, even if by a small amount, because WTP starves the player for them, but provides tons and tons of food.

Although the more nuanced equation is, given minimum amounts of some resources, which excess is worth the most? 3 food 1 mineral is definitely worth more than 4 food. However, 1 food 2 mineral is not clearly worth more than 2 food 1 mineral.

So this depends on how centralized or dispersed the decisionmaking equations are.

There's also the sum total of the city's productions to consider. 3,1 + 3,1 + 2,1,4 = 8,3,4. 3,1 + 4 + 2,1,4 = 9,2,4. The former is clearly superior to the latter, because the minerals count is so low.

tnevolin commented 3 years ago

I don't understand the problem with sea bases governor. When I test it - it always chooses 3-1-0 over 4-0-3.

Besides, I don't understand why 1 mineral is even better than 3 energy and 1 nutrient combined. One always can rush production with energy 3 to 1. So the productivity value of these two tiles is the same but latter also have extra food. So from that point of view it is clearly better.

Of course 3 energy do not go directly to credits. They are split between credit and labs when labs is arguably slightly worse than productivity. So maybe latter is not precisely better. Maybe it is on par. But it definitely not inferior to former. Extra cash flow may pay great role in rushing critical production in some other base. Not necessarily this one. I had cases when my cash flow was negative and I had to pump more into economy. It is pretty damaging to advancement.

bvanevery commented 3 years ago

I never said this had anything to do with the Governor. I never use the Governor. This is primarily about default square selection when I click on the picture of my base. Governor, base AI, and default square selection unfortunately could all be different code paths. In an ideal universe, one would have hopefully centralized this, but who knows. I've only started to look at the WTP repo now, and even that's not the original binary code.

I don't understand why 1 mineral is even better than 3 energy and 1 nutrient combine

I did not report this as a problem. Perhaps you are making an additional observation about further weirdnesses.

tnevolin commented 3 years ago

I never said this had anything to do with the Governor. I never use the Governor. This is primarily about default square selection when I click on the picture of my base. Governor, base AI, and default square selection unfortunately could all be different code paths. In an ideal universe, one would have hopefully centralized this, but who knows. I've only started to look at the WTP repo now, and even that's not the original binary code.

The Governor or default selection = something automatic.

I don't understand why 1 mineral is even better than 3 energy and 1 nutrient combine

I did not report this as a problem. Perhaps you are making an additional observation about further weirdnesses.

Than what is the problem? I thought you are unhappy it doesn't pick mining platform tile vs. tidal harness?

bvanevery commented 3 years ago

Please look at the screenshots. There is no tidal harness. The default picker is choosing a 4 food square, over a 3 food 1 mineral square. The latter is clearly superior for the size of the city.

tnevolin commented 3 years ago

Yes. I see this too. First worker is placed on platform but second is not. The default choice prefer combined intake of 9-2-2 over 8-3-2 for 2 size base.

There is an interesting effect. If I allow base to grow but itself to size to then it places both workers on platforms. However, if I then click on base center forcing auto placement it jumps to tile without platform. This happens only with second worker. All others are placed on platforms up to size 11.

tnevolin commented 3 years ago

I checked the code. When citizen is added it assumes previous workers are placed right and just tries to place new one. When citizen is subtracted or user clicks base time requesting replacement - all workers are relieved and they are placed one by one over again. Every time new worker placed the so far combined nutrient yield from placed workers is compared to current food consumption. If it is too low to feed the base it emphasizes nutrients. That is why when first worker is placed the combined nutrient intake is only 2 but the consumption is 4 (in 2 base size). It is then placed on highest nutrient yield tile. The algorithm is definitely stupid one but it should not error too often. Most of the time this richest nutrient tile will also have some energy and won't be a complete waste. You just found a specific condition when it breaks. If you build harness in one tile it will prefer it.

bvanevery commented 3 years ago

Huh, that is a weird 2nd code path.

With the Pirates, with a player dealing with their totally rational deficit of minerals, they will get this error at the beginning of every single game. That's annoying enough to want to squish the bug, if it's easy to fix.

Is there some weight where the 2nd code path's emphasis on nutrients can be turned down? Where is the code exactly?

tnevolin commented 3 years ago

With the Pirates, with a player dealing with their totally rational deficit of minerals, they will get this error at the beginning of every single game. That's annoying enough to want to squish the bug, if it's easy to fix.

Nope. They won't. Read it again. When population naturally grows one by one algorithm works fine. You can simulate that in editor and see that it works. Doesn't matter if governor is on or off. What matters is that population increases in small increment. This thing happens only when population is either decreased or user explicitly request total replacement by clicking base tile. Both of the above happens quite rarely for AI. And actually for most human players too. I almost never explicitly request worker placement.

Besides. Even if it happens it is only one tile emphasizing food over minerals. Others should be fine. If this tile has also harness on it then it is not a big deal to have one harness worked at sea base, right?

bvanevery commented 3 years ago

At the beginning of the game, you are (I am?) manually building things on squares. When you finally complete stuff, you need to make manual adjustment for optimality, or your base will continue to work a sea square with only 1 nutrient or something. Clicking on the picture of your base, is the fastest way to do this, and is pretty much an automatic muscle memory movement for any experienced SMAC player. Since squares are going to be completed, and kelp is also going to spread on its own as happened in these screenshots, this is going to happen all the time with the Pirates.

Where is the code for this decision?

tnevolin commented 3 years ago

004E80B0

bvanevery commented 3 years ago

It's in machine code? Good grief.

I will remind about the path of least resistance: do not penalize nutrients because of a Mine or Mining Platform. Problem goes away.

tnevolin commented 3 years ago

It is an address of function that places workers as you requested. It is what you were looking for?

bvanevery commented 3 years ago

I was hoping the logic might have been something that someone had already converted into C++. Oh well, no such luck. I've never gone up the learning curve of how to deal with the game's machine code. That seriously raises the bar for the level of effort this would require out of me personally. From a triage standpoint, not gonna happen right now. But that's what an Issue Tracker is for. Least I've got an address to start at in the future, if I get into it for other reasons.

tnevolin commented 3 years ago

Nope. It is not converted to C++. Check OpenSMACX if it does it already.

tnevolin commented 3 years ago

I am going to close it on a ground that it is very hard to fix right and that the bad effect is negligible. Sorry, man. Thank you for catching this up but there are a lot of things in this game not worth fixing. I would not even remove food penalty for mine just for that - too not worth it.