Exemple #1
0
        public StateMachine(DataTypes.BitmapUnsafe bitmap, List<State> states)
        {
            _bitmap = bitmap;
            _states = states;

            startx = rand.Next(0, bitmap.Width);
            starty = rand.Next(0, bitmap.Height);
            startstate = states[rand.Next(0, states.Count)];

            Reset();
        }
Exemple #2
0
        public static State FromString(string value, int maxstates)
        {
            State retval = new State();

            value = value.Substring(1);
            int index;

            index = value.IndexOf('m');

            retval.action = (Action)Convert.ToInt32(value.Substring(0, index));
            value = value.Substring(index + 1);

            index = value.IndexOf(']');

            retval.magnitude = Convert.ToInt32(value.Substring(0, index));

            retval.maxstates = maxstates;

            return retval;
        }
Exemple #3
0
 public void Reset()
 {
     x = startx;
     y = starty;
     state = startstate;
 }
Exemple #4
0
        public void Handle()
        {
            int newstate = state.Handle(ref _bitmap, ref x, ref y);
            if (newstate < 0)
            {
                int reprogramindex = -newstate - 1;

                int otherparam=0;
                while (reprogramindex >= _states.Count)
                {
                    reprogramindex -= _states.Count;
                    otherparam++;
                }

                _states[reprogramindex] = new State(_states.Count);
            }
            else
            {
                while (newstate >= _states.Count) newstate -= _states.Count;
                state = _states[newstate];
            }
        }
Exemple #5
0
        void button_randomize_Click(object sender, EventArgs e)
        {
            this.checkbox_executionstate.Enabled = true;
            this.button_singlestep.Enabled = !this.checkbox_executionstate.Checked;

            boring = int.MinValue;
            boredom = 0;

            this.textbox_boredom.Text = boredom.ToString();
            this.pictureBox1.BackgroundImage = null;

            string text = "r" + this.numeric_executionrate.Value.ToString();

            text += "w" + this.numeric_width.Value.ToString() + "h" + this.numeric_height.Value.ToString();

            image = new Bitmap((int)this.numeric_width.Value, (int)this.numeric_height.Value, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            numeric_executionrate_ValueChanged(null, null);

            _image = new DataTypes.BitmapUnsafe(image);

            for (int y = 0; y < this.numeric_height.Value; y++)
            {
                for (int x = 0; x < this.numeric_width.Value; x++)
                {
                    image.SetPixel(x, y, Color.FromArgb(255, 0, 0, 0));
                }
            }

            text += "v" + this.numeric_values.Value.ToString();

            if (this.checkbox_samemachine.Checked)
            {
                List<TuringMachine.State> states = new List<TuringMachine.State>();

                text += "m" + this.numeric_states.Value.ToString() + "s";

                for (int n = 0; n < this.numeric_states.Value; n++)
                {
                    TuringMachine.State state = new TuringMachine.State((int)this.numeric_values.Value);
                    states.Add(state);

                    text += state.ToString();
                }

                instances = new List<TuringMachine.StateMachine>();

                text += "i" + this.numeric_instances.Value.ToString();

                for (int n = 0; n < this.numeric_instances.Value; n++)
                {
                    TuringMachine.StateMachine what = new TuringMachine.StateMachine(_image, states);
                    instances.Add(what);
                    text += what.ToString(true);
                }
            }
            else
            {
                instances = new List<TuringMachine.StateMachine>();

                text += "i" + this.numeric_instances.Value.ToString();

                for (int n = 0; n < this.numeric_instances.Value; n++)
                {
                    List<TuringMachine.State> states = new List<TuringMachine.State>();

                    for (int subn = 0; subn < this.numeric_states.Value; subn++)
                    {
                        TuringMachine.State state = new TuringMachine.State((int)this.numeric_values.Value);
                        states.Add(state);
                    }

                    TuringMachine.StateMachine what = new TuringMachine.StateMachine(_image, states);
                    instances.Add(what);

                    text += what.ToString(false);
                }
            }

            this.textbox_machines.Text = text;
        }