Thursday, January 7, 2010

Hunt the Wumpus, (evoke), Wumpus Noir, and Wumpus Intergalactica

Hello world,

Now that the hubbub of xmas has passed, I've found a few moments to upload the four versions of Hunt the Wumpus that I mentioned in my pre-xmas post.

Hunt the Wumpus is an old computer game, originally text-based when it came out in the 70s. During my last programming subject at uni - CSCI337 The organisation of programming languages - we had four assignments in which we were to develop Hunt the Wumpus using a different programming language and programming paradigm each time.

I just signed up to MediaFire and uploaded my files and so I'll explain how to run each one in a Linux environment like Ubuntu. You will have to download a couple of packages (as I will instruct) for my games if you do not already have them installed. These games should all also run in a Unix environment and in some cases will do so more easily, but I will only give the instructions for Linux and those Unix users can figure out the differences themselves. :)

Scroll down to view each set of instructions in turn, or click on the name of the Hunt the Wumpus you're interested in below to jump to that one.


Hunt the Wumpus - Lisp (Functional paradigm)
This is basically the original game as from its creator (Gregory Yob), but programmed in Lisp rather than BASIC.

  1. Click on the name of the game above or click here to download the file. Choose to save it rather than open it in a text editor. Remember where you saved the file.

  2. Open terminal and navigate to the folder containing the file you just downloaded. You should be able to see ass3.lisp in the list of files in the current directory when you type ls at your terminal command line.

  3. In order to play the lisp version, you will need to download and install the clisp package. To do this, enter the following into your terminal command line and follow the prompts:
    sudo apt-get install clisp

  4. Now that you have clisp installed, run it by typing clisp into your terminal command line. The programme will display a header and all will be beautiful.

  5. Type (load "ass3.lisp") to load the game file.

  6. Type (wumpus) to start playing the game. Enjoy!

  7. After you have finished playing Hunt the Wumpus and have quit it, you will still be in clisp. To quit this, type (bye). You will be returned to the terminal command line interface.


Hunt the Wumpus (evoke) - Fortran (Imperative paradigm)
This follows the same narrative of the original game and the same rules/events/hazards, etc, but I rewrote the story to be a bit more evocative. Programmed in the dinosaur language Fortran77.

  1. Click on the name of the game above or click here to download the file. Choose to save it rather than open it in a text editor. Remember where you saved the file.

  2. Open terminal and navigate to the folder containing the file you just downloaded. You should be able to see wumpus.f in the list of files in the current directory when you type ls at your terminal command line.

  3. You will need to install the package gfortran, a fortran95 compiler. The assignment required me to programme in fortran77, unfortunately however Ubuntu does not support a fortran77 compiler like g77. Since fortran95 is an extension of fortran77, gfortran still correctly compiles g77 code - the problem that most of my fellow programmers had was that they used functionality that did not exist in 77 and so they lost marks for failure to compile.

    You need to type the following into your terminal command line and follow the prompts to get and install gfortran:
    sudo apt-get install gfortran


  4. Compile the wumpus.f file by entering the following into your terminal command line:
    gfortran wumpus.f

  5. Now when you type ls into your terminal command line it should list both wumpus.f and a.out. To run Hunt the Wumpus (evoke) type the following in at your terminal command line:
    ./a.out

  6. Enjoy the game! If you'd like to quit mid-game, use Ctrl+C.


Wumpus Noir - Literate C++ (Literate paradigm)
Here is where I start to make it a bit more fun! The Wumpus is now a mafia boss, and you are a detective on his tail. It was great, though my darling Karina pointed out after I'd finished that I'd consistently spelt labyrinth incorrectly the whole way though - 'labarynth'. Not to worry. Anyway, this one is using C++ and the literate programming paradigm, one that is very smart and really ought to be used all the time, in my opinion! It forces you to document your code, something which future programmers will thank you for.

