ommmmmmm / keeperfx

Automatically exported from code.google.com/p/keeperfx
0 stars 1 forks source link

Computer player ignores gems when low on gold #229

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I was playing a game, in version 1.4.4.996 and the enemy keeper mined the gems. 
At some point in the game he also wanted to mine my gold, loosing most of his 
imps in the process.
At that point the gems no longer interested him and he stopped mining gems 
alltogether while continuing to send imps into my dungeon to try and reach my 
gold.

When not having too much gold the computer player should focus mining all faces 
of gems first. Savegame attached.

Original issue reported on code.google.com by Loobinex on 24 Jan 2014 at 8:30

Attachments:

GoogleCodeExporter commented 9 years ago
Do you really think that would be a correct approach, to put gems over gold?

That would lead to gold never being digged.
Also, gold provides faster wealth than gems.

Finally, this is actually not a computer player issue, but imp tasks issue - 
computer player marked both gems and gold for digging, imps have chosen to dig 
gold first.

Imps are always placing non-gem slabs as digging priority - I made that change 
because on some levels imps were so focused on gems, that they never digged 
anything else - so computer player couldn't even build any rooms beyond 
treasury.

Original comment by mefistotelis on 27 Jan 2014 at 11:52

GoogleCodeExporter commented 9 years ago
Ok, if computer player marked both, that's fine. Still not very sensible to try 
to mine in my dungeon when save gems are available.

I would say if possible you always should prioritize gems over gold since that 
way you end up with more gold in the long run->

* Let’s say you have 8 imps, 6000 in gold to mine and 2 faces of gems. Each 
imp can mine 10 gold per second or 5 gems per second.

* If you prioritize the gems you have 6 imps on gems and 2 on gold, the 2 imps 
would take 6000/10/2=300 seconds to mine the gold. In that time the 6 remaining 
imps would have mined 6x5x300=9000 gems. So in 5 minutes a total of 15000 gold.

* If you prioritize the gold, 8 imps would mine out the gold in 6000/10/8=75 
seconds, and in the remaining 225 seconds only 6 imps would mine 6x5x225=6750 
gems. So in the same 5 minutes a total of 12750 gold.

If imps prioritize digging over gems this would also harm the human player, 
especially on low income maps with only one or two gemfaces available. Digging 
a room can be done with 1 or 2 imps, but if all 8 of your imps decide to dig 
out that single room you run out of gold in no-time. In those scenario's it's 
key for the imps to stay on gems at all time.

The computer player should always attempt to have at least 2 more imps then 
they have gemfaces available. On top of that, when digging rooms, assign an imp 
to the job so rooms are created even when imps are in short supply.

A bit of an unrelated question: Did you also change something in the imp-code 
that compels them to reinforce walls when you drop them somewhere? I have a 
feeling they do this much more than in vanilla keeper, I find it more difficult 
then I remember to get imps to pick up corpses/prisoners just in enemy 
territory, when I drop them on my closest tile, they just reinforce the wall 
next to it.

Original comment by Loobinex on 27 Jan 2014 at 8:29

GoogleCodeExporter commented 9 years ago
How about if they prioritised proximity?
I was playing a level where the computer player had gems built into his dungeon 
and was in the far northeast corner of the map where I was in the southwest. 
And yet the AI crossed two rivers of lava and 1 of water to get to my gold that 
was my only source of income. When I got to their dungeon they weren't mining 
the gems at all.
So maybe there's a way to prioritise gold only if gems aren't closest? 

Original comment by shortaie...@gmail.com on 28 Jan 2014 at 3:21

GoogleCodeExporter commented 9 years ago
As suggested on issue #302, a possible solution on putting more focus on gems 
with other tasks still getting completed is to have imps get 'fed up' with 
mining gems and won't allow them to spend more then 75% of their time on mining 
gems. For example if over 4500 of the last 6000 gameturns are spend 
mining(counting trips to the treasure room) the imp will select another task.

This - or any other solution - would really strongly benefit CP on maps with 
gems, as right now they frequently run out of gold on these maps which makes 
them very easy and inferior to the Gold-ai.

