Example #1
0
        //Manages the state history, and making sure the correct state is being created/stored
        public static void StepPrepare() //Go to the most current state, and step forward once.
        {                                //If the algorithm hasn't started, this will just start the algorithm and leave us at step 0.
            //use start new episode if this is the first step
            //step and add, or dont step and dont add
            AlgorithmState stepWith = new AlgorithmState(GetCurrentState());

            //After the copy consctructor above, the state will have the correct episode number.
            //We may need to add a new episode.


            if (stepWith.GetEpisodeNumber() > stateHistory.Count)
            {
                stateHistory.Add(new AlgorithmEpisode(stateHistory.Count + 1)); //Add the first empty episode
            }
            else
            {
                stepWith.Step();
            }

            stateHistory.Last().Add(stepWith); //Add the state to the history list, after everything possible has been done to it.
            stepWith.GenerateStatusMessage();

            if (GetCurrentState().GetUnit(UnitType.Url).chasing == true)
            {
                FormsHandler.hasUrlStartedChasing = false;
            }
        }
Example #2
0
        //This is ran every time we step through the algorithm.
        //Handles updating all the fields that change every time we look at new data
        //This method handles any time we are updating what is displayed for any reason once the algorithm is active
        //We expect the algorithm state to be set from the outside before we enter this.
        //This will also handle updating the history dropdowns
        static public void DisplayState()
        {
            picture_board.ClonePosition(loadedState.boardData); //This copies the state's board over to our PictureSquare board.

            //Textboxes update
            if (AlgorithmManager.algorithmStarted) //Only display this if we've started
            {
                //This will configure the q-matrix dropdowns properly, and handle if there is no qmatrix as well.
                //This doesn't affect the stored entries textbox
                HandleQmatrixForms(loadedState, loadedState.GetPerception(UnitType.Bender));

                //Session progress
                stepNumber.Text    = loadedState.GetStepNumber().ToString();
                episodeNumber.Text = loadedState.GetEpisodeNumber().ToString();
                e_session.Text     = GetString(loadedState.liveQmatrix.e);
                y_session.Text     = loadedState.liveQmatrix.y.ToString();

                //If this moveset doesn't exist, we should get an error.
                //This function should only be called at the algorithm start, or from a dropdown that has a valid q-matrix combination.
                //These textboxes handle percepts

                PerceptionState to_view = loadedState.boardData.units[UnitType.Bender].perceptionData;

                foreach (var i in Move.HorizontalMovesAndGrab)
                {
                    listCurrentPositionTextboxes[i].Text = to_view.perceptionData[i].ToString();
                }

                beer_remaining.Text = loadedState.boardData.GetCansRemaining().ToString();
                beerCollected.Text  = loadedState.cansCollected.ToString();
                reward_episode.Text = loadedState.episodeRewards.ToString();
                rewardTotal.Text    = loadedState.totalRewards.ToString();

                //Update the history episode dropdown
                if (combobox_history_episodes.Items.Count < AlgorithmManager.stateHistory.Count)
                {
                    combobox_history_episodes.Items.Add(AlgorithmManager.stateHistory.Last());
                }

                combobox_history_episodes.SelectedIndex = combobox_history_episodes.Items.Count - 1;

                if (!combobox_history_steps.Items.Contains(loadedState) || loadedState.GetStepNumber() == 0)
                {
                    combobox_history_steps.Items.Clear();
                    combobox_history_steps.Items.AddRange(AlgorithmManager.stateHistory.Last().ToArray());
                    combobox_history_steps.Text = loadedState.ToString();
                }
            }


            status_box.Text = loadedState.GetStatus();

            //Handle drawing the board
            foreach (var i in picture_board.boardData)
            {
                foreach (var j in i)
                {
                    ((SquareBoardDisplay)j).SetPicture();
                }
            }

            DisplayInitialSettings();

            //If the algorithm is ended, disable the stepping groupbox.
            if (AlgorithmManager.algorithmEnded == true)
            {
                groupboxControlProgress.Enabled = false;
            }
        }