ñòð. 104 |

string +

"HANOI will solve this problem recursively, in that

rules ";

string +

"make themselves refireable until a desired state is ";

string +

"reached. Rule weights ensure that rules fire in the ";

string +

"proper sequence. HANOI.FPS has one rule for input,";

string +

" one to quit, and only three to solve the problem. \n" ;

message "<string>" ;

message "Ready to run...\n" ;

:run ;

TEAM LinG - Live, Informative, Non-cost and Genuine !

303

APPENDIX

: ******************************************************

:program HANOI.PAR - solves Tower of Hanoi problem

recursively

:uses rule confidences to control rule firing sequence ;

:if rule r2 and rule r4 concurrently fireable, r2 fires

first.

:(rule confidences override normal MEA algorithm for

sequencing rules)

: ******************************************************

message "Loading program hanoi.par...\n" ;

declare Spindles

n int :number of disks to be moved

s str :source spindle

d str :destination spindle

t str :temporary spindle

rtn int ; :pointer for rule(s) to be executed next

declare True;

: ******************************************************

:rule r0

rule (goal Declares itself in parallel mode, enables

block 1, switches to serial mode)

IF (True)

THEN

message "First rule firing, block 0 - mode parallel.\n

Switching to serial mode",

fire block 0 off,

fire block 1 on,

serial;

:rule r1

rule rconf 0 block 1 (goal Inputs number of disks to

move)

IF (in Spindles n.cf = 0)

THEN

reset,

input "r0 - Tower of Hanoi - how many disks to move (0

to quit)?\n" 1 n,

make Spindles s = "S1" t = "S2" d = "S3" rtn = 1,

debug 4;

TEAM LinG - Live, Informative, Non-cost and Genuine !

304 APPENDIX

:rule r2

rule block 1 (goal Quits on zero numbers of disks to

move)

IF (in Spindles n = 0)

THEN

message nocancel "r1 - Thanks for the game.\n",

fire block 1 off,

fire block 2 on,

parallel;

:rule r3

rule block 1 (goal Fires if only one disk to move)

IF (in Spindles n = 1 AND s = <S> AND d = <D>)

THEN

reset,

write "r2 - move <S> to <D>\n",

delete 1;

:rule r4

rule rconf 999 block 1 (goal Fires if NDisk > 1\; makes

r2 or r4 fireable)

IF (in Spindles n > 1 AND n = <N> AND s = <S> AND d = <D>

AND t = <T>

AND rtn = 1)

THEN

debug 0,

reset,

write "r3 - modifying Spindles\n",

:save Spindles for return to rule 4 later

in 1 rtn = 2,

:first recursive call

make Spindles n = (<N> - 1) s = "<S>" d = "<T>"

t = "<D>" rtn = 1;

:rule r5

rule rconf 999 block 1 (goal Fires after r3 if NDisk > 1

to move - recursive)

IF (in Spindles n = <N> AND n > 1 AND s = <S> AND d = <D>

AND t = <T> AND rtn = 2)

THEN

reset,

write "r4 - move <S> to <D>\n",

:second recursive call

in 1 n = (<N> - 1) s = "<T>" d = "<D>" t = "<S>" rtn = 1;

TEAM LinG - Live, Informative, Non-cost and Genuine !

305

APPENDIX

:rule r6

rule block 2 (goal Announce return to parallel mode)

IF (True)

THEN

message "Back to parallel mode in block 2";

halt;

: ******************************************************

make Spindles s = "S1" t = "S2" d = "S3" rtn = 1;

make True;

: ******************************************************

string =

"We have some disks of different diameters with holes ";

string +

"bored through the center, and three vertical spindles. ";

string +

"The disks are loaded onto one spindle in order of

size, ";

string +

ñòð. 104 |