public Chromosome(CraftingSim sim, ushort[] availableValues, int valueCount, ushort[] values) { Sim = sim.Clone(); AvailableValues = availableValues; Values = new ushort[valueCount]; values.CopyTo(Values, 0); Fitness = Evaluate(); }
public Chromosome(CraftingSim sim, ushort[] availableValues, int valueCount) { Sim = sim.Clone(); AvailableValues = availableValues; Values = new ushort[valueCount]; for (int i = 0; i < Values.Length; i++) { Values[i] = AvailableValues.GetRandom(); } Fitness = Evaluate(); }
public void Solve(CraftingSim sim) { Sim = sim.Clone(); MaxProgress = Sim.CurrentRecipe.MaxProgress; MaxQuality = Sim.CurrentRecipe.MaxQuality; var a = C.CraftingActions.Values.Where(x => x.IncreasesQuality).ToList(); a.Add(C.InnerQuiet); a.Add(C.WasteNot); a.Add(C.WasteNotII); a.Add(C.GreatStrides); a.Add(C.Manipulation); a.Add(C.MastersMend); a.Add(C.Observe); Sim.RemoveActions(); //Sim.AddActions(C.Reflect); ushort[] actions = new ushort[4]; for (int i = 0; i < 4; i++) { actions[i] = 0; } Dictionary <ExtendedArray <ushort>, int> QValues = new Dictionary <ExtendedArray <ushort>, int>(); PossibleCraftingAction pAction = new PossibleCraftingAction(a.Select(x => x.Id)); while (true) { Sim.RemoveActions(); Sim.AddActions(true, actions.Select(x => C.CraftingActions[x])); QValues[Sim.GetCraftingActions().Select(x => x.Id).ToArray()] = Sim.CurrentQuality; int index = 0; while (a[index] == a.Last()) { actions[index] = a[0].Id; index++; } actions[index]++; } }
public RotationStats GetStats(CraftingSim sim) { CraftingSim copy = sim.Clone(); sim.CopyTo(copy, true); int progress = sim.CurrentProgress; int quality = sim.CurrentQuality; int cp = sim.CurrentCP; int durability = sim.CurrentDurability; var actions = sim.GetCraftingActions().ToList(); actions.AddRange(Rotation.Array.Select(x => CraftingAction.CraftingActions[x])); copy.AddActions(true, actions); return(new RotationStats( Rotation.Array.Length, copy.CurrentProgress - progress, copy.CurrentQuality - quality, cp - copy.CurrentCP, durability - copy.CurrentDurability )); }
public static RecipeSolutionInfo FromSim(CraftingSim sim, bool findMinLevel) { if (sim == null || sim.CurrentProgress < sim.CurrentRecipe.MaxProgress || sim.CurrentQuality < sim.CurrentRecipe.MaxQuality) { return(null); } RecipeSolutionInfo result = new RecipeSolutionInfo(); CraftingSim s = sim.Clone(); var actions = sim.GetCraftingActions(); s.AddActions(true, actions); result.CP = s.MaxCP - s.CurrentCP; result.Rotation = actions.Select(x => (ushort)x.Id).ToArray(); s.Level = s.CurrentRecipe.ClassJobLevel; s.Level = sim.Level; if (findMinLevel) { int minLevelFromActionsLevel = actions.Max(x => x.Level); int minLevelFromSuccess = s.Level; bool craftFailed = false; while (!craftFailed) { s.RemoveActions(); minLevelFromSuccess--; s.Level = minLevelFromSuccess; s.AddActions(true, actions); craftFailed = s.CurrentProgress < s.CurrentRecipe.MaxProgress || s.CurrentQuality < s.CurrentRecipe.MaxQuality; } minLevelFromSuccess++; result.MinLevel = Math.Max(Math.Max(minLevelFromSuccess, minLevelFromActionsLevel), s.CurrentRecipe.ClassJobLevel); } else { result.MinLevel = sim.Level; } s.Level = result.MinLevel; int recipeProgress = s.CurrentRecipe.MaxProgress; int recipeQuality = s.CurrentRecipe.MaxQuality; int oldCraftsmanshipBuff = s.CraftsmanshipBuff; int oldControlBuff = s.ControlBuff; while (s.CurrentProgress > recipeProgress) { s.CraftsmanshipBuff--; s.ExecuteActions(); } s.CraftsmanshipBuff++; s.RemoveActions(); s.AddActions(true, actions); result.MinCraftsmanship = Math.Max(s.Craftsmanship, sim.CurrentRecipe.RequiredCraftsmanship); while (s.CurrentQuality > recipeQuality) { s.ControlBuff--; s.ExecuteActions(); } result.MinControl = Math.Max(s.Control + 1, sim.CurrentRecipe.RequiredControl); s.CraftsmanshipBuff = oldCraftsmanshipBuff; s.ControlBuff = oldControlBuff; int oldActionsLength = actions.Length; int newActionsLength = oldActionsLength; s.RemoveActions(); s.AddActions(true, actions); while (newActionsLength >= oldActionsLength) { s.CraftsmanshipBuff++; s.ExecuteActions(); newActionsLength = s.CraftingActionsLength; if (s.Craftsmanship > 10000) { break; } } result.MaxCraftsmanship = s.Craftsmanship - 1; return(result); }