//Manages the state history, and making sure the correct state is being created/stored public static void PrepareStep() //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 step_with = new AlgorithmState(GetCurrentState()); if (step_with.GetStepNumber() == Qmatrix.step_limit) { state_history.Add(new AlgorithmEpisode(state_history.Count + 1)); //Add the first empty episode } step_with.TakeStep(); state_history.Last().Add(step_with); //Add the state to the history list, after everything possible has been done to it. }
//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.clone_position(loaded_state.board_data); //This copies the state's board over to our PictureSquare board. //Textboxes update if (AlgorithmState.algorithm_started) //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(loaded_state, loaded_state.bender_perception_starting); //Session progress step_number.Text = loaded_state.GetStepNumber().ToString(); episode_number.Text = loaded_state.GetEpisodeNumber().ToString(); e_session.Text = GetString(loaded_state.live_qmatrix.e_current); y_session.Text = loaded_state.live_qmatrix.y_current.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 = loaded_state.board_data.get_bender_perception(); foreach (var i in Move.list) { list_current_position_textboxes[i].Text = to_view.perception_data[i].ToString(); } beer_remaining.Text = loaded_state.board_data.get_cans_remaining().ToString(); beer_collected.Text = loaded_state.cans_collected.ToString(); reward_episode.Text = loaded_state.episode_rewards.ToString(); reward_total.Text = loaded_state.total_rewards.ToString(); //Update the history episode dropdown if (combobox_history_episodes.Items.Count < AlgorithmState.state_history.Count) { combobox_history_episodes.Items.Add(AlgorithmState.state_history.Last()); } combobox_history_episodes.SelectedIndex = combobox_history_episodes.Items.Count - 1; if (!combobox_history_steps.Items.Contains(loaded_state) || loaded_state.GetStepNumber() == 0) { combobox_history_steps.Items.Clear(); combobox_history_steps.Items.AddRange(AlgorithmState.state_history.Last().ToArray()); combobox_history_steps.Text = loaded_state.ToString(); } } picture_board.clone_position(loaded_state.board_data); //Handle drawing the board foreach (var i in picture_board.board_data) { foreach (var j in i) { ((PictureSquare)j).setPicture(); } } status_box.Text = StatusMessage.GetMessageFromState(loaded_state); DisplayInitialSettings(); }