⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 expert.cs

📁 动物识别专家系统的c#实现 采用了15条规则
💻 CS
字号:
/*
 * 作者:namespace
 * QQ:82108212
 * Email:gysyf@163.com
 * 欢迎交流
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;


namespace 动物识别专家程序
{
    class expert
    {
        /*事实库*/
        public string[] fact = new string[32] { "", "有毛发", "有奶", "有羽毛", "会飞", "会下蛋", "吃肉", "有犬齿", "有爪", "眼盯前方", "有蹄", "黄褐色", "身上有暗斑点", "身上有黑色条纹", "有长脖子", "有长腿", "会游泳", "有黑白二色", "善飞", "不会飞", "哺乳动物", "鸟", "食肉动物", "蹄类动物", "嚼反刍动物", "金钱豹", "老虎", "长颈鹿", "斑马", "鸵鸟", "企鹅", "信天翁" };
       
        /*规则库*/
        public int[,] rule = new int[16,6] { { 0, 0, 0, 0, 0, 0 }, { 20, 1, 0, 0, 0, 0 }, { 20, 2, 0, 0, 0, 0 }, { 21, 3, 0, 0, 0, 0 }, { 21, 4, 5, 0, 0, 0 }, { 22, 6, 0, 0, 0, 0 }, { 22, 7, 8, 9, 0, 0 }, { 23, 20, 10, 0, 0, 0 }, { 23, 20, 24, 0, 0, 0 }, { 25, 20, 22, 11, 12, 0 }, { 26, 20, 22, 11, 13, 0 }, { 27, 23, 14, 15, 12, 0 }, { 28, 23, 13, 0, 0, 0 }, { 29, 21, 14, 15, 19, 17 }, { 30, 21, 16, 19, 17, 0 }, { 31, 21, 18, 0, 0, 0 } };
        public int[] factList = new int[32];
        public int[] used = new int[10];
        public int[] conclusion = new int[10];
        public ListBox lb=new ListBox();

        /*推理*/
        public string  think()
        {
            int i;
            int l = 0;
            int m = 0;
            for (i = 1; i <= 15; i++)
            {
                if (find(i) == true)
                {
                    used[m] = i;
                    conclusion[l] = rule[i,0];
                    if (conclusion[l] >= 25)
                    {
                        return fact[conclusion[l]];
                    }
                    l++;
                    m++;
                }
            }
            return "未知动物";
        }

        /*知识匹配*/
        public bool find(int a)
        {
            int i, j, temp;
            int flag = 0;
            for (i = 1; i < 6; i++)
            {
                if (rule[a,i] == 0)
                {   
                    break;
                }
                for (j = 0; j < 10; j++)
                {
                    if (factList[j] == 0)
                    {
                        break;
                    }
                    if (rule[a,i] == factList[j])
                    {
                        flag++;
                        break;
                    }
                    else
                    {  
                        continue;
                    }
                }

                if (flag != i)
                {
                    for (j = 0; j < 10; j++)
                    {
                        if (conclusion[j] == 0)
                        {
                            break;
                        }
                        if (rule[a, i] == conclusion[j])
                        {
                            flag++;
                            if (flag == i)
                                break;
                        }
                        else
                        {
                            continue;
                        }
                    }
                }
            }
            if (flag == i-1)
            {
                return true;
            }
            return false;
        }

        /*解释(没有除去相同的规则)*/
        public void report()
        {
            int i,j;
            int m;
            string s = "";
            for (i = 0; i <= 15; i++)
            {
                if (used[i] == 0)
                    break;
                else
                {
                    for (j = 0; j < 6; j++)
                    {
                        m=rule[used[i], j];
                        if (m == 0)
                            break;
                        else
                        {
                            if (j == 0)
                            {
                                s = ",所以此动物是" + fact[m];
                            }
                            else
                            {
                                s =fact[m]+s;
                            }
                        }
                            
                    }
                    lb.Items.Add(s);
                } 
            }
        }

    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -