duckworld - prolog sample

Duck World is is described in the Quick Tutorial of the Amzi! Prolog reference. It is a simple application used to demonstrate how to implement complex applications. Accordingly, it is composed of a number of files.

The game:

Duck World is a simple adventure game, where the objective is to go from the house, through the yard, to the duck pen to get an egg, and back to the house again, without losing any ducks to the fox.

Once started, Duck World provides a '>>' prompt at which you enter commands in the format of legal Prolog goals (ending in periods). The commands are:

The game continues until you get the egg back to the house.

The source files are:

To run Duck World from the listener:

  alis
  ?- consult([duck1, duck2]).
  yes
  ?- main.
   Welcome to Duck World
   Go get an egg
  >>

Enter commands at the >>.

To compile Duck World:

  acmp duck1
  acmp duck2

The file ducks.pro has the directives to load both modules

  :- load(duck1).
  :- load(duck2).

To run the compiled modules:

  alis ducks
    Welcome to Duck World...

(Note, the above examples are only suggestions. The compiled .plm files can be loaded from the listener, and the source .pro files can be automatically consulted and run by listing them on the alis command line.)

You can also link the two modules together and create a stand-alone executable for running the program and run it using the arun command:

  alnk ducks duck1 duck2
  arun ducks
    Welcome to Duck World...

You can make a copy of arun(.exe) and name it ducks to have a stand-alone executable:

  copy \amzi\bin\arun.exe ducks.exe (windows)
  cp /amzi/bin/arun ducks   (unix)

Now the program can be run simply by typing ducks.

There is a makefile that can be used to create ducks.xpl.

There is also a single file version of the program in ducky.pro, designed for use from the interpreter.