Esempio n. 1
0
        private void AdvancePlayback()
        {
            Simulator.Engine.Ability optimalAction = analyzer.OptimalAction(currentState);

            RadioParams selectedParams  = (RadioParams)selectedRadio.Tag;
            string      statusString    = (selectedParams.success) ? "Success" : "Failure";
            string      conditionString = selectedParams.condition.ConditionString();

            currentState           = optimalAction.Activate(currentState, selectedParams.success);
            currentState.Condition = selectedParams.condition;

            if (currentState.Status == SynthesisStatus.IN_PROGRESS)
            {
                if (!analyzer.TryGetOptimalAction(currentState, out optimalAction))
                {
                    // We hit a leaf.  Kick off a new analysis.
                    SetAppState(AppState.Analyzing);
                    worker.RunWorkerAsync(currentState);
                }
                else
                {
                    UpdateUIStateForPlayback(currentState, optimalAction);
                }
            }
            else
            {
                UpdateUIStateForPlayback(currentState, null);
            }
        }
Esempio n. 2
0
        public void EnsureMastersMendAtEndOfMultiStageSynth()
        {
            // By using a 4 step max analysis depth, we can check that after 3 steps, if the
            // 4th step would end the synth, a Master's Mend can be used to regain durability.
            Analyzer analyzer = new Analyzer();

            analyzer.Actions.AddAction(new BasicSynthesis());
            analyzer.Actions.AddAction(new BasicTouch());
            analyzer.Actions.AddAction(new MastersMend());
            analyzer.Actions.AddAction(new SteadyHand());
            analyzer.Actions.AddAction(new Observe());
            analyzer.Actions.AddAction(new Manipulation());
            analyzer.Actions.AddAction(new TricksOfTheTrade());
            analyzer.Actions.AddAction(new StandardTouch());

            State initialState = new State();

            initialState.Condition     = Condition.Normal;
            initialState.Control       = 115;
            initialState.Craftsmanship = 123;
            initialState.CP            = 251;
            initialState.MaxCP         = 251;
            initialState.MaxDurability = 40;
            initialState.Durability    = 40;
            initialState.MaxProgress   = 74;
            initialState.Quality       = 0;
            initialState.MaxQuality    = 1053;
            initialState.SynthLevel    = 20;
            initialState.CrafterLevel  = 18;

            analyzer.MaxAnalysisDepth = 4;

            analyzer.Run(initialState);

            BasicSynthesis basic = new BasicSynthesis();

            initialState = basic.Activate(initialState, true);
            initialState = basic.Activate(initialState, true);
            initialState = basic.Activate(initialState, true);

            Simulator.Engine.Ability bestAction = analyzer.OptimalAction(initialState);
            Assert.AreEqual <Type>(typeof(MastersMend), bestAction.GetType());
        }
Esempio n. 3
0
        private void AbilityCheck_CheckChanged(object sender, RoutedEventArgs e)
        {
            CheckBox check = (CheckBox)sender;

            if (check.Tag != null)
            {
                Simulator.Engine.Ability action = (Simulator.Engine.Ability)check.Tag;
                if (action != null)
                {
                    if (check.IsChecked.Value)
                    {
                        analyzer.Actions.AddAction(action);
                    }
                    else
                    {
                        analyzer.Actions.RemoveAction(action.GetType());
                    }
                }
            }
        }
Esempio n. 4
0
        public void TestUrgentCompletion2()
        {
            Analyzer       analyzer = new Analyzer();
            BasicSynthesis bs       = new BasicSynthesis();
            SteadyHand     sh       = new SteadyHand();

            analyzer.Actions.AddAction(bs);
            //analyzer.Actions.AddAction(new BasicTouch());
            //analyzer.Actions.AddAction(new MastersMend());
            analyzer.Actions.AddAction(sh);
            //analyzer.Actions.AddAction(new Observe());

            State state = Utility.CreateDefaultState();

            // Make sure we don't have enough CP to run Master's Mend.
            state.CP         = Compute.CP(SynthAction <SynthActionAttribute, MastersMend> .Attributes.CP, state) - 1;
            state.Durability = 20;

            // Make sure exactly 2 Basic Synthesis' are required to finish the synth.
            state.Progress    = 0;
            state.MaxProgress = 2 * Compute.Progress(state, bs.BaseEfficiency);

            analyzer.Run(state);

            // The best sequence is Steady Hand -> Basic Synthesis -> Basic Synthesis
            Simulator.Engine.Ability bestAction = analyzer.OptimalAction(state);
            Assert.AreEqual <Type>(typeof(SteadyHand), bestAction.GetType());

            state      = sh.Activate(state, true);
            bestAction = analyzer.OptimalAction(state);
            Assert.AreEqual <Type>(typeof(BasicSynthesis), bestAction.GetType());

            state      = bs.Activate(state, true);
            bestAction = analyzer.OptimalAction(state);
            Assert.AreEqual <Type>(typeof(BasicSynthesis), bestAction.GetType());

            state = bs.Activate(state, true);
            Assert.AreEqual(SynthesisStatus.COMPLETED, state.Status);
        }
