ñòð. 113 |

:rule r0

rule (goal Get numbers of missionaries = cannibals, max

boat will hold)

IF (in Max miss.cf = 0)

THEN

cls ,

input "Enter number miss (= # cann)" 1 miss ,

input "Enter max in boat" 1 boat ;

:rule r1

rule 999 (goal Get total number of people, initialize

people on banks, boat)

IF (in Max miss = <M> AND total.cf = 0)

THEN

reset ,

write â€™rule r1 - initializing\nâ€™ ,

in 1 cann = <M> total = (2 * <M>) ,

make Boat miss = 0 cann = 0 total = 0 state = "L",

make Left miss = <M> cann = <M> total = (2 * <M>) ,

make Right miss = 0 cann = 0 total = 0 ;

: ++++++++++++++++++++++++++++++++++++++++++++++++++++++

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

329

APPENDIX

: LOAD BOAT LEFT

:rule r2

rule 0 (goal Loading boat from left - first load a

missionary)

IF ( in Boat miss = 0 AND cann = 0 AND state = "L")

( in Left miss = <LM> AND total = <LT>)

THEN

reset ,

write â€™rule r2 - loading first missionary on left\nâ€™ ,

in 1 miss = 1 total = 1 ,

in 2 miss = (<LM> - 1) total = (<LT> - 1) ;

:rule r3

rule 0 (goal Load another missionary on left)

IF (in Max boat <MX>)

(in Left miss = <LM> AND cann = <LC> AND miss > 0 AND

total = <LT>)

(in Boat state = "L" AND miss = <BM> AND cann = <BC>

AND total = <BT>

AND miss > 0 total < <MX>)

THEN

reset ,

write â€™rule r3 - loading missionary on left\nâ€™ ,

in 2 miss = (<LM> - 1) total = (<LT> - 1) ,

in 3 miss = (<BM> + 1) total = (<BT> + 1) ;

:rule r4

rule (goal Load a cannibal on left)

IF ( in Max boat <MX>)

( in Left miss = <LM> AND cann = <LC> AND cann > 0 AND

total = <LT>)

( in Boat state = "L" AND miss = <BM> AND cann = <BC>

AND total = <BT>

AND miss > 0 AND total < <MX>)

THEN

reset ,

write â€™rule r4 - loading cannibal on left\nâ€™ ,

in 2 cann = (<LC> - 1) total = (<LT> - 1) ,

in 3 cann = (<BC> + 1) total = (<BT> + 1) ;

: ------------------------------------------------------

: CHECK READY TO SAIL FROM LEFT BANK

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

330 APPENDIX

:rule r5

rule 999

(goal Missionaries >= cannibals on left\, shore and

boat-ready to sail)

IF ( in Max boat <MX>)

( in Boat state = "L" AND miss = <BM> AND cann = <BC>

AND total = <BT> AND miss >= <BC> AND total >= 2 AND

total <= <MX>)

( in Left miss = <LM> AND cann = <LC> AND total = <LT>

AND miss >= <LC>)

THEN

reset ,

write â€™Boat holds miss <BM> cann <BC> total <BT>\nâ€™ ,

write â€™leaving miss <LM> cann <LC> total <LT>\nâ€™ ,

message â€™rule r5 - ready to sail from left\nâ€™ ,

in 2 state = "LR",

in 3 total = <LT> ;

:rule r6

rule 999 (goal Miss 0 on shore miss >= cann on boat,

ready to sail from left)

IF ( in Max boat <MX>)

( in Boat state = "L" AND miss = <BM> AND cann = <BC>

AND total = <BT> AND miss >= <BC> AND total >= 2 AND

total <= <MX>)

( in Left miss = 0 AND cann = <LC> AND total = <LT>)

THEN

reset ,

write â€™Boat holds miss <BM> cann <BC> total <BT>\nâ€™ ,

write â€™leaving miss 0 cann <LC> total <LT>\nâ€™ ,

message â€™rule r6 - ready to sail from left\nâ€™ ,

in 2 state = "LR";

: SEE IF NEED TO BACKTRACK

: if backtracking is necessary, forget it: delete boat, left

:rule r7

rule (goal Missionaries < cannibals, <> 0 on shore, boat

up to max, backtrack)

IF ( in Max boat <MX>)

( in Boat state = "L" AND total = <MX>)

( in Left cann = <LC> AND miss < <LC> AND miss > 0)

THEN

warning â€™rule r7 - miss will get eaten on left on

shore\, backtracking\nâ€™ ,

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

331

APPENDIX

delete 2 ,

delete 3 ;

:rule r8

rule (goal Miss < cann, <> 0 in boat, boat up to max,

backtrack)

IF ( in Max boat <MX>)

( in Boat state = "L" AND cann = <BC> AND miss < <BC>

AND total = <MX>)

( in Left TT <TT>)

THEN

warning â€™rule r8 - miss will get eaten on left in

ñòð. 113 |