C# ta Sonlu Durumlu Otomata Similasyonu

C# ta Sonlu Durumlu Otomata Similasyonu

Merhaba Arkadaşlar,

proje

Ayrık matematik proje ödevi olarak yaptığım similasyonun kaynak kodları ile paylaşıyorum.Otomata öğrenen veya algoritmasını merak eden arkadaşlara faydalı olmasını umarım.yaklaşık 2 hafta anlatılan (6 ders saati) sürede konunun başlangıcı olarak elimden geldiği kadar uygulamaya çalıştım.Similasyonda tüm işlevler ve durumlar kullanıcı tarafından oluşturulacaktır.Projede farklı olarak Linq  ile liste içinde sorgulama işleminide görebilirsin.Umarım faydalı olur.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace mesutpek_ayrikmat_2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
panel1.Visible = false;
}

private void button1_Click(object sender, EventArgs e)
{
try
{
for (int i = 1; i <= Convert.ToInt32(textBox1.Text); i++)
{
comboBox1.Items.Add("Q"+i);
comboBox3.Items.Add("Q" + i);
comboBox4.Items.Add("Q" + i);
}
panel2.Visible = false;
panel1.Visible = true;
}
catch (Exception)
{

MessageBox.Show("Geçerli Değer girin");
}
}
List<mat> listem = new List<mat>();

private void button2_Click(object sender, EventArgs e)
{
try
{
mat m = new mat();
m.BQ = comboBox1.SelectedItem.ToString();
m.Harf = comboBox2.SelectedItem.ToString();
m.GQ = comboBox3.SelectedItem.ToString();
comboBox2.SelectedIndex=0;
comboBox3.SelectedIndex=0;
listem.Add(m);
listBox1.Items.Add(m.BQ.ToString()+"-" + m.Harf.ToString() + "-" + m.GQ.ToString());
}
catch (Exception)
{

MessageBox.Show("Bir hata oluştu.Lütfen doğru değerler girin !! ");
}
}
string bulunanq = "Q1";
private void button3_Click(object sender, EventArgs e)
{
button3.Visible = false;

if (listem.Count>0 &&textBox2.Text.Length>0 &comboBox4.SelectedIndex>=0 )
{
string dizgi = textBox2.Text;

string gelenharf;

for (int i = 0; i < dizgi.Length; i++)
{
List<mat> lst = new List<mat>();
lst =listem.Where(list => list.BQ == bulunanq &&list.Harf == dizgi.Substring(i, 1)).ToList();
foreach (var item in lst)
{
bulunanq = item.GQ;
}
listBox2.Items.Add(dizgi.Substring(i, 1) + " -->" + bulunanq.ToString());
}
if (bulunanq==comboBox4.SelectedItem.ToString())
{
listBox2.Items.Add("Sonuç Başarılı.");
}
else
{
listBox2.Items.Add("Sonuç istenilen değere ulaşamadı.");
}
}
else
{
MessageBox.Show("Q değerlerini oluşturun");
}

}

private void button4_Click(object sender, EventArgs e)
{
try
{
comboBox2.Items.Add(textBox3.Text);
listBox1.Items.Add("Giriş : "+textBox3.Text);
textBox3.Clear();
}
catch (Exception ex)
{
MessageBox.Show("Lütfen Değer Girin");

}
}

private void button5_Click(object sender, EventArgs e)
{
listBox2.Items.Clear();
bulunanq = "Q1";
button3.Visible = true;
}
}
}