Esempio n. 5
0
        public void EnsureMastersMendAtEndOfSingleStageSynth()
        {
            Analyzer analyzer = new Analyzer();

            analyzer.Actions.AddAction(new BasicSynthesis());
            analyzer.Actions.AddAction(new BasicTouch());
            analyzer.Actions.AddAction(new MastersMend());
            analyzer.Actions.AddAction(new SteadyHand());
            analyzer.Actions.AddAction(new Observe());
            analyzer.Actions.AddAction(new Manipulation());
            analyzer.Actions.AddAction(new TricksOfTheTrade());
            analyzer.Actions.AddAction(new StandardTouch());

            State initialState = new State();

            initialState.Condition     = Condition.Normal;
            initialState.Control       = 115;
            initialState.Craftsmanship = 123;
            initialState.CP            = 251;
            initialState.MaxCP         = 251;
            initialState.MaxDurability = 70;
            initialState.Durability    = 10;
            initialState.Progress      = 73;
            initialState.MaxProgress   = 74;
            initialState.Quality       = 0;
            initialState.MaxQuality    = 1053;
            initialState.SynthLevel    = 20;
            initialState.CrafterLevel  = 18;

            analyzer.MaxAnalysisDepth = 1;

            analyzer.Run(initialState);

            Simulator.Engine.Ability bestAction = analyzer.OptimalAction(initialState);
            Assert.AreEqual <Type>(typeof(MastersMend), bestAction.GetType());
        }
Esempio n. 6
0
        private void SetAppState(AppState newState)
        {
            if (appState == newState)
            {
                return;
            }

            switch (newState)
            {
            case AppState.Idle:
                btnAccept.Content   = "Solve!";
                btnAccept.IsEnabled = true;
                btnCancel.Content   = "Exit";
                btnCancel.IsEnabled = true;

                // Re-enable parameter entry.
                txtInitialQuality.IsEnabled   = true;
                txtCraftsmanship.IsEnabled    = true;
                txtCrafterLevel.IsEnabled     = true;
                txtCP.IsEnabled               = true;
                txtControl.IsEnabled          = true;
                txtAnalysisDepth.IsEnabled    = true;
                txtRecipeDifficulty.IsEnabled = true;
                txtRecipeDurability.IsEnabled = true;
                txtRecipeLevel.IsEnabled      = true;
                txtRecipeQuality.IsEnabled    = true;
                comboBoxCraft.IsEnabled       = false;
                comboBoxRecipe.IsEnabled      = false;

                // Disable random outcome entry.
                radioFailureExcellent.IsEnabled = false;
                radioFailureGood.IsEnabled      = false;
                radioFailureNormal.IsEnabled    = false;
                radioFailurePoor.IsEnabled      = false;
                radioSuccessExcellent.IsEnabled = false;
                radioSuccessGood.IsEnabled      = false;
                radioSuccessNormal.IsEnabled    = false;
                radioSuccessPoor.IsEnabled      = false;
                break;

            case AppState.Analyzing:
                btnAccept.Content   = "Analyzing...";
                btnAccept.IsEnabled = false;
                btnCancel.Content   = "Cancel Analysis";
                btnCancel.IsEnabled = true;

                // Disable parameter entry.
                txtInitialQuality.IsEnabled   = false;
                txtCraftsmanship.IsEnabled    = false;
                txtCrafterLevel.IsEnabled     = false;
                txtCP.IsEnabled               = false;
                txtControl.IsEnabled          = false;
                txtAnalysisDepth.IsEnabled    = false;
                comboBoxCraft.IsEnabled       = false;
                comboBoxRecipe.IsEnabled      = false;
                txtRecipeDifficulty.IsEnabled = false;
                txtRecipeDurability.IsEnabled = false;
                txtRecipeLevel.IsEnabled      = false;
                txtRecipeQuality.IsEnabled    = false;

                // Disable random outcome entry.
                radioFailureExcellent.IsEnabled = false;
                radioFailureGood.IsEnabled      = false;
                radioFailureNormal.IsEnabled    = false;
                radioFailurePoor.IsEnabled      = false;
                radioSuccessExcellent.IsEnabled = false;
                radioSuccessGood.IsEnabled      = false;
                radioSuccessNormal.IsEnabled    = false;
                radioSuccessPoor.IsEnabled      = false;
                break;

            case AppState.Playback:
                btnAccept.IsEnabled = false;
                btnAccept.Content   = "Playing Back";
                btnCancel.Content   = "Cancel Playback";
                btnCancel.IsEnabled = true;

                // Disable parameter entry.
                txtInitialQuality.IsEnabled   = false;
                txtCraftsmanship.IsEnabled    = false;
                txtCrafterLevel.IsEnabled     = false;
                txtCP.IsEnabled               = false;
                txtControl.IsEnabled          = false;
                txtAnalysisDepth.IsEnabled    = false;
                comboBoxCraft.IsEnabled       = false;
                comboBoxRecipe.IsEnabled      = false;
                txtRecipeDifficulty.IsEnabled = false;
                txtRecipeDurability.IsEnabled = false;
                txtRecipeLevel.IsEnabled      = false;
                txtRecipeQuality.IsEnabled    = false;

                // Enable random outcome entry.
                radioFailureExcellent.IsEnabled = true;
                radioFailureGood.IsEnabled      = true;
                radioFailureNormal.IsEnabled    = true;
                radioFailurePoor.IsEnabled      = true;
                radioSuccessExcellent.IsEnabled = true;
                radioSuccessGood.IsEnabled      = true;
                radioSuccessNormal.IsEnabled    = true;
                radioSuccessPoor.IsEnabled      = true;

                Simulator.Engine.Ability bestAction = analyzer.OptimalAction(currentState);
                UpdateUIStateForPlayback(currentState, bestAction);
                break;
            }

            appState = newState;
        }
