Esempio n. 1
0
        private void start_algorithm(object sender, EventArgs e)
        {
            change_enabled_setting(); //Toggle controls
            AlgorithmState.StartAlgorithm();

            FormsHandler.LoadAndDisplayState(AlgorithmState.GetCurrentState());
        }
Esempio n. 2
0
 //In response to stop algorithm button being pressed
 public static void StopAlgorithm(AlgorithmState to_handle)
 {
     loaded_state = to_handle;
     to_handle.EraseBoardForReset(); //Special function that creates a new board but keeps bender's position
     //clear the board and keep bender
     ResetConfiguration();           //Clear comboboxes and other forms
 }
Esempio n. 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 set_from)
        {
            cans_collected = set_from.cans_collected;

            episode_rewards = set_from.episode_rewards; //Reward data
            total_rewards   = set_from.total_rewards;

            board_data = new GameBoard(set_from.board_data); //Copy the board

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

            //The initial location will be the resulting location of the last step
            location_initial = new int[2] {
                set_from.location_result[0], set_from.location_result[1]
            };

            bender_perception_starting = set_from.bender_perception_ending;

            //Detect if we reached the limit for this episode

            if (live_qmatrix.step_number == Qmatrix.step_limit)
            {
                StartNewEpisode();
            }
            else
            {
                live_qmatrix.step_number++;
            }
        }
Esempio n. 4
0
        //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.
        }
Esempio n. 5
0
        private void history_index_changed(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.state_history_data.ToArray());
                comboboxHistorystep.SelectedIndex = 0;

                AlgorithmState state_to_display = (AlgorithmState)comboboxHistorystep.Items[0];
                FormsHandler.LoadAndDisplayState(state_to_display);
            }
        }
Esempio n. 6
0
        //Advance algorithm button
        async private void buttonAdvancestepsdropdown_Click(object sender, EventArgs e)
        {
            FormsHandler.halted = false;
            int steps_to_take = Int32.Parse(comboboxAdvancesteps.Text);
            int episodes      = Int32.Parse(comboboxAdvanceepisodes.Text);

            if (episodes > 0)
            {
                steps_to_take += (Int32.Parse(comboboxAdvanceepisodes.Text) * FormsHandler.loaded_state.GetStepLimit()) + 1; //+1 to get the new episode generated
            }
            int initial_delay = Int32.Parse(comboboxDelayms.Text);
            int delay         = initial_delay;

            if (steps_to_take > 1)
            {
                textboxProgresssteps.Text         = steps_to_take.ToString();
                groupboxCountdown.Enabled         = true;
                groupboxAlgorithmprogress.Enabled = false;
                groupboxHistory.Enabled           = false;
                while (steps_to_take-- > 0 && !FormsHandler.halted)
                {
                    AlgorithmState.PrepareStep();
                    FormsHandler.LoadAndDisplayState(AlgorithmState.GetCurrentState());
                    textboxProgresssteps.Text = steps_to_take.ToString();
                    do
                    {
                        await Task.Delay(1);

                        textboxCountdown.Text = delay.ToString();
                    } while (--delay > 0 && !FormsHandler.halted);
                    delay = initial_delay;
                }
                groupboxAlgorithmprogress.Enabled = true;
                groupboxCountdown.Enabled         = false;
                groupboxHistory.Enabled           = true;
            }

            else
            {
                AlgorithmState.PrepareStep();
                FormsHandler.LoadAndDisplayState(AlgorithmState.GetCurrentState());
            }
        }