Original comment by Loobinex on 19 Mar 2015 at 11:22

GoogleCodeExporter commented 9 years ago
As of now I made a change which allows imps to search of other tasks only every 
5 times they return with gold to treasury.

This makes imps dig the gems a little longer, but they still switch to other 
tasks sooner or later.

Also, when a new imp is created with no job in the place he drops, he will 
still go for digging jobs other than gems, if only there are any.

I will think about how to prioritize gems during task selection.
Also, the value of 5 unloads before checking other jobs could be increased.

Original comment by mefistotelis on 21 Mar 2015 at 1:51

GoogleCodeExporter commented 9 years ago
Ok, I will look tomorrow if the CP performs better on maps with gems now.

Original comment by Loobinex on 21 Mar 2015 at 1:55

GoogleCodeExporter commented 9 years ago
I have to say, I can't tell the difference. Multiplayer map 146 is a good one 
to test this, but I've also looked level 15 and Morkardar. I've looked at this 
in the old and new nightly, and in both the CP seems to mine quite enough of 
the gems for a while.

Problems begin when they start to run out of imps and not build enough new ones 
to effectively mine. Also issue #204 seems like it could make a huge difference 
because they mine really inefficiently.

I'm not sure anymore the CP can be improved by more focus on gems for the CP or 
Imps.

Original comment by Loobinex on 22 Mar 2015 at 9:40

GoogleCodeExporter commented 9 years ago
Ok, so the problem is is imps task selection.

When you create an imp, it selects a job from queue for himself. If that job is 
unsafe, the imp will likely die. Then another imp is assigned to that job. And 
does the same until all imps are depleted.

I think what would be best here is a way to determine whether a job is 
"dangerous" or "safe". Then Imp would be able to skip dangerous jobs until 
these are only ones left.
But this would be quite complex new code...

Original comment by mefistotelis on 22 Mar 2015 at 9:49

GoogleCodeExporter commented 9 years ago
And it is very difficult to tell if a job is safe or not; Claim rival ground, 
pickup corpses and prisoners are jobs were imps likely die yes,...

But when a library is build right up against the gems or between gold/gems and 
the nearest treasure room they will also die. When the gold they want to mine 
is being taken by a rival keeper they will die.  And when the keeper is under 
attack, almost all jobs are dangerous,... 

