Skip to content

Conversation

SomeTroglodyte
Copy link
Collaborator

@SomeTroglodyte SomeTroglodyte commented Jun 28, 2023

Commit messages tell a lot.

  • The "Add a chance" one is half of the point of this. It's minimal as it only tries the water AI when land AI reached a medium level fail. Affects only the "workboats" unique.
  • The second "half" just removes blockers that kept findTileToWork from working on water when a Worker has "Can build [Water] improvements on tiles" - later commit.

What would really help would be a fuzzy logic so improve land could return a best "quality" and create by sacrifice on water could do the same, both are compared the better ones win. Better result for more CPU. Concept could be extended to large parts of automation...

UNTESTED so far

Tests were done, by issue OP as well. See below. Looks like sizable improvement for little work (and little risk for G&K players).

@SeventhM
Copy link
Collaborator

Hmm... something tells me eventually we may need to deprecate the workboat unique. Oh well, for now we can work around it I guess

Heads up: I don't remember if Can build [Water] improvements on tiles functions correctly (I think I remember testing it in the past and it not working, but I could be wrong), but I do I know that if you have water improvement with a turnsToBuild, you can actually use that unique just fine. Perhaps try removing the checks for if the tile is land in tileCanBeImproved

@SomeTroglodyte
Copy link
Collaborator Author

Heads up: I don't remember if Can build [Water] improvements on tiles functions correctly (I think I remember testing it in the past and it not working, but I could be wrong), but I do I know that if you have water improvement with a turnsToBuild, you can actually use that unique just fine.

Hidden contradiction? That Unique is only supposed to support improvements with a turnsToBuild, so the "not working" in the first half sounds more like "misunderstood".

But yes, that "half" of the task, I've only looked for blockers and saw none, not in findTileToWork or upstream from it. tileCanBeImproved could well be the site I didn't yet check - because at some point you want the game to debug to see what's really happening...

@SomeTroglodyte
Copy link
Collaborator Author

... Also raises the question what would happen if some mod had a carthage-style "can climb mountains" plus an improv buildable on Mountains - which does work fine for a human plr - just need to swap often or have enough acceleration and medic effects so a Worker can survive it - Good AI use of such a thing yould get tricky... Remove another early exit from tileCanBeImproved, yes, but that can't be enough. Or is that situation already the case with G&K Carthage and roads? Can't remember if I had to change the terrain to test that.

@SomeTroglodyte
Copy link
Collaborator Author

Wait - isn't AF's Derrick already such an improvement? Any my simulation had a Derrick on Coast - how can that be with that if (!tile.isLand) return false???

@SomeTroglodyte
Copy link
Collaborator Author

SomeTroglodyte commented Jun 29, 2023

Latest commit deals with a few blockers - @SeventhM 's observation and one more - and I've so far seen them go for it up to WorkerAutomation L253 "startWorkingOnImprovement". Using the save here by @hackedpassword , an excerpt of debugger notes:

Worker currentTile Tile @(-4.0,0.0), Batou-Cho, Grassland, Hill, {3} {Promethine}, City center, Worker - Daikyu Boei Kikan, Drop Trooper - Daikyu Boei Kikan tilesToAvoid.size = 312 filter up to getPriority -> 4 candidates workableTilesCenterFirst -> 1 candidate selects Tile @(-4.0,-1.0), Coast, Algae, Drop Trooper - Daikyu Boei Kikan Worker currentTile Tile @(-8.0,-4.0), Niihama New Port City, Mycelium, City center, Worker - Daikyu Boei Kikan tilesToAvoid.size = 0 filter up to getPriority -> 40 candidates workableTilesCenterFirst -> 37 candidates selects Tile Tile @(-8.0,-5.0), Coast, {42} {Promethine} Place 2 of workableTilesPrioritized after Tile @(-9.0,-5.0), Plains, Hill, {42} {Titanium}, Railroad, Mine unit.movement.canReach(it) == true tileCanBeImproved(unit, workableTilesPrioritized.first()) == false Worker currentTile Tile @(-5.0,5.0), Coast, Plankton, Worker - Badwalmusafir, Hovertank - Badwalmusafir tilesToAvoid.size = 47 filter up to getPriority -> 26 candidates workableTilesCenterFirst -> 13 candidates selects #2 Tile @(-5.0,8.0), Coast, Ice-10 after #1 Tile @(-2.0,8.0), Grassland, {42} {Ulframite}, Mine

A size difference between "filter up to getPriority" and "workableTilesCenterFirst" means the danger avoidance level 2 works, tilesToAvoid.size varying and showing > 0 means danger avoidance level 1 works - which is upstream from the code I touchend and which I haven't analyzed. Could well be that they could be unified. The first two show the old code has parked a few in cities, which now embark to get to a resource. Last one did reach the "Ice-10" tile soon after and started the improvement.

Sounds like a good return for a few minor strategic incisions.

One open question - the first !isLand in tileCanBeImproved shoudn't always shunt out, but I didn't want to discard the optimization entirely, so I checked the close-but-not-quite cached unique instead. Cheap and fast but imperfect. Drop the line, leave it as is, or add another cached flag, with a slightly more complex formula than just hasUnique...?

@SomeTroglodyte SomeTroglodyte marked this pull request as ready for review June 29, 2023 19:16
@hackedpassword
Copy link
Contributor

hackedpassword commented Jun 30, 2023

... Also raises the question what would happen if some mod had a carthage-style "can climb mountains"

Was reading through and this caught my attention. Mod {the great unciv rework} has 2 natural wonders granting climber abilities. My in-development map takes advantage of these mountains as designed gameplay. fyi

@SomeTroglodyte
Copy link
Collaborator Author

Mod {the great unciv rework} has 2 natural wonders granting climber abilities.

I should rename the PR to "Minimal AI support" in case that wasn't clear enough. Your or any Mod's changes to Mountains- if they test out fine by a human player that is only one side of the coin. Whether the AI can make effective use of such changes is relatively independent. But, agreed - making Mountains less boring is an attractive modding target. There's probably quite some opportunities to code more support into Unciv - is there control over the damage? Control that can depend on unique conditionals? Just one example. I have no clear picture, so I'll pretty much zone out. This PR exists because a specific issue triggered my curiosity and I saw an opportunity that -maybe- relatively little code might help.

@yairm210 yairm210 merged commit 6a6a8a0 into yairm210:master Jul 5, 2023
@SomeTroglodyte SomeTroglodyte deleted the WaterWorkers branch July 6, 2023 07:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: Allow AI workers in mods like Alpha Frontier to get both land and water resources
4 participants