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

📄 form1.frm

📁 人工智能课程 产生式部分的一个实验设计:用产生式解决“过河问题”
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "产生式系统演示:传教士和野人过河问题"
   ClientHeight    =   6540
   ClientLeft      =   165
   ClientTop       =   735
   ClientWidth     =   7875
   LinkTopic       =   "Form1"
   ScaleHeight     =   6540
   ScaleWidth      =   7875
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton Command3 
      Caption         =   "生成规则库"
      Height          =   375
      Left            =   3120
      TabIndex        =   14
      Top             =   360
      Width           =   1335
   End
   Begin VB.Frame Frame1 
      Caption         =   "初始条件设置:"
      Height          =   1695
      Left            =   120
      TabIndex        =   7
      Top             =   120
      Width           =   2895
      Begin VB.TextBox Text6 
         Alignment       =   1  'Right Justify
         Appearance      =   0  'Flat
         Height          =   375
         Left            =   2160
         TabIndex        =   13
         Text            =   "2"
         Top             =   1200
         Width           =   495
      End
      Begin VB.TextBox Text5 
         Alignment       =   1  'Right Justify
         Appearance      =   0  'Flat
         Height          =   375
         Left            =   2160
         TabIndex        =   11
         Text            =   "3"
         Top             =   720
         Width           =   495
      End
      Begin VB.TextBox Text4 
         Alignment       =   1  'Right Justify
         Appearance      =   0  'Flat
         Height          =   390
         Left            =   2160
         TabIndex        =   9
         Text            =   "3"
         Top             =   240
         Width           =   495
      End
      Begin VB.Label Label5 
         Caption         =   "渡船容量(1-9)人:"
         Height          =   255
         Left            =   240
         TabIndex        =   12
         Top             =   1320
         Width           =   1815
      End
      Begin VB.Label Label4 
         Caption         =   "野蛮人人数(1-9)人:"
         Height          =   375
         Left            =   240
         TabIndex        =   10
         Top             =   840
         Width           =   2055
      End
      Begin VB.Label Label3 
         Caption         =   "传教士人数(1-9)人:"
         Height          =   375
         Left            =   240
         TabIndex        =   8
         Top             =   360
         Width           =   1935
      End
   End
   Begin VB.Timer Timer1 
      Enabled         =   0   'False
      Interval        =   800
      Left            =   4920
      Top             =   0
   End
   Begin VB.CommandButton Command2 
      Caption         =   "开始自动推理"
      Height          =   375
      Left            =   3120
      TabIndex        =   6
      Top             =   840
      Width           =   1335
   End
   Begin VB.TextBox Text3 
      Appearance      =   0  'Flat
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   15
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   6240
      TabIndex        =   4
      Text            =   "Text1"
      Top             =   1320
      Width           =   855
   End
   Begin VB.TextBox Text2 
      Appearance      =   0  'Flat
      Height          =   855
      Left            =   120
      MultiLine       =   -1  'True
      TabIndex        =   3
      Text            =   "Form1.frx":0000
      Top             =   5640
      Width           =   6615
   End
   Begin VB.PictureBox Picture1 
      Height          =   3615
      Left            =   120
      ScaleHeight     =   3555
      ScaleWidth      =   6555
      TabIndex        =   1
      Top             =   1920
      Width           =   6615
   End
   Begin VB.TextBox Text1 
      Appearance      =   0  'Flat
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   15
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   5040
      TabIndex        =   0
      Text            =   "Text1"
      Top             =   600
      Width           =   1095
   End
   Begin VB.Label Label2 
      Caption         =   "已走步数"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   15
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   615
      Left            =   4920
      TabIndex        =   5
      Top             =   1080
      Width           =   855
   End
   Begin VB.Label Label1 
      Caption         =   "黑板情况:"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   15
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   5520
      TabIndex        =   2
      Top             =   0
      Width           =   1575
   End
   Begin VB.Menu M问题描述 
      Caption         =   "问题描述"
   End
   Begin VB.Menu M退出 
      Caption         =   "退出"
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private WithEvents a1 As ProdSys
Attribute a1.VB_VarHelpID = -1


Private Sub Command2_Click()
    a1.go
End Sub

Private Sub Command3_Click()
    a1.CreatRuleBase Val(Right(Text4.Text, 1)), Val(Right(Text5.Text, 1)), Val(Right(Text6.Text, 1)), 1
    a1.blackboard = a1.StateB
    draw (a1.blackboard)
End Sub

Private Sub Form_Activate()
    draw (a1.blackboard)
    Text1.Text = a1.blackboard
End Sub

Private Sub Form_Load()
Dim i As Integer
    
    Set a1 = New ProdSys
    
End Sub

Private Sub draw(s As String)
    Dim iMonker, iVayaer, iShip, i, iMonCoun, iVayCoun As Integer
    iMonker = Val(Left(s, 1))       '获取当前黑板情况
    iVayaer = Val(Mid(s, 2, 1))
    iShip = Val(Right(s, 1))
    
    iMonCoun = a1.MonCount    '参加过河的传教士和野人的总数
    iVayCoun = a1.VayCount
   
    '位置控制变量
    Dim r, h, w, LeftBegin, TopBegin, boldWidth As Integer
    r = 200
    h = 2 * r + 80
    w = 2 * r + 80
    LeftBegin = r + 100
    TopBegin = r + 100
    boldWidth = 10
             
    With Picture1
        .Cls
        .DrawWidth = boldWidth
                
        '河左岸情况
        For i = 0 To iMonker - 1
            Picture1.Circle (LeftBegin + i * w, TopBegin), r, vbRed
        Next
        For i = 0 To iVayaer - 1
            Picture1.Circle (LeftBegin + i * w, TopBegin + h), r, vbGreen
        Next
        '船只
        If iShip = 1 Then
            Picture1.Circle (LeftBegin + i * w, TopBegin + h * 2), r, vbBlue, , , 5 / 25
        Else
            Picture1.Circle (LeftBegin + i * w, TopBegin + h * 4), r, vbBlue, , , 5 / 25
        End If
        '画河水
        Picture1.Line (LeftBegin - r, TopBegin + h * 3)-(LeftBegin + r + w * 10, h * 3 + r), 4, BF
        '河右案情况
        For i = 0 To iMonCoun - iMonker - 1    '传教士有3人
            Picture1.Circle (LeftBegin + i * w, TopBegin + h * 5), r, vbRed
        Next
        For i = 0 To iVayCoun - iVayaer - 1    '野人有3人
            Picture1.Circle (LeftBegin + i * w, TopBegin + h * 6), r, vbGreen
        Next
    End With
End Sub

Private Sub M退出_Click()
    Set a1 = Nothing
    Unload Me
End Sub

Private Sub M问题描述_Click()
    MsgBox "      设有N个传教士和N个野人同在河的左岸,他们都要到对岸去;河里只有一条船,他们都会划船,但每次渡船至多只能乘M人;如果在任何一边河岸上,野人的数量超过传教士,野人就要吃掉传教士,问怎样才能用船将3个传教士和3个野人从左岸都渡到右岸,又不会发生传教士被吃的事件呢?   ", vbOKOnly, "问题描述:"
End Sub

Private Sub Timer1_Timer()
    If a1.flagSucess Then Timer1.Enabled = False
    Call Command1_Click
End Sub

Private Sub a1_go1step()
    MsgBox "asdf"
    Text1.Text = a1.blackboard
    Text3.Text = a1.StepCount
    draw (a1.blackboard)
End Sub

⌨️ 快捷键说明

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