예제 #1
0
        public static StateMachine FromString(DataTypes.BitmapUnsafe image, string value, int maxstates)
        {
            StateMachine retval = new StateMachine();
            retval._bitmap = image;

            value = value.Substring(1);
            if (value[0] != 's') throw new Exception("wrong function for dupmachine");

            value = value.Substring(1);

            int index;

            index = value.IndexOf('i');

            int statecount = Convert.ToInt32(value.Substring(0, index));
            value = value.Substring(index + 1);

            index = value.IndexOf('x');

            int initialstate = Convert.ToInt32(value.Substring(0, index));
            value = value.Substring(index + 1);

            index = value.IndexOf('y');

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

            index = value.IndexOf('[');

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

            retval._states = new List<State>();

            for (int n = 0; n < statecount; n++)
            {
                index = value.IndexOf(']');
                retval._states.Add(State.FromString(value.Substring(0, index + 1), maxstates));
                value = value.Substring(index + 1);
            }

            if (value != ")") throw new Exception("end mismatch");

            retval.startstate = retval._states[initialstate];

            retval.Reset();
            return retval;
        }
예제 #2
0
        public static StateMachine FromString(DataTypes.BitmapUnsafe image, string value, List<State> states)
        {
            StateMachine retval = new StateMachine();
            retval._bitmap = image;

            value = value.Substring(1);
            if (value[0] != 'd') throw new Exception("wrong function for not dupmachine");

            value = value.Substring(1);

            int index;

            index = value.IndexOf('i');

            int statecount = Convert.ToInt32(value.Substring(0, index));
            value = value.Substring(index + 1);

            index = value.IndexOf('x');

            int initialstate = Convert.ToInt32(value.Substring(0, index));
            value = value.Substring(index + 1);

            index = value.IndexOf('y');

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

            index = value.IndexOf(')');

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

            retval._states = states;

            if (value != ")") throw new Exception("end mismatch");

            retval.startstate = retval._states[initialstate];

            retval.Reset();
            return retval;
        }
예제 #3
0
파일: Form1.cs 프로젝트: felayga/TuringRand
        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;
        }