Skip to content

Commit

Permalink
Added override priorities
Browse files Browse the repository at this point in the history
Misspelling


Updated readme docs to include information about the override system


Typo fix
  • Loading branch information
Drise13 committed Jul 19, 2022
1 parent 297fbe2 commit 631f7c9
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 6 deletions.
2 changes: 2 additions & 0 deletions PetsOptimizer/JsonParser/BreedingData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class BreedingData

[JsonIgnore] public IEnumerable<Pet> ShuffledPets => Pets.Shuffle();

[JsonIgnore] public List<bool>? Overrides { get; set; }

public override string ToString()
{
return JsonConvert.SerializeObject(this, Formatting.Indented, new StringEnumConverter());
Expand Down
38 changes: 37 additions & 1 deletion PetsOptimizer/Options.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
namespace PetsOptimizer;

using System.Text.RegularExpressions;

using CommandLine;

public class Options
Expand All @@ -17,4 +19,38 @@ public class Options
public string FilePath { get; set; } =
Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "IdleonSaver",
"idleon_save.json");
};

[Option('o', "override", Required = false, HelpText = "A comma separated list (starting with 1) of territories to prioritize", Default = null)]
public string OverriddenPriorities { get; set; }

private List<bool>? priorities;

/// <summary>
/// A list of overriden priorities from the user. If they want to prioritize the 5th territory, they would input 5.
/// If they want to prioritize multiple territories, they provide for example "1,2,3,4".
/// </summary>
public List<bool>? Priorities
{
get
{
if (priorities != null)
{
return priorities;
}

if (!string.IsNullOrWhiteSpace(OverriddenPriorities))
{
if (Regex.IsMatch(OverriddenPriorities, @"[\d,]*"))
{
var entries = OverriddenPriorities.Split(',', StringSplitOptions.RemoveEmptyEntries).Distinct().ToList();

return priorities ??= Enumerable.Range(1, 18).Select(i => entries.Contains(i.ToString())).ToList();
}

throw new Exception("Expected an override list in comma separated format eg. 1,2,3,4");
}

return null;
}
}
}
18 changes: 14 additions & 4 deletions PetsOptimizer/Population.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,21 @@ public double GetTotalScore()

double sum = 0;

for (var i = 0; i < Territories.Count; ++i)
// If the user wants to call out specific territories to prioritize,
// then multiply priority scores by 1.5 and others by 0.5
if (BreedingData.Overrides?.Count > 0)
{
var territory = Territories[i];

sum += territory.GetTotalForagePower() * (1 + i * 0.1);
for (var i = 0; i < Territories.Count; ++i)
{
sum += Territories[i].GetTotalForagePower() * (BreedingData.Overrides[i] ? 1.5 : 0.5);
}
}
else
{
for (var i = 0; i < Territories.Count; ++i)
{
sum += Territories[i].GetTotalForagePower() * (1 + i * 0.1);
}
}

return sum;
Expand Down
2 changes: 2 additions & 0 deletions PetsOptimizer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

var data = JsonConvert.DeserializeObject<BreedingData>(jsonDataString);

data.Overrides = parsedArgs.Value.Priorities;

IEnumerable<Population> CreatePopulations(int populationCount)
{
return Enumerable.Range(0, populationCount).Select(_ => new Population(data));
Expand Down
36 changes: 35 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,40 @@ How many iterations run the algorithm. In my testing, I generally found I had co

How many pet arrays to test each iteration. The more pet arrays, generally the better, but it comes with an increased time per iteration. 5000 is probably on the excessive side, but gives a decent variety for the algorithm to work with. I found that with 5000 pet arrays, I had an average iteration time of 25ms.

## Territory priority override: `o[verride]`

### Default Value: `Not set`

A user provided list of one or more territories to prioritize during optimization score calculations.

To prioritize the 5th territory, input `5`.
To prioritize multiple territories, input for example `1,2,3,4`.
The territories can be referenced below:

```
('Grasslands', 1)
('Jungle', 2)
('Encroaching Forest', 3)
('Tree Interior', 4)
('Stinky Sewers', 5)
('Desert Oasis', 6)
('Beach Docks', 7)
('Coarse Mountains', 8)
('Twilight Desert', 9)
('The Crypt', 10)
('Frosty Peaks', 11)
('Tundra Outback', 12)
('Crystal Caverns', 13)
('Pristalle Lake', 14)
('Nebulon Mantle', 15)
('Starfield Skies', 16)
('Shores of Eternity', 17)
```

This list is one based, so to prioritize the first territory (`Grasslands`), use `1`, etc.

If set, score calculations are adjusted from positionally prioritizing the later territories incrementally to applying a blanket `1.5` or `0.5` based on priority or not, respectively.

# How it works

A genetic algorithm is based off the principle of natural selection. The algorithm works as follows.
Expand All @@ -59,4 +93,4 @@ There is also a mechanism to run the algorithm several times and choose the best

# Results

Results are written to the execution directory, so if you run the application in `C:/My/Special/Folders/` it will output `best-result.txt` in that folder. It prints each territory with each pet in the specific position (top down equals left to right in-game). Pet positions within a territory are important since there are above / below interactions to keep in mind. It also prints the expected territory forage power, this should match what you see in game, at least until Lava add some gem-based boost modifiers like he has with Flaggy Rate in Construction. If the rate doesn't match (with adjustments for rounding), open an issue with you JSON save file and I can take a look when I have time.
Results are written to the execution directory, so if you run the application in `C:/My/Special/Folders/` it will output `best-result.txt` in that folder. It prints each territory with each pet in the specific position (top down equals left to right in-game). Pet positions within a territory are important since there are above / below interactions to keep in mind. It also prints the expected territory forage power, this should match what you see in game, at least until Lava add some gem-based boost modifiers like he has with Flaggy Rate in Construction. If the rate doesn't match (with adjustments for rounding), open an issue with your JSON save file and I can take a look when I have time.

0 comments on commit 631f7c9

Please sign in to comment.