Esempio n. 7
0
        private void Form1_Load(object sender, EventArgs e)
        {
            AlgorithmState.SetDefaultConfiguration();


            //Second entry point of the program.
            //When the form loads, we'll create some pictureboxes, that will function as the robot world grid.


            PictureBox    picturebox_in_progress; //Temporary picturebox
            PictureSquare square_to_build;        //This is object inherits from boardSquare, but has a picture element.

            //Create pictureboxes and pass them to our board
            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    //Fill in the column with rows
                    picturebox_in_progress          = new PictureBox();
                    square_to_build                 = new PictureSquare();
                    picturebox_in_progress.Name     = i.ToString() + "-" + j.ToString(); //Each name is the coordinate
                    picturebox_in_progress.Location =
                        new Point(InitialSettings.x_offset() + (i * InitialSettings.edge_length()),
                                  InitialSettings.y_offset() + (j * InitialSettings.edge_length()));
                    picturebox_in_progress.Size     = new Size(InitialSettings.edge_length(), InitialSettings.edge_length());
                    picturebox_in_progress.SizeMode = PictureBoxSizeMode.StretchImage;
                    picturebox_in_progress.BackgroundImageLayout = ImageLayout.Stretch;
                    Controls.Add(picturebox_in_progress);
                    square_to_build.pictureData = picturebox_in_progress;
                    FormsHandler.Add(i, 9 - j, square_to_build); //9-j to handle the board layout, for some reason!
                }
            }

            //Called from the restart button, but works here on initial launch.
            //This triggers the constructor for algorithm manager, as well

            textboxStatus.Text = "Program launched.";

            FormsHandler.DisplayState(); //First time we display the board.
        }
Esempio n. 8
0
        static public PictureBoard picture_board;  //Stored seperately from the algorithm state because this board will store PictureSquares

        static FormsHandler()
        {
            picture_board = new PictureBoard();
            loaded_state  = new AlgorithmState();

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

            link_handler_to_form();

            //Initialize dropdown boxes
            control_progress_steps.SelectedIndex = 0;
            control_progress_episodes.Text       = "0";;
            control_progress_delay.Text          = InitialSettings.ms_delay().ToString();

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

            DisplayInitialSettings();
        }
Esempio n. 9
0
        private void restart_algorithm_button_click(object sender, EventArgs e)
        {
            FormsHandler.StopAlgorithm(AlgorithmState.GetCurrentState());

            change_enabled_setting(); //Togle controls
        }
Esempio n. 10
0
        private void comboboxHistorystep_SelectedIndexChanged(object sender, EventArgs e)
        {
            AlgorithmState state_to_dislay = (AlgorithmState)((ComboBox)sender).SelectedItem;

            FormsHandler.LoadAndDisplayState(state_to_dislay);
        }
Esempio n. 11
0
 //Displays the most recent state in the algorithm history list
 static public void LoadAndDisplayState(AlgorithmState to_display)
 {
     loaded_state = to_display;
     DisplayState();
 }
Esempio n. 12
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 perception_to_view)
        {
            qmatrix_stored_entires.Text = current_state.live_qmatrix.matrix_data.Count.ToString();

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

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


                //reset qmatrix textboxes
                foreach (var i in List_qmatrix_value_textboxes.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> > dropdown_text_items = new Dictionary <Move, HashSet <Percept> >();

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

                //Copy the items over to the small comboboxes.
                foreach (var i in current_state.live_qmatrix.matrix_data.Keys)
                {
                    foreach (var j in Move.list)
                    {
                        //For each qmatrix entry, copy each percept over to dropdowns dictionary for the appropriate move.
                        dropdown_text_items[j].Add(i.perception_data[j]);
                    }
                }


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

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

                if (current_state.live_qmatrix.matrix_data.Keys.Contains(current_state.bender_perception_starting))
                {
                    ViewQmatrixConfiguration(loaded_state.bender_perception_starting);
                }
                else
                {
                    ViewQmatrixConfiguration(loaded_state.live_qmatrix.matrix_data.Keys.First()); //Just grab the first q-matrix item
                }
            }
        }
Esempio n. 13
0
 //Add a state
 public static void AddToHistory(AlgorithmState to_add)
 {
     state_history.Last().Add(to_add);
 }
Esempio n. 14
0
 public void Add(AlgorithmState to_add)
 {
     state_history_data.Add(to_add);
 }