Dec 232017
 
Source and Exe's for three Turbo Prolog programs which are detailed in the book "Advanced Turbo Prolog" by Herbert Schildt. Includes classic farmer, chicken and fox program as well as a Robot simulator.
File PROLOG3.ZIP from The Programmer’s Corner in
Category Miscellaneous Language Source Code
Source and Exe’s for three Turbo Prolog programs which are detailed in the book “Advanced Turbo Prolog” by Herbert Schildt. Includes classic farmer, chicken and fox program as well as a Robot simulator.
File Name File Size Zip Size Zip Type
FARMER.DOC 3860 1559 deflated
FARMER.EXE 45245 23968 deflated
FARMER.PRO 5064 1073 deflated
NLP.DOC 1674 751 deflated
NLP.EXE 42962 23165 deflated
NLP.PRO 3217 934 deflated
ROBOT.DOC 3471 1426 deflated
ROBOT.EXE 58398 28506 deflated
ROBOT.PRO 13552 2814 deflated

Download File PROLOG3.ZIP Here

Contents of the FARMER.DOC file



This routine is taken from and fully documented in:

ADVANCED TURBO PROLOG Version 1.1
Herbert Schildt
Borland-Osborne/McGraw-Hill
Berkeley CA 94710
Copyright 1987


The essence of the problem is as follows :
- A farmer must cross a river with three items.
- His boat can only hold himself and one item.
- If the fox and chicken are left alone, the fox will eat the
chicken.
- If the chicken and grain are left alone, the chicken will
eat the grain.
- What is the sequence of moves the farmer must make in order
to transport all across the river?


This program requires a CGA color card or better.

The function of the first predicate, "move", is
precisely what the name implies. The moves of the farmer and
whatever else he has in the boat across the river are
accomplished using the three move clauses. The first will
animate the farmer himself. The second will perform the
actual work of checking the leftbank, taking one of the items
to be moved, and transporting it to the other side. The other
move clause is needed in order to return an item back to the
rightbank. This would be needed in what is termed an illegal
situation where two items must not be left alone together. At
this time one item must be returned to the rightbank with the
farmer.
The next predicate listed is "legal". The clauses which
use it are basically rules to determine if two items can be
left alone on one bank of the river. These clauses are very
straightforward and easy to understand from the rules of the
puzzle itself. With three items, there are only three
different possible sets of two which can be together on a
side :

SETS CONSEQUENCES ? LEGAL ?

Fox & grain NONE YES
Fox & chicken FOX EATS CHICKEN NO
Chicken & grain CHICKEN EATS GRAIN NO

Thus, the only safe or legal combination alone for either
side is the fox and the grain.

"Crossed_river" performs the function of recognizing
when all items desired to be moved are actually across the
river. It checks the leftbank for the chicken, fox and grain
and if all are present, prints an appropriate message.
The remainder of the predicates deal expressly with
creating the graphics routines required for setup, initial
positions, and movement of the items which must make the
crossing. "River" constitutes the routines needed to produce
the river on the video screen. "Setup" draws the river, the
farmer and the three items to be moved. "Sail" initializes
the items for the crossing by positioning them on the
appropriate bank. "Transportleft" and "transportright"
produces the video effect of the item actually crossing the
river from one side or the other. This is accomplished by
successively writing the item name in one position, erasing
it, and writing it again in an advanced position. Finally,
two routines control the farmer's placement. "Checkfarmer",
which is not a graphics routine, is needed to check the
position of the farmer when he needs to be moved by himself.
This is applicable when he has just transported the first
item to the left side and now needs to return for the second.
Since the item on the leftbank is alone, no unsafe conditions
are possible. After this, he will always transport one item
back to the right with him in order to avoid illegal
situations. "Movefarmer" is the graphics routine for this
special circumstance action.


 December 23, 2017  Add comments

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)