private void onAlgoritmBtnClick(object obj, EventArgs args) { string sourceCode = programTexton.Buffer.Text; IAlghoritm alg; if (obj == turingBtn) { alg = new TuringAlg(sourceCode); } else { alg = new MarkovAlg(sourceCode); } string initStateStr = initState.Text; initState.Text = alg.calculate(initStateStr); if (obj == turingBtn) { TuringDisplay display = new TuringDisplay(); alg.setInitState(initStateStr); display.setCurrentTuringAlg((Turing.TuringAlg)alg); display.Show(); } }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); string[] Example = new string[0]; string[] Example1 = new string[0]; string[] ClearArray = { "" }; spinnerRule = FindViewById <Spinner>(Resource.Id.spinner1); spinnerStep = FindViewById <Spinner>(Resource.Id.spinner2); MarkovAlg Markov = new MarkovAlg(); var RESULT = FindViewById <EditText>(Resource.Id.RESULT); // Get our button from the layout resource, // and attach an event to it Button nextRule = FindViewById <Button>(Resource.Id.nextRule); Button ansver = FindViewById <Button>(Resource.Id.ansver); Button ACCEPT = FindViewById <Button>(Resource.Id.ACCEPT); Button Exit = FindViewById <Button>(Resource.Id.Exit); Button Help = FindViewById <Button>(Resource.Id.Help); Button Clear = FindViewById <Button>(Resource.Id.Clear); Clear.Click += delegate { Markov.Clear(); Array.Clear(Example, 0, Example.Length); Array.Clear(Example1, 0, Example1.Length); count = 0; i = 0; k = 0; RESULT.Text = " All Clear"; FindViewById <EditText>(Resource.Id.rule1).Text = ""; FindViewById <EditText>(Resource.Id.rule2).Text = ""; FindViewById <EditText>(Resource.Id.original).Text = ""; spinnerRule.Adapter = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleSpinnerDropDownItem, ClearArray); spinnerStep.Adapter = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleSpinnerDropDownItem, ClearArray); }; Exit.Click += delegate { this.FinishAffinity(); }; Help.Click += delegate { Android.App.AlertDialog.Builder builder = new Android.App.AlertDialog.Builder(this); Android.App.AlertDialog alertDialog = builder.Create(); alertDialog.SetTitle("Help"); alertDialog.SetMessage("Empty symbol it's ' " + " ' (Spacebar) \n For enteryng Original word press Accept \n For eneryng every rule press Next Rule"); alertDialog.Show(); }; ACCEPT.Click += delegate { Markov.ReadOriginal(FindViewById <EditText>(Resource.Id.original).Text); }; nextRule.Click += delegate { if (FindViewById <EditText>(Resource.Id.rule1).Text == "" && FindViewById <EditText>(Resource.Id.rule2).Text == "") { Android.App.AlertDialog.Builder builder = new Android.App.AlertDialog.Builder(this); Android.App.AlertDialog Validation = builder.Create(); Validation.SetTitle("Error"); Validation.SetMessage("One from rules must be diferent from NULL"); Validation.Show(); } else { Markov.ReadRule(FindViewById <EditText>(Resource.Id.rule1).Text, FindViewById <EditText>(Resource.Id.rule2).Text, count); Array.Resize <string>(ref Example, count + 1); Example[count] = (count + 1).ToString() + " rule - " + FindViewById <EditText>(Resource.Id.rule1).Text + " -> " + " " + FindViewById <EditText>(Resource.Id.rule2).Text; spinnerRule.Adapter = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleSpinnerDropDownItem, Example); count = count + 1; FindViewById <EditText>(Resource.Id.rule1).Text = ""; FindViewById <EditText>(Resource.Id.rule2).Text = ""; } }; i = 0; ansver.Click += delegate { if (Markov.Result() == "") { Android.App.AlertDialog.Builder builder = new Android.App.AlertDialog.Builder(this); Android.App.AlertDialog Error = builder.Create(); Error.SetTitle("Help"); Error.SetMessage("Enter original word"); Error.Show(); } else { k = count; int RuleCount = 0; Array.Resize <string>(ref Example1, RuleCount + 1); Example1[RuleCount] = "Original String " + Markov.Result(); spinnerStep.Adapter = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleSpinnerDropDownItem, Example1); RuleCount = 1; int CycleControl = 0; { while (i < count) { CycleControl++; if (CycleControl > 1000) { Markov.CycleControl(); break; } if (Markov.Contains(Markov.rules[i, 0])) { Markov.replace(Markov.rules[i, 0], Markov.rules[i, 1]); Array.Resize <string>(ref Example1, RuleCount + 1); Example1[RuleCount] = (RuleCount + 1).ToString() + " step - " + Markov.Result(); spinnerStep.Adapter = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleSpinnerDropDownItem, Example1); RuleCount++; if (Markov.end(i)) { break; } i = 0; } else { i++; } } ; } } RESULT.Text = Markov.Result(); }; }