Esempio n. 7
0
        private void UpdateUIStateForPlayback(State state, Simulator.Engine.Ability bestAction)
        {
            UpdateUIState(state);

            if (bestAction != null)
            {
                lblBestAction.Content = bestAction.Name;
            }
            else
            {
                lblBestAction.Content = String.Empty;
            }

            switch (state.Condition)
            {
            case Engine.Condition.Poor:
            case Engine.Condition.Good:
                radioFailureExcellent.IsEnabled = false;
                radioFailureGood.IsEnabled      = false;
                radioFailurePoor.IsEnabled      = false;
                radioSuccessExcellent.IsEnabled = false;
                radioSuccessGood.IsEnabled      = false;
                radioSuccessPoor.IsEnabled      = false;

                radioFailureNormal.IsEnabled = true;
                radioSuccessNormal.IsEnabled = true;

                if (selectedRadio != null)
                {
                    selectedRadio.IsChecked = false;
                }
                break;

            case Engine.Condition.Excellent:
                radioFailurePoor.IsEnabled = true;
                radioSuccessPoor.IsEnabled = true;

                radioFailureExcellent.IsEnabled = false;
                radioFailureGood.IsEnabled      = false;
                radioSuccessExcellent.IsEnabled = false;
                radioSuccessGood.IsEnabled      = false;
                radioFailureNormal.IsEnabled    = false;
                radioSuccessNormal.IsEnabled    = false;

                if (selectedRadio != null)
                {
                    selectedRadio.IsChecked = false;
                }
                break;

            case Engine.Condition.Normal:
                radioFailurePoor.IsEnabled = false;
                radioSuccessPoor.IsEnabled = false;

                radioFailureExcellent.IsEnabled = true;
                radioFailureGood.IsEnabled      = true;
                radioSuccessExcellent.IsEnabled = true;
                radioSuccessGood.IsEnabled      = true;
                radioFailureNormal.IsEnabled    = true;
                radioSuccessNormal.IsEnabled    = true;

                if (selectedRadio != null)
                {
                    selectedRadio.IsChecked = false;
                }
                break;
            }

            if (bestAction == null || state.Status != SynthesisStatus.IN_PROGRESS)
            {
                radioFailureExcellent.IsEnabled = false;
                radioFailureGood.IsEnabled      = false;
                radioFailureNormal.IsEnabled    = false;
                radioFailurePoor.IsEnabled      = false;
                radioSuccessExcellent.IsEnabled = false;
                radioSuccessGood.IsEnabled      = false;
                radioSuccessNormal.IsEnabled    = false;
                radioSuccessPoor.IsEnabled      = false;
            }
            else if (!bestAction.CanFail)
            {
                radioFailureExcellent.IsEnabled = false;
                radioFailureGood.IsEnabled      = false;
                radioFailureNormal.IsEnabled    = false;
                radioFailurePoor.IsEnabled      = false;
            }
        }