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

📄 smain.~pas

📁 用delphi编写的人工智能中的过河问题的源码
💻 ~PAS
📖 第 1 页 / 共 2 页
字号:
//********************************
// Author : Li Jiazhou
// Date : 2004-12-12
// Description : Please look at Qution 2.10 at Page 72 on
//    <<人工智能原理及其应用>>/王万森/电子工业出版社/2000.9
//*******************************
unit SMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, Buttons, ComCtrls;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Panel2: TPanel;
    Panel3: TPanel;
    Label1: TLabel;
    GroupBox1: TGroupBox;
    Panel4: TPanel;
    Panel5: TPanel;
    Panel6: TPanel;
    sbLM1: TSpeedButton;      // SpeedButton of No.1 Left Missionary
    sbLM2: TSpeedButton;      // SpeedButton of No.2 Left Missionary
    sbLM3: TSpeedButton;      // SpeedButton of No.3 Left Missionary
    sbLC1: TSpeedButton;      // SpeedButton of No.1 Left Cannibal
    sbLC2: TSpeedButton;      // SpeedButton of No.2 Left Cannibal
    sbLC3: TSpeedButton;      // SpeedButton of No.3 Left Cannibal
    sbRM1: TSpeedButton;      // SpeedButton of No.1 Right Missionary
    sbRM2: TSpeedButton;      // SpeedButton of No.2 Right Missionary
    sbRM3: TSpeedButton;      // SpeedButton of No.3 Right Missionary
    sbRC1: TSpeedButton;      // SpeedButton of No.1 Right Cannibal
    sbRC2: TSpeedButton;      // SpeedButton of No.2 Right Cannibal
    sbRC3: TSpeedButton;      // SpeedButton of No.3 Right Cannibal
    sbB1: TSpeedButton;       // SpeedButton of Position 1 in Boat
    sbB2: TSpeedButton;       // SpeedButton of Position 2 in Boat
    GroupBox2: TGroupBox;
    RichEdit1: TRichEdit;
    GroupBox3: TGroupBox;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    RichEdit2: TRichEdit;
    Button4: TButton;
    SaveDialog1: TSaveDialog;
    procedure Button3Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation
var
   LeftM, LeftC : Integer;    // amount of Missionary、Cannnibal in Left Bank
   RightM, RightC : Integer;  // amount of Missionary、Cannnibal in Right Bank
   BoatM, BoatC : Integer;    // amount of Missionary、Cannnibal in Boat

{$R *.dfm}

// Initial the Data
procedure Initial;
begin
   LeftM := 3;    LeftC := 3;
   RightM := 0;   RightC := 0;
   BoatM := 0;    BoatC := 0;
end;

// Display the instance of the Left Bank
procedure DispLeftBank(m : Integer; c : Integer);
begin
   // display the instance of Missionaries
   with Form1 do
   case m of
      0:
      begin
         sbLM1.Caption := '';    sbLM1.Flat := True;
         sbLM2.Caption := '';    sbLM2.Flat := True;
         sbLM3.Caption := '';    sbLM3.Flat := True;
      end;
      1:
      begin
         sbLM1.Caption := '修';  sbLM1.Flat := False;
         sbLM2.Caption := '';    sbLM2.Flat := True;
         sbLM3.Caption := '';    sbLM3.Flat := True;
      end;
      2:
      begin
         sbLM1.Caption := '修';  sbLM1.Flat := False;
         sbLM2.Caption := '修';  sbLM2.Flat := False;
         sbLM3.Caption := '';    sbLM3.Flat := True;
      end;
      3:
      begin
         sbLM1.Caption := '修';  sbLM1.Flat := False;
         sbLM2.Caption := '修';  sbLM2.Flat := False;
         sbLM3.Caption := '修';  sbLM3.Flat := False;
      end;
      else
         ShowMessage('Missionary Infomation error in Left Bank');
   end;
   // display the instance of Cannibals
   with Form1 do
   case c of
      0:
      begin
         sbLC1.Caption := '';    sbLC1.Flat := True;
         sbLC2.Caption := '';    sbLC2.Flat := True;
         sbLC3.Caption := '';    sbLC3.Flat := True;
      end;
      1:
      begin
         sbLC1.Caption := '野';  sbLC1.Flat := False;
         sbLC2.Caption := '';    sbLC2.Flat := True;
         sbLC3.Caption := '';    sbLC3.Flat := True;
      end;
      2:
      begin
         sbLC1.Caption := '野';  sbLC1.Flat := False;
         sbLC2.Caption := '野';  sbLC2.Flat := False;
         sbLC3.Caption := '';    sbLC3.Flat := True;
      end;
      3:
      begin
         sbLC1.Caption := '野';  sbLC1.Flat := False;
         sbLC2.Caption := '野';  sbLC2.Flat := False;
         sbLC3.Caption := '野';  sbLC3.Flat := False;
      end;
      else
         ShowMessage('Cannibal Information error in Left Bank');
   end;
