private void ListViewAvailable_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            CraftingActionContainer item = (sender as ListView)?.SelectedItem as CraftingActionContainer;

            if (item != null)
            {
                Sim.AddActions(true, item.Action);
            }
        }
 private void ConditionalSolvingWindow_FinishedConditionExecution(CraftingSimEx obj)
 {
     Sim.RemoveActions();
     for (int i = 0; i < obj.StepSettings.Length; i++)
     {
         Sim.StepSettings[i].RecipeCondition = obj.StepSettings[i].RecipeCondition;
     }
     Sim.AddActions(true, obj.GetCraftingActions());
 }
 private void Sim_PropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     if (e.PropertyName == "Level")
     {
         if (Sim.CurrentRecipe != null)
         {
             UpdateAvailableActions(Sim.CurrentRecipe);
             var actions = Sim.GetCraftingActions();
             Sim.RemoveActions();
             Sim.AddActions(true, actions);
         }
     }
 }
        private void ButtonChooseRotation_Click(object sender, RoutedEventArgs e)
        {
            if (Sim == null || Sim.CurrentRecipe == null)
            {
                return;
            }
            RotationsDatabaseWindow window = new RotationsDatabaseWindow();

            window.AddRotations(Sim.CurrentRecipe);
            if (window.ShowDialog() == true)
            {
                Sim.RemoveActions();
                Sim.AddActions(true, window.RotationInfo.Rotation.Array.Select(x => CraftingAction.CraftingActions[x]));
            }
        }
Пример #5
0
        private void SolveForCurrentActions(CraftingAction[] availableActions, CraftingAction[] actions)
        {
            Sim.RemoveActions();
            Sim.AddActions(true, actions);
            var currentActions = Sim.GetCraftingActions();

            if (currentActions.Length == actions.Length)
            {
                for (int i = 0; i < availableActions.Length; i++)
                {
                    var newActions = new CraftingAction[currentActions.Length + 1];
                    currentActions.CopyTo(newActions, 0);
                    newActions[newActions.Length - 1] = availableActions[i];
                    SolveForCurrentActions(availableActions, newActions);
                }
            }
        }
        private void SimulateConditions()
        {
            if (CheckBoxSimulateOnChanges.IsChecked != true)
            {
                return;
            }

            Sim.RemoveActions();

            foreach (var c in CraftingConditions)
            {
                c.ActionSettings.Reset();
            }

            bool shouldContinue = true;

            while (shouldContinue)
            {
                var f = CraftingConditions.Where(x => x.AreConditionsSatisfied(Sim)).ToArray();
                if (f.Length == 0 || Sim.CraftingActionsLength >= CraftingSimEx.MaxActions || Sim.CurrentDurability <= 0)
                {
                    shouldContinue = false;
                }
                else
                {
                    int simLength = Sim.CraftingActionsLength;
                    for (int i = 0; i < f.Length; i++)
                    {
                        Sim.AddActions(true, f[i].CraftingAction);
                        if (Sim.CraftingActionsLength > simLength)
                        {
                            f[i].ActionSettings.TimesUsed++;
                            break;
                        }
                        else if (i == f.Length - 1)
                        {
                            shouldContinue = false;
                        }
                    }
                }
            }
            FinishedConditionExecution(Sim);
        }
Пример #7
0
        public double Evaluate()
        {
            Sim.RemoveActions();
            UsableValues = Values.Where(x => x > 0).ToArray();
            try
            {
                var values = UsableValues.Select(y => CraftingAction.CraftingActions[y]).ToArray();
                Sim.AddActions(true, values);
            }
            catch (Exception e)
            {
                Debugger.Break();
            }

            Size         = Sim.CraftingActionsLength;
            UsableValues = UsableValues.Take(Size).ToArray();
            Hash         = GetHashCode();
            return(Sim.Score);
        }
Пример #8
0
        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]++;
            }
        }
Пример #9
0
        private void UpdateLoop()
        {
            //int currentTick = Environment.TickCount;
            //int stopAtTick = currentTick + CurrentTimeLimit;

            bool useTimeLimit      = CurrentTimeLimit > 0;
            bool useIterationLimit = CurrentIterationLimit > 0;

            while (Continue)
            {
                if (NeedsUpdate)
                {
                    Sim.RemoveActions();
                    Sim.AddActions(true, BestChromosome.Values.Where(y => y > 0).Select(x => CraftingAction.CraftingActions[x]));
                    NeedsUpdate = false;

                    if (CopyBestRotationToPopulations)
                    {
                        for (int i = 0; i < Populations.Length; i++)
                        {
                            Populations[i].PendingBest = BestChromosome.Clone();
                        }
                    }
                    CraftingSim sim = Sim.Clone(true);
                    Utils.AddRotationFromSim(sim);
                    FoundBetterRotation(sim);
                }

                if ((useIterationLimit && (Iterations >= CurrentIterationLimit)))
                {
                    Continue = false;
                }
            }

            Stopped();
        }
Пример #10
0
        private void GInitialized()
        {
            if (File.Exists("Settings.db"))
            {
                DataStreamEx s        = new DataStreamEx(File.ReadAllBytes("Settings.db"));
                int          recipeId = s.ReadInt();

                Sim.Level             = s.ReadInt();
                Sim.BaseCraftsmanship = s.ReadInt();
                Sim.BaseControl       = s.ReadInt();
                Sim.BaseMaxCP         = s.ReadInt();

                Dispatcher.Invoke(() =>
                {
                    CheckBoxIsSpecialist.IsChecked = s.ReadByte() == 1;
                });

                int id = s.ReadInt();
                if (id > 0)
                {
                    SelectedFood = G.Items[id];
                    FoodIsHQ     = s.ReadByte() == 1;
                }
                id = s.ReadInt();
                if (id > 0)
                {
                    SelectedTea = G.Items[id];
                    TeaIsHQ     = s.ReadByte() == 1;
                }
                Dispatcher.Invoke(() =>
                {
                    ApplyFoodBuffs();
                });
                List <CraftingAction> actions = new List <CraftingAction>();
                while (s.Position < s.Length)
                {
                    try
                    {
                        actions.Add(CraftingAction.CraftingActions[s.ReadInt()]);
                    }
                    catch { }
                }

                if (recipeId > 0)
                {
                    LoadRecipe(G.Recipes.FirstOrDefault(x => x.Id == recipeId));
                }

                Sim.AddActions(true, actions);
                s.Flush();
                s.Close();
            }

            if (Solver == null)
            {
                Solver = new GASolver(Sim);
                Solver.GenerationRan       += Solver_GenerationRan;
                Solver.FoundBetterRotation += Solver_FoundBetterRotation;
                Solver.Stopped             += Solver_Stopped;
            }
        }