Imps will die, that is unavoidable. Right now though it means the entire 
economy of the CP collapses and it never really recovers.
Somehow the CP should focus more on getting the economy back on track, and keep 
a healthy number of imps mining.
• Having the CP build treasure rooms against gems(issue #204) and gold could 
make a difference there as the imps don’t have to travel as much(traveling is 
dangerous!).
• Making a computer process that has the CP pick up imps that take damage or 
are being attacked could save it a lot of gold
• Have the CP assign (new) imps to gems/gold when low on gold could help. 
Mining gold is a relative save job (especially when they don’t have to 
travel) and it keeps them away from the dangerous jobs.
• Build sufficient new imps when gems are available and have them start 
mining again.
• Having imps prefer mining (gems) over other jobs, always or just when low 
on gold, might still not be a bad idea.

Original comment by Loobinex on 22 Mar 2015 at 10:38

GoogleCodeExporter commented 9 years ago
Your solutions are far better than the threat detection idea; I will try to 
implement at least some of these.

The CP processes to pick up imps sound especially good, and shouldn't be hard 
to implement. Also the process which builds new imps could be improved quite 
easily.

Original comment by mefistotelis on 22 Mar 2015 at 10:53

GoogleCodeExporter commented 9 years ago
I just finished making a function which moves imps to dig gold/gems when 
treasury is low. 
I also updated selling traps and doors to be triggered only when there is 
anything to sell.

Please check whether its working, and whether it is enough to keep computer 
players treasury high.

Original comment by mefistotelis on 28 Mar 2015 at 11:43

GoogleCodeExporter commented 9 years ago
Unfortunately the answer to both questions is 'sometimes'. The compuchat is 
useful for testing this by the way.

I have seen the computer player do this when running low on gold. But load the 
attached save and observe the green keeper. He is broke, selling traps and 
doors, and has his remaining imp fortifying walls and not mining gold or gems. 
I believe in this scenario the imps should be assigned to mined and new imps 
should be created.

How effective it is when used also heavily depends on how far away the treasure 
room is, and how many faces of gem blocks are excavated.

Original comment by Loobinex on 29 Mar 2015 at 10:29

Attachments:

GoogleCodeExporter commented 9 years ago
With such plain repro, that was easy to fix.

Computer player wasn't able to move creatures when he had zero gold - that was 
the issue.

Please re-test tomorrow.

Original comment by mefistotelis on 29 Mar 2015 at 1:44

GoogleCodeExporter commented 9 years ago
Still doesn't work right. I just observed a multiplayer map where green lost 
most his imps and his gold, and he did drop some imps to mine, but he also 
picked up already mining imps to mine, imps on their way back to the treasure 
room.
And he also picked up imps mining to do other jobs.

All in all, he did not recover because he kept losing any new imps he build 
because there was a long way between the distand gold and his treasure room and 
that went through yellow rooms. The gems in his own dungeon were hardly used.

When critically low on gold they should be allowed to mine.

I think however that building treasure rooms around gems (so that all sides are 
excavated) and near gold so that the distance remains low has by far the 
biggest impact of the bunch.

Original comment by Loobinex on 30 Mar 2015 at 10:17

GoogleCodeExporter commented 9 years ago
Did a modification where creatures mining are not picked up to mine.
They can still be used for other jobs, this shouldn't be prevented IMO.

For other pints on your ideas list:
- Having the CP build treasure rooms against gems(issue #204) - it's still 
pending
- The computer can pick up imps fighting and put them back to heart, it has 
always been like this. But if an imp is escaping fight, this task is not used.
- Build sufficient new imps when gems are available - I'm planning to introduce 
a modification which increases computer players imp trasholds when there are 
gems selected for digging.

Btw, to increase imp tresholds in map script, use:
SET_COMPUTER_CHECKS(PLAYER1,"CHECK FOR ENOUGH 
IMPS",203,<max_amount>,<min_amount>,0,0)
<min_amount> - when comp. player has imps below this, he will prioritize 
getting imps back over everything else
<max_amount> - when comp. player has imps below this, he will build a new imp, 
if he has surplus of gold
The 203 is just an amount of turns between checks, it's best to leave that 
value.
Default values vary for different computer players, but usually are 16,9.

Original comment by mefistotelis on 4 Apr 2015 at 9:11

GoogleCodeExporter commented 9 years ago
Thanks for the scripting suggestion, I was thinking about defining more types 
of computer players to differ between low gold, plenty of gold and gem maps, 
but this is simpler.

- I tested and I have not been able to recognize the CP picking up mining imps 
to start mining again, so that indeed seems fixed. I do not know which imp 
tasks are more important to get assigned to imps when they are critically low 
on gold than mining, but perhaps it is better to at least allow for now as when 
the CP does not manage to ever recover from lack of gold he at least seems a 
bit alive.

- I know the CP picks up imps fighting other imps, still the CP is not the most 
skilled in keeping his imps alive, and imps are terribly expensive. They will 
spend up to 40k gold just in building imps. I'm not saying this is a problem 
area, but it is something that could help with gold issues. Detecting 'being 
attacked' or 'taking damage'(for example from poison gas) is something 
different from detecting fighting of course.

- An increase on min amount of imps can help a CP to recover from being broke, 
but I suggest waiting with this modification until after #204. Because right 
now often when they go broke with gems it is in losing imps (often returning 
mined gold) and more imps simply means losing a more expensive one, putting the 
CP in a bigger hole. Increase of max imps will mostly help in situations where 
the CP already has quite a bit of gold, but having lots of gold is a good thing.

Original comment by Loobinex on 5 Apr 2015 at 10:27