end;

// Display the instance of the Right Bank
procedure DispRightBank(m : Integer; c : Integer);
begin
   // display the instance of Missionaries
   with Form1 do
   case m of
      0:
      begin
         sbRM1.Caption := '';    sbRM1.Flat := True;
         sbRM2.Caption := '';    sbRM2.Flat := True;
         sbRM3.Caption := '';    sbRM3.Flat := True;
      end;
      1:
      begin
         sbRM1.Caption := '修';  sbRM1.Flat := False;
         sbRM2.Caption := '';    sbRM2.Flat := True;
         sbRM3.Caption := '';    sbRM3.Flat := True;
      end;
      2:
      begin
         sbRM1.Caption := '修';  sbRM1.Flat := False;
         sbRM2.Caption := '修';  sbRM2.Flat := False;
         sbRM3.Caption := '';    sbRM3.Flat := True;
      end;
      3:
      begin
         sbRM1.Caption := '修';  sbRM1.Flat := False;
         sbRM2.Caption := '修';  sbRM2.Flat := False;
         sbRM3.Caption := '修';  sbRM3.Flat := False;
      end;
      else
         ShowMessage('Missionary Infomation error in Right Bank');
   end;
   // display the instance of Cannibals
   with Form1 do
   case c of
      0:
      begin
         sbRC1.Caption := '';    sbRC1.Flat := True;
         sbRC2.Caption := '';    sbRC2.Flat := True;
         sbRC3.Caption := '';    sbRC3.Flat := True;
      end;
      1:
      begin
         sbRC1.Caption := '野';  sbRC1.Flat := False;
         sbRC2.Caption := '';    sbRC2.Flat := True;
         sbRC3.Caption := '';    sbRC3.Flat := True;
      end;
      2:
      begin
         sbRC1.Caption := '野';  sbRC1.Flat := False;
         sbRC2.Caption := '野';  sbRC2.Flat := False;
         sbRC3.Caption := '';    sbRC3.Flat := True;
      end;
      3:
      begin
         sbRC1.Caption := '野';  sbRC1.Flat := False;
         sbRC2.Caption := '野';  sbRC2.Flat := False;
         sbRC3.Caption := '野';  sbRC3.Flat := False;
      end;
      else
         ShowMessage('Cannibal Information error in Right Bank');
   end;
end;

// Display the instance of the Boat
procedure DispBoat(m : Integer; c : Integer);
begin
   if ( m + c > 2 ) or ( m + c < 0 ) then
   begin
      ShowMessage('Information error in Boat');
      Exit;
   end;

   with Form1 do
   if (m = 2) and (c = 0) then
   begin
      sbB1.Caption := '修';   sbB1.Flat := False;
      sbB2.Caption := '修';   sbB2.Flat := False;
   end
   else if (m = 1) and (c = 1) then
   begin
      sbB1.Caption := '修';   sbB1.Flat := False;
      sbB2.Caption := '野';   sbB2.Flat := False;
   end
   else if (m = 1) and (c = 0) then
   begin
      sbB1.Caption := '修';   sbB1.Flat := False;
      sbB2.Caption := '';     sbB2.Flat := True;
   end
   else if (m = 0) and (c = 0) then
   begin
      sbB1.Caption := '';     sbB1.Flat := True;
      sbB2.Caption := '';     sbB2.Flat := True;
   end
   else if (m = 0) and (c = 1) then
   begin
      sbB1.Caption := '野';   sbB1.Flat := False;
      sbB2.Caption := '';     sbB2.Flat := True;
   end
   else if (m = 0) and (c = 2) then
   begin
      sbB1.Caption := '野';   sbB1.Flat := False;
      sbB2.Caption := '野';   sbB2.Flat := False;
   end;
end;

⌨️ 快捷键说明

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