ñòð. 103 |

small, medium, large.\n" ;

message "<string>" ;

prule r0 ;

fire block 1 off ;

message â€™Here are the membership functions for fuzzy set

size:\nâ€™ ;

drawmemf Data size ;

message â€™Ready to run\nâ€™ ;

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

300 APPENDIX

:run ;

:message â€™Fuzzification demonstration finished.\nâ€™ ;

:exit ;

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

Guess.fps: try to guess a number.

declare Guess

x int ;

:rule r0

rule (goal Guess too low)

IF (x < 6)

THEN

write "Your guess is too low - guess again\n",

delete 1;

:rule r1

rule (goal Guess too high)

IF (x > 6)

THEN

write "Your guess is too high guess again\n",

delete 1;

:rule r2

rule (goal Guess correct - stop)

IF (x = 6)

THEN

write "Your guess is correct! Thanks for the game\n",

stop;

:rule r3

rule (goal Input guess)

IF (x = 0)

THEN

write "What is your guess for the number ?\n",

read 1 x;

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

:program HANOI.FPS - 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)

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

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

301

APPENDIX

message "Loading program hanoi.fps...\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

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

:rule r0

rule rconf 0 ( goal Inputs number of disks to move )

IF ( in Spindles n.cf = 0 )

THEN

reset,

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

quit)?\n" 1 n ,

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

:rule r1

rule rconf 1000 (goal Quits on zero numbers of disks to

move )

IF ( in Spindles n = 0 )

THEN

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

exit ;

:rule r2

rule rconf 1000 ( goal Fires if only one disk to move )

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

THEN

reset ,

write 12 "*** move <S> to <D> ***\n" ,

delete 1 ;

:rule r3

rule rconf 999 (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

reset ,

:save Spindles for return to rule 4 later

in 1 rtn = 2 ,

:first recursive call

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

302 APPENDIX

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

t = "<D>" rtn = 1;

:rule r4

rule rconf 999 ( goal Fires after r3 if NDisk > 1to 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 12 "*** move <S> to <D> ***\n" ,

:second recursive call

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

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

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

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

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 +

"with the largest at the bottom. \n" ;

string +

"The problem is to move the disks from spindle #1 to #3\,";

string +

"one disk at a time, never placing a larger disk on a

ñòð. 103 |