-
Notifications
You must be signed in to change notification settings - Fork 29
Add settler tile adjustments to Civilization class #539
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bmgxyz
wants to merge
12
commits into
C7-Game:Development
Choose a base branch
from
bmgxyz:0092-settler-ai-weights
base: Development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f6e3954
Add settler tile adjustments to Civilization class
bmgxyz 39b4a08
Revert linting changes
bmgxyz 65f97f9
Merge branch 'Development' into 0092-settler-ai-weights
bmgxyz 4856580
Fix a few issues that I created during the merge
bmgxyz f67f36a
Fix tests by altering serialization and updating test saves
bmgxyz a014cd0
Remove lingering linter config comments, tweak imports, and re-add a …
bmgxyz c699f20
Copy over the intended comment, mark as TODO, and link #802 in origin…
bmgxyz 1b59341
Rename SettlerLocationAi back to SettlerLocationAI
bmgxyz 57d7d9e
Add SettlerLocationTest.cs
bmgxyz 85f85eb
Move MakeTestPlayer and SurroundTile into MapBase
bmgxyz 9834021
Move SettlerLocationTest locations so they aren't on top of each other
bmgxyz 527e9d8
Remove redundant distance penalty in SettlerLocationAI
bmgxyz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| using C7Engine; | ||
| using C7GameData; | ||
| using C7GameData.AIData; | ||
| using C7GameData.Save; | ||
| using EngineTests.Utils; | ||
| using System.Collections.Generic; | ||
| using Xunit; | ||
|
|
||
| namespace EngineTests.AI.UnitAI { | ||
| public sealed class SettlerLocationAITests : MapBase { | ||
| private Tile MakeDesertTileWithDefaultYield() { | ||
| Tile tile = MakeDesertTile(); | ||
| tile.overlayTerrainType.baseFoodProduction = 0; | ||
| tile.overlayTerrainType.baseShieldProduction = 1; | ||
| tile.overlayTerrainType.baseCommerceProduction = 0; | ||
| return tile; | ||
| } | ||
| private Tile MakeFloodPlainTileWithDefaultYield() { | ||
| Tile tile = MakeFloodPlainTile(); | ||
| tile.overlayTerrainType.baseFoodProduction = 3; | ||
| tile.overlayTerrainType.baseShieldProduction = 0; | ||
| tile.overlayTerrainType.baseCommerceProduction = 0; | ||
| return tile; | ||
| } | ||
|
|
||
| [Fact] | ||
| private void HillsOverPlains() { | ||
bmgxyz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // a single hill tile surrounded by desert | ||
| InitilizeStartTile(MakeHillTile(), new TileLocation(56, 50)); | ||
| Tile hills = startTile; | ||
| List<Tile> map = SurroundTile(hills, MakeDesertTile); | ||
|
|
||
| // a single plains tile surrounded by desert | ||
| InitilizeStartTile(MakePlainsTile(), new TileLocation(44, 50)); | ||
| Tile plains = startTile; | ||
| map.AddRange(SurroundTile(plains, MakeDesertTile)); | ||
|
|
||
| // starting position at the midpoint between the two viable candidates | ||
| InitilizeStartTile(MakeDesertTile(), new TileLocation(50, 50)); | ||
| Tile start = startTile; | ||
| startTile.map = gameMap; | ||
|
|
||
| // settler should choose the hill | ||
| Player player = MakeTestPlayer(map); | ||
| Tile chosenTile = SettlerLocationAI.FindSettlerLocation(start, player); | ||
| Assert.Equal(hills, chosenTile); | ||
| } | ||
| [Fact] | ||
| private void CoastalHillsOverInlandHills() { | ||
| List<Tile> map = new(); | ||
|
|
||
| // a hill tile with a coast tile neighbor | ||
| InitilizeStartTile(MakeHillTile(), new TileLocation(56, 50)); | ||
| Tile coastalHills = startTile; | ||
| map.Add(coastalHills); | ||
| map.Add(AddNeighborsAndUpdateMap(coastalHills, MakeCoastTile(), TileDirection.NORTH)); | ||
| map.Add(AddNeighborsAndUpdateMap(coastalHills, MakeDesertTile(), TileDirection.NORTHEAST)); | ||
| map.Add(AddNeighborsAndUpdateMap(coastalHills, MakeDesertTile(), TileDirection.EAST)); | ||
| map.Add(AddNeighborsAndUpdateMap(coastalHills, MakeDesertTile(), TileDirection.SOUTHEAST)); | ||
| map.Add(AddNeighborsAndUpdateMap(coastalHills, MakeDesertTile(), TileDirection.SOUTH)); | ||
| map.Add(AddNeighborsAndUpdateMap(coastalHills, MakeDesertTile(), TileDirection.SOUTHWEST)); | ||
| map.Add(AddNeighborsAndUpdateMap(coastalHills, MakeDesertTile(), TileDirection.WEST)); | ||
| map.Add(AddNeighborsAndUpdateMap(coastalHills, MakeDesertTile(), TileDirection.NORTHWEST)); | ||
|
|
||
| // a hill surrounded by desert | ||
| InitilizeStartTile(MakeHillTile(), new TileLocation(44, 50)); | ||
| Tile inlandHills = startTile; | ||
| map.AddRange(SurroundTile(inlandHills, MakeDesertTile)); | ||
|
|
||
| // starting position at the midpoint between the two viable candidates | ||
| InitilizeStartTile(MakeDesertTile(), new TileLocation(50, 50)); | ||
| Tile start = startTile; | ||
| startTile.map = gameMap; | ||
|
|
||
| // settler should choose the coastal hill even when starting on the inland one a few tiles away | ||
| Player player = MakeTestPlayer(map); | ||
| Tile chosenTile = SettlerLocationAI.FindSettlerLocation(start, player); | ||
| Assert.Equal(coastalHills, chosenTile); | ||
| } | ||
| [Fact] | ||
| private void CloseOverFar() { | ||
| List<Tile> map = new(); | ||
|
|
||
| // a single plains tile surrounded by desert | ||
| // not a good settlement spot, but our settler is already on this tile | ||
| InitilizeStartTile(MakePlainsTile(), new TileLocation(50, 50)); | ||
| Tile close = startTile; | ||
| map.AddRange(SurroundTile(close, MakeDesertTileWithDefaultYield)); | ||
|
|
||
| // a hill tile surrounded by flood plains | ||
| // high settlement score from yield but very far away | ||
| InitilizeStartTile(MakeHillTile(), new TileLocation(200, 50)); | ||
| Tile far = startTile; | ||
| map.AddRange(SurroundTile(far, MakeFloodPlainTileWithDefaultYield)); | ||
|
|
||
| Player player = MakeTestPlayer(map); | ||
| Tile chosenTile = SettlerLocationAI.FindSettlerLocation(close, player); | ||
| Assert.Equal(close, chosenTile); | ||
| } | ||
| [Fact] | ||
| private void NotAlreadyBeingSettled() { | ||
| // just one hill tile | ||
| InitilizeStartTile(MakeHillTile(), new TileLocation(50, 50)); | ||
| startTile.map = gameMap; | ||
|
|
||
| List<Tile> map = new(); | ||
| map.Add(startTile); | ||
| Player player = MakeTestPlayer(map); | ||
|
|
||
| // with no other settlers in play, our test settler chooses the only available tile | ||
| Tile chosenTile = SettlerLocationAI.FindSettlerLocation(startTile, player); | ||
| Assert.Equal(startTile, chosenTile); | ||
|
|
||
| // add a settler whose destination is the one known tile | ||
| MapUnit settler = MakeLandUnit(); | ||
| settler.unitType.name = "Settler"; | ||
| SettlerAIData data = new(); | ||
| data.destination = startTile; | ||
| settler.currentAI = new SettlerAI(data); | ||
| player.units.Add(settler); | ||
|
|
||
| // now the test settler should have nowhere to go | ||
| chosenTile = SettlerLocationAI.FindSettlerLocation(startTile, player); | ||
| Assert.Equal(Tile.NONE, chosenTile); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.