Пример #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;
            }
        }
Пример #2
0
        static public void load()
        {
            picture_board = new BoardDisplay();
            loadedState   = new AlgorithmState();

            InitialSettings.Initialize();

            lock_indexChange_events = false;
            halted = false;
            //Pass textboxes to the board, so it can manage them.

            link_handlerToForm();

            //Initialize dropdown boxes
            controlProgress_steps.SelectedIndex = 0;
            controlProgress_episodes.Text       = "0";;
            controlProgress_delay.Text          = InitialSettings.MS_Delay.ToString();

            foreach (var i in list_qmatrixComboboxes)
            {
                i.Value.SelectedIndex = -1;
            }

            DisplayInitialSettings();
        }
Пример #3
0
        //Copied from another algorithm state
        //We reset some data, so we dont reflect values that aren't true for the new state
        //This constructor is called when a new step is being generated, so we transfer some values appropriately.
        public AlgorithmState(AlgorithmState setFrom)
        {
            cansCollected = setFrom.cansCollected;

            episodeRewards = setFrom.episodeRewards; //Reward data
            totalRewards   = setFrom.totalRewards;

            boardData = new BoardGame(setFrom.boardData); //Copy the board

            //Increase steps in here
            liveQmatrix = new Qmatrix(setFrom.liveQmatrix); //Copy the q matrix

            //The initial location will be the resulting location of the last step
            locationInitial = boardData.GetUnitSquare[UnitType.Bender];

            //Detect if we reached the limit for this episode


            if (liveQmatrix.setNumber == Qmatrix.stepLimit || setFrom.benderAttacked)
            {
                if (liveQmatrix.episodeNumber == Qmatrix.episodeLimit)
                {
                    AlgorithmManager.algorithmEnded = true;
                }
                else
                {
                    StartNewEpisode();
                }
            }
            else
            {
                liveQmatrix.setNumber++;
            }
        }
Пример #4
0
        private void history_indexChanged(object sender, EventArgs e)
        {
            ComboBox sender_box = (ComboBox)sender;

            if (sender_box.SelectedIndex > -1)
            {
                comboboxHistorystep.Items.Clear();

                AlgorithmEpisode to_display = (AlgorithmEpisode)sender_box.SelectedItem;
                comboboxHistorystep.Items.AddRange(to_display.stateHistoryData.ToArray());
                comboboxHistorystep.SelectedIndex = 0;

                AlgorithmState stateTo_display = (AlgorithmState)comboboxHistorystep.Items[0];
                FormsHandler.LoadAndDisplayState(stateTo_display);
            }
        }
Пример #5
0
        private void comboboxHistorystep_SelectedIndexChanged(object sender, EventArgs e)
        {
            AlgorithmState stateTo_dislay = (AlgorithmState)((ComboBox)sender).SelectedItem;

            FormsHandler.LoadAndDisplayState(stateTo_dislay);
        }
Пример #6
0
 public void Add(AlgorithmState toAdd)
 {
     stateHistoryData.Add(toAdd);
 }
Пример #7
0
 //Add a state
 public static void AddToHistory(AlgorithmState toAdd)
 {
     stateHistory.Last().Add(toAdd);
 }
Пример #8
0
 //Displays the most recent state in the algorithm history list
 static public void LoadAndDisplayState(AlgorithmState to_display)
 {
     loadedState = to_display;
     DisplayState();
 }
Пример #9
0
        //This is used to display rows of the qmatrix and the q-values for each move
        //This is called from FormsHandler.DisplayState, as well as directly from the dropdowns when their contents are changed.
        //When this is called from displaystate, the perception to view may not be valid.
        //When this is called from the dropdown, the perception should exist in the qmatrix.
        static private void HandleQmatrixForms(AlgorithmState current_state, PerceptionState perceptionTo_view)
        {
            qmatrix_stored_entires.Text = current_state.liveQmatrix.matrixData.Count.ToString();

            //May not have qmatrix data at the step being displayed.
            if (current_state.liveQmatrix.matrixData.Count == 0)
            {   //There are no q-matrix entries.
                //reset qmatrix combo boxes
                foreach (var i in list_qmatrixComboboxes.Values)
                {
                    i.Items.Clear();
                    i.Items.Add("None");
                }

                qmatrix_stateComboboxLarge.Items.Clear();
                qmatrix_stateComboboxLarge.Items.Add("A q-matrix entry has not yet been made.");


                //reset qmatrix textboxes
                foreach (var i in List_qmatrix_valueTextboxes.Values)
                {
                    i.Clear();
                }
            }
            else
            {
                //Build q-matrix dropdowns.
                //use a hashset to avoid adding duplicates
                //For each move, we want a hashet of percepts, in other words all the percepts that this move sees in the q matrix entries that exist.
                Dictionary <Move, HashSet <Percept> > dropdownText_items = new Dictionary <Move, HashSet <Percept> >();

                //Initialize hashsets before looping over perceptionstates
                foreach (var i in Move.HorizontalMovesAndGrab)
                {
                    dropdownText_items.Add(i, new HashSet <Percept>());
                }

                //Copy the items over to the small comboboxes.
                foreach (var i in current_state.liveQmatrix.matrixData.Keys)
                {
                    foreach (var j in Move.HorizontalMovesAndGrab)
                    {
                        //For each qmatrix entry, copy each percept over to dropdowns dictionary for the appropriate move.
                        dropdownText_items[j].Add(i.perceptionData[j]);
                    }
                }


                //Cycle through the moves to add to select each small combobox
                foreach (var i in Move.HorizontalMovesAndGrab)
                {
                    list_qmatrixComboboxes[i].Items.Clear();
                    //Cycle through the percepts we gathered for this move's dropdown
                    foreach (var j in dropdownText_items[i].OrderBy(o => o.perceptData))
                    {
                        list_qmatrixComboboxes[i].Items.Add(j); //I think i can just give my objects a tostring method
                    }
                }

                //Refresh the overall-state dropdown
                qmatrix_stateComboboxLarge.Items.Clear();
                foreach (var i in current_state.liveQmatrix.matrixData.Keys.OrderBy(o => o.ID))
                {
                    qmatrix_stateComboboxLarge.Items.Add(i);
                }

                if (current_state.liveQmatrix.matrixData.Keys.Contains(current_state.GetPerception(UnitType.Bender)))
                {
                    ViewQmatrixConfiguration(current_state.GetPerception(UnitType.Bender));
                }
                else
                {
                    ViewQmatrixConfiguration(loadedState.liveQmatrix.matrixData.Keys.First()); //Just grab the first q-matrix item
                }
            }
        }