Literate programming allows you to generate both a machine-compilable file and a human-readable pdf file from the original web file. I will give you instructions on how to generate both before running the game.

  1. Click on the name of the game above or click here to download the file. Choose to save it rather than open it in a text editor. Remember where you saved the file.

  2. Open terminal and navigate to the folder containing the file you just downloaded. You should be able to see wumpus.w in the list of files in the current directory when you type ls at your terminal command line.

  3. In order to process the wumpus.w file, you will need to install cweb. Click here to get cweb and install it as per the instructions.

  4. You will also need to download and install pdftex in order to generate a pdf. Click here to download and install it.

  5. Finally, you will need to install 'build-essential', which contains a number of essential development tools that are used for compiling C and C++ files. Type the following into your terminal command line and follow the prompts to get and install build-essential:
    sudo apt-get install build-essential

  6. Now we can get down to business! First, type the following into your terminal command line to prepare to create the pdf file:
    cweave wumpus.w

    This will have generated a collection of different files.

  7. To generate the final, readable pdf file, enter the following at your terminal command line:
    pdftex wumpus.tex

    You will now find a file called wumpus.pdf in your current directory which documents how I developed this particular version of the game.

  8. To generate the compilable version of the game, type the following into your terminal command line:
    ctangle wumpus.w

    This will create the file wumpus.c in your current directory.

  9. Since I work in C++, not C, you then need to convert this into a C++ source file. To do this, enter the following into your terminal command line:
    mv wumpus.c wumpus.cpp

  10. Nearly done. Now to compile the C++ source into an executable, enter the following:
    g++ wumpus.cpp -o wumpus.out

  11. To execute the final game file, type the following into your terminal command line:
    ./wumpus.out

  12. Enjoy! If you wish to exit mid-game, you can do so by pressing Ctrl+C.


Wumpus Intergalactica - Prolog (Logical paradigm)
Finally, we have the sci-fi variation. You are a bounty hunter off to neutralise the Wormhole Union of Marauders, Pirates and Unsavoury Scoundrels, aka the WUMPUS. Written in the very frustrating logic language Prolog. While nowhere near the insanity of Lisp, this language is tricky to get used to, and should be left for AI and not games.

  1. Click on the name of the game above or click here to download the file. Choose to save it rather than open it in a text editor. Remember where you saved the file.

  2. Open terminal and navigate to the folder containing the file you just downloaded. You should be able to see wumpus.P in the list of files in the current directory when you type ls at your terminal command line.

  3. You will need to download XSB in order to run this game. Click the link to go to their website and follow their instructions to download and install XSB. The game will run with XSB 2.6 and up. Remember where you unpacked the file to; I put mine on the Desktop.

  4. Now you need to run XSB without leaving the directory where you have wumpus.P saved. To do this you need to type the absolute address of the XSB executable into your terminal command line. The XSB executable will be located the the XSB folder you saved, in the bin subfolder, and it will be named 'xsb' (note the lower case). For example, to access my XSB, here is what I typed:
    $HOME/Desktop/XSB/bin/xsb

    Once you have opened XSB it will display its header in the terminal and you will be ready to load the prolog file.

  5. Load the wumpus.P file by typing the following:
    [wumpus].

    Don't forget the '.' at the end of the command, otherwise XSB will keep hanging, waiting for you to finish your command!

  6. Run the game by typing the following :
    go.

  7. Enjoy!

  8. In order to exit XSB once you have quit Wumpus Intergalactica, type the following:
    halt.

    You will be returned to the terminal command line interface.


And there you have it, four varieties of Hunt the Wumpus. I hope the sparse few who find this interesting enjoy playing my own personal spin on the game, and that those that stumble upon this in search of help with the programming languages used herein find the code useful to help them learn. :)

Just for funzies, I made an image to go with Wumpus Intergalactica. I actually made it because I was originally going to post the game files for download from deviantArt, and I wanted a thumbnail image for them, but I only made this one before I changed my mind and when with MediaFire. Anyway, here it is:

Wumpus Intergalactica image


I altered it a little so it would suit the narrow size of this blog post, but if you click on the image you can see the original 640x480px version.

~ Eyespiral

A note to all those would-be code plagiarisers: If you are planning on ripping off my code for the same class at UOW as I took, be warned - I don't doubt that Ian will remember these particular assignments. So be smart, and only use them to help you understand the languages and as a reference while you are building your own programmes. Toodloo!

1 comment:

  1. I loved this game as a kid. it's cool that you did this.

    ReplyDelete