Hangman Pro

From UBC Wiki

Authors: Brian Ho, Daniel Shirvani

haha, get it? hangman pro(log)

What is the problem?

Winning in Hangman
Losing in Hangman

As the name suggests, Hangman Pro is a hangman game built on Prolog. The problem is building an interactable UI on a logical programming framework seems difficult. But.. how could we know without trying! We wanted to find out if we can leverage the logical programming features that are baked into Prolog in order to design a user interface and "logic engine" for Hangman.

What is the something extra?

One of the main challenges in creating GUIs with Prolog is that Prolog is a declarative language, which means that it is designed to express relationships and rules rather than imperative instructions. This can make it difficult to write procedural code for handling user interface events such as button clicks or mouse movements. For this reason, we built a command-line interface for Hangman using Prolog. To implement more variability to users, we added options to create and input ASCII art into the game and modify survival rules. To add even more customization, we created a system that allows the use of JSON files in the game. The setup we designed allows users to customize a JSON file titled `words.json`. The game automatically pulls Hangman words from this JSON file randomly. Thus, users have the flexibility to modify the game however they want *without* having to ever even open the codebase. I would like to add, that we also built a derivative of the project using the XQuartz-intergrated PCE library for Prolog. Building this project using PCE was not feasible, for reasons we will describe below. Overall, we explored all possible extra avenues that were possible using this domain model in order to make an awesome project.

What did we learn from doing this?

To put it bluntly, relative to other programming languages, the Prolog community is tiny. This unfortunately reflects in the amount (or lack thereof) of documentation and useful examples present in Prolog, especially for libraries such as XPCE. We researched into how XPCE words. It is essentially a virtual machine that runs PCE and interfaces with Prolog in order to allow Prolog users to write GUIs. However, this requires the use of a platform like XQuartz (or X.org) in order to run. We ran into two problems during the development of our XPCE system; one small, one big. The first (small) problem was that our project, by nature, requires lots of data transfer and processing, namely for formatting reasons. Now, that's normal for a programming project. But, the way that we would format/process text in order to display it (i.e. placing spaces between underscores) would lead to data objects that were not equivalent to those would be displayed in XPCE. Type errors would occur for data that is seemingly of the same type, even when we specified types (We still don't know how to properly elucidate this issue). Looking into this problem it seemed like others had run into similar issues, but given the smaller Prolog community, we couldn't find a reasonable solution. Nonetheless, could this have been worked through? Sure. But... problem #2: the use of XQuartz. XQuartz would consistently crash even with very simple user interfaces. This was between devices as well. This made planning, testing, and building our project ontop of the XPCE library unfeasible. So, we stuck to a command-line interface and instead chose to allow high-levels of user customizability to make up the inability of XQuartz-PCE to run smootly. I was surprised to see XPCE is still highly maintained to date, even with its ancient framework. Prolog might not be the best software to use for GUIs. But, on a positive note, building Hangman into a customizable system was a pleasure using the Prolog binding system. It made our code very readable and easy to implement. That should come across in our demo! We will show you what we developed in XPCE and in our CLI tool!

Demo of XPCE and Hangman

Links to Code

https://github.com/briantkho/HangmanPro