Duckworld - Prolog Sample

Duck World is described in the Quick Tutorial of the Amzi! Prolog User's Guide and 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:

There is also a single file version which has all of the code in one file. It is duckym.pro.

Command Line

To run Duck World from inside the listener:

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

Enter commands at the >>.

To compile Duck World from the command line:

  acmp dw_main
  acmp dw_rules
  acmp dw_data

To link and then run from the command line:

  alnk dw dw_main dw_rules dw_data
  arun dw
    Welcome to Duck World...

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

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

Now the program can be run simply by typing dw.

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

Windows IDE

To make a project in the Windows IDE:

  File/New Project
  xpl file: dw.xpl
  directory: the duckworld sample directory on your machine
  add files: dw_main.pro dw_rules.pro dw_data.pro
  File/Save As: dw.ppj

To run the project in the listener:

  listener/start or LIS button
  listener/reconsult or Re button
  ?- main.   % runs the program in the listener
  ...
  ?- quit.   % exits the listener

To compile, link and run the project:

  click the BLD button
  click the RUN button

Close the project and IDE.