As I described in my previous post, I am reviewing functional programming patterns that can be used to augment a traditional Java application.
In the late 1980’s I played with the Prolog language (Programming with Logic). As its name implies, Prolog is a logic programming language; logic programming shares many concepts and styles with pure functional programming. (More on the distinctions in a future post.)
I studied Prolog by writing some games for the HP-95 MS-DOS handheld computer. The development environment was Borland’s Turbo Prolog. One nice feature of Turbo Prolog that worked well for game programming was a overlapping text window “GUI” library. This library supported pop-up menus that could be keyboard-navigated with arrow keys and the Enter or Esc keys.
In the mid 1990’s I played with the Java language. As part of my learning, I became involved in a pair of open source Prolog implementations written in Java. My favorite of these implementations was tuProlog (also known as 2p) from the University of Bologna.
I adapted my Turbo Prolog version of a two-card draw poker game known as Hurricane Poker to run in the tuProlog/Java environment. This implementation is in the public domain and is available for download from this web folder: Hurricane Poker on SkyDrive
To run the game as a Java applet, download the HurricanePokerApplet.zip file and expand it. Then double-click on the HurricanePoker.html file to open it in your default browser. The rules of the game appear, and a link at the top of the page will launch the Java applet. If you have a standard Java installation you can also double-click on the HurricanePoker.jar file to run it as a Java application.
You can download the Java and Prolog source code as HurricanePoker.zip Expand this ZIP file and then copy the resulting folder into your Eclipse workspace as a preconfigured project. To build and run the project in Eclipse, you will also need to download the 2p-2.2.zip file; expand it and copy the resulting folder into your Eclipse workspace as another project beside the HurricanePoker folder. (Note that this 2p-2.2.zip file is subject to the LGPL license.)
I plan to discuss the integration of Prolog and Java in the tuProlog environment in a future post.