Description
CECS 342 Assignment 1 – Specialty Languages with Inform 7
The purpose of this assignment is to familiarize you with the concept of
specialty programming languages and expose you to some of the unique grammars and structures that
programming languages can offer.
Part One. The first part of the assignment is to familiarize yourself with how works of interactive fiction
are played by the end user. Interactive fiction is, above all else, an early example of computer video games.
Unlike the early graphical games, like those in the Atari 2600 and early arcade games, early PC games catered
to a different kind of audience; people who owned PCs in the early 1980s were typically more educated and
more often worked professionally in computing (i.e. computer programmers). Because of this, the computer
operating systems and built-in programming languages were often intertwined together and the expectation
was that an owner of a PC was also a programmer to some degree.
In this first part, you will play the game Planetfall, written by Steve Meretzky. Planetfall is considered
by many to be one of the best entries of interactive fiction and it is one of my personal favorites. I have
included all of the necessary game files for you to download on Beachboard, including all of the relevant game
manuals. You will also need an interpreter in order to play these games. Check out a brief introduction to
interactive fiction here.
• Windows: I have included WinFrotz on Beachboard for your use. The program has long been abandoned by its creator, but it’s still one of the better Inform interpreters on Windows.
• MacOS: Download the program Spatterlight from Github. Alternatively, you might also consider
Lectrote, a more modern but less feature-filled interpreter.
• Linux: Install the program frotz in apt-get or similar repository. It is a command-line IF interpreter
and it is extremely robust/considered the standard for IF interpreters today.
I know that it is not common practice in computer games today to read manuals before diving into games
(that’s what tutorials are for, right?) but Planetfall harkens back to a time when disk space was extremely
limited (in the kilobyte range!) and online documentation was non-existent. As such, I highly recommend
reading all of the included documentation before attempting to play the game. Not only will the
documentation help you understand how the parser will interpret your input, but the manuals (mostly) are
written to help you as the player fully immerse yourself in this world you are about to enter and give you
necessary background information. They are also some of the most quirky and humorous game materials
that I have ever read and serve well to involve you in the game from the start.
Planetfall is a text game which is puzzle-based and the game will throw various puzzles at you to solve
in order to progress the storyline. Please avoid the temptation to Google a walkthrough for the
game. The game should be played and enjoyed; I do not expect you to be able to finish the entire game (as
people often played these games for weeks before finishing), but attempt to get as far in the game as you
can. The game also contains many “in” jokes intended for the computer-literate crowd which were atypical
for the era (which I also hope that you will appreciate). Don’t be afraid to experiment within the game and
test the limits of the parser—you might be surprised at how well the parser will understand you. Part of the
enjoyment of these games is trying new things out and attempting to solve puzzles in unexpected ways.
Planetfall also exists on several sites which allow you to play in a web browser, but they typically lack
the save/restore features which are important to actually finishing the game. You will also need to know
how to use an interpreter to play the game you will eventually create in Part Two.
1
No deliverables are required for Part One. Simply use this time to play and enjoy the game and understand
how interactive fiction works.
Part Two. In Part Two, you will create a game using the Inform programming language. The use of the
included IDE for Inform is optional, but recommended.
Your game should contain one (or more, if you like) of each of the following:
• Locked door. In its most boring form, you must find a key and use it to unlock a door, thus giving
you access to one or more additional rooms. With a little more imagination: You aren’t admitted
without a badge. You need to buy a ticket. You must give the troll a gold piece before you can cross
the bridge. Waving the magic wand causes the rainbow bridge to appear. Et cetera. Any sort of locked
door puzzle will do.
• Hidden object. Boring form: You open a box and find something inside. More interesting: You
break open a treasure chest. You use the combination to a safe. You peer into the crystal ball. You
buy the candy bar from the vending machine. You disassemble the robot to get some part out of it.
• Incomplete object. Your flashlight needs batteries. Your gun needs bullets. Your car needs gas.
Your bicycle has a flat tire. You need a computer to get at the information on a floppy disk. You are
a zombie and need a brain.
• Limited resource. You have a limited amount of time (to find the bomb before it goes off) or money
(to buy the things you need), or food, drink, or sleep (so you don’t collapse), or some other resource.
Maybe you can find more resources in the game, maybe you can’t.
Review the documentation for Inform 7 on the language’s official website. The site includes the language
documentation as well as example source code files in the form of complete, compliable games.
Deliverables. Submit your source code and the compiled Inform file (in .z8 format) through Beachboard
Dropbox. I should be able to play your game by downloading the compiled file and running it in my
interpreter of choice (all compiled .z* files should work in any compatible interpreter). Make sure that you
have adequately commented your original source code, else I will not grade it and you will receive zero points
for the assignment!
2
CECS 342 Assignment 2 – Scripting Languages with Ruby
The purpose of this assignment is to familiarize you with the features of
scripting languages and demonstrate the power that these languages can offer for certain tasks.
Part One – Coin Arranger. We’re going to play a game with this assignment. We begin with ten coins
in a row (five heads and five tails) tightly packed with no gaps between adjacent coins.
HHHHHTTTTT
The object is to rearrange the coins into an alternating heads/tails pattern, i.e., one of the following two
patterns:
HTHTHTHTHT
THTHTHTHTH
Again, there are no gaps between adjacent coins. The rearrangement must be accomplished in five
“moves” where a move consists of taking any two touching coins and moving them into a two-coin gap, if
such a gap exists, or to one end of the row, if no such gap exists. For example, initially there is no two-coin
gap, so a possible move would be to take the “HT” coins in the center and move them to the right end,
yielding
HHHH–TTTTHT
Now there is a two-coin gap, so on the next move we would have to take two adjacent coins and move
them into the gap, e.g., we could try
HHHHTHTTT–T
As these examples illustrate, the coins are not allowed to switch places during the move, i.e., of the two
moved coins, the one on the left before the move must remain on the left after the move. Also, moving coins
to the end of the row is illegal if there is a two-coin interior gap. The two coins that are moved must be
touching; so for example the isolated “T” at the right end in the last picture above cannot be moved on the
next move.
Write a Ruby program to play this game. Allow for a maximum of five moves per playthrough. Use
strings and display the string after each move. For each move, display the string and let the user select the
position of the left of the two characters to move by spacing to it with the cursor under that left character of
the two. Then print the string again and let the user space to the left position to where the two characters
should be moved. Use the split method with an empty string argument to convert the string to an array.
Make the move and use the join method to convert the array to a string. Repeat until five moves have been
made.
Part Two – Array Partitioner. Write a Ruby program to partition an array. Read in n values to an
array, and a test value x. Rearrange the array so that the elements up to and including index p are <= x
and the elements from p + 1 to n are > x. Elements may be repeated. The test value, x, may be larger
than all values or smaller than all values or in between somewhere. You may only visit each element once,
and may not copy it to another array. For each test case show the input array, the output array, and the
partition index p.
For example, given: 28 26 25 11 16 12 24 29 6 10 with test 17 the result might be: 10 6 12 11 16
25 24 29 26 28 with partition index 4.
An outline of an algorithm is as follows:
1. Start with markers at each end. Move markers towards each other until a wrongly placed pair is
encountered. Allow for x being outside the range of array values.
1
2. While the two markers have not crossed over:
(a) Exchange the wrongly placed pair and move both markers inward by one.
(b) Extend the left marker while elements are less than or equal to x.
(c) Extend the right marker while elements are greater than x.
3. Return the partition index p and the partitioned array.
Deliverables. Submit your source code files through Beachboard Dropbox. Make sure that you have
adequately commented your original source code, else I will not grade it and you will receive zero points for
the assignment!
2
CECS 342 Assignment 3 – Functional Languages with Erlang
The purpose of this assignment is to familiarize you with the features and
strengths of functional programming languages and also demonstrate the power that these languages can
offer for tasks in their areas of specialties.
Part One – Students and Candy. Three students sit in a circle while their teacher gives them candy.
Each student initially has an even number of pieces of candy. When the teacher blows a whistle, each student
simultaneously gives half of his or her own candy to the neighbor on the right. Any student who ends up
with an odd number of pieces of candy gets one more piece from the teacher.
Write an Erlang program that includes a recursive function with four parameters, the amounts of candy
for the three students and the number of turns. Each time the function is called it adjusts the number
of candy of each student according to the above rules. A helper function should be defined to make this
adjustment. At each whistle blow output the amount of candy of each student and the turn number. Stop
when all students have the same amount of candy.
The div and rem operators produce integer values. Remember that the output value using io:format
must be enclosed in list brackets, []. Test your program using different input including some larger numbers.
Part Two – Frequency Count. Write an Erlang program that counts the word frequencies in the file
assign3-part2.txt. Erlang uses a list of tuples as a hash table. Write four Erlang functions.
1. This function has a string file name parameter and returns a list of words in the file. Open the file
with file:open. The file assign3-part2.txt was written in a text editor as one line, so io:get_line will
read the whole file. string:tokens will separate it into words. Its second argument specifies all the
delimiters.
ie: file:open(“assign3-part2.txt”,read).
ie: L1= io:get_line(S, ‘’).
2. This function has two parameters, a string word and a list of tuples, and returns a list of tuples with
the word added appropriately. Each tuple is a word key and a frequency value. The lists:keyfind
method will find a tuple if it exists and return false if it does not. If the word is not found use
lists:append to add a tuple with the word as key and 1 as the frequency. If the word is found use
lists:replace to replace the tuple with a new tuple with frequency increased by one.
3. This function has a list of words as parameter and returns a hash table of tuples of words and their
frequencies. The string:to_lower method will make a word lower case to provided the desired case
insensitivity. Use the lists:foldl method to build the answer using the function 2.
4. This function outputs the final hash table sorted by frequency from high to low using the lists:sort
function. Its one parameter is the file name. It uses functions 3 and 1.
Deliverables. Submit your source code files through Beachboard Dropbox. Make sure that you have
adequately commented your original source code, else I will not grade it and you will receive zero points for
the assignment!
1
CECS 342 Assignment 4 – Logic Languages with SWI-Prolog
The purpose of this assignment is to give you some experience programming
with logic programming. You will be using SWI-Prolog for this assignment.
Part One – Logic Puzzles. To successfully complete this program, you will have to use lists in Prolog
and provide solutions to the following logic problems along with your Prolog source code.
The three logic puzzles are as follows:
It’s a Tie. I have provided a sample solution for this one on Beachboard. Use this as a model for your
own solutions.
Imaginary Friends. The first part of your assignment is to write (and turn in) a Prolog program to
solve this logic puzzle. Once you understand the “It’s a Tie” solution, this should be easy. Do this one first.
Star Tricked. The second part is to write (and turn in) a Prolog program to solve this logic puzzle.
This one is a little trickier–you need to figure out how to describe the ordering of weekdays–but it’s not too
hard.
These problems make unusually extensive use of the NOT operator, \+. Here’s what you need to know
about this operator:
• \+ works as you would expect when all variables are completely instantiated (bound).
• Prolog tries to prove things, so if expression E contains unbound variables, \+E will try to find variable
bindings that will make E true.
It is easy to check whether a solution is correct: Just check whether it satisfied each of the numbered rules
in the problem.
1
2
Deliverables. Upload your .pl source code and a text file with the queries asked to solve each puzzle to
Beachboard Dropbox. Your assignment will not be graded unless the query file is included along with
your source code.
Part Two – Adventure Game. Remember back to the first week of class? Guess what? You get to make
another adventure game! This time, it’ll be in Prolog.
Your assignment is to write an adventure game in SWI-Prolog (almost like we did with Inform!). The
requirements are exactly the same as the Inform assignment: pick any theme you like for your adventure
game: rescue, survival, treasure hunt, “a day in the life,” or whatever else appeals to you.
Copy the file adventure.pl (on Beachboard) and use it as a starting point. This is an absolutely boring
game consisting of one room, one object, and one direction you can go (but going in that direction takes you
back to the same room). Add to this code to create your own game; if it doesn’t do what you want, fix it
so that it does. This is free code, to use or modify any way you like. If you don’t want to use it, that’s okay
too.
You can get additional ideas from the file spider.pl (also on Beachboard).
Your program should contain one (or more, if you like) of each of the following:
• Locked door. In its most boring form, you must find a key and use it to unlock a door, thus giving
you access to one or more additional rooms. With a little more imagination: You aren’t admitted
without a badge. You need to buy a ticket. You must give the troll a gold piece before you can cross
the bridge. Waving the magic wand causes the rainbow bridge to appear. Et cetera. Any sort of locked
door puzzle will do.
• Hidden object. Boring form: You open a box and find something inside. More interesting: You
break open a treasure chest. You use the combination to a safe. You peer into the crystal ball. You
buy the candy bar from the vending machine. You disassemble the robot to get some part out of it.
3
• Incomplete object. Your flashlight needs batteries. Your gun needs bullets. Your car needs gas.
Your bicycle has a flat tire. You need a computer to get at the information on a floppy disk. You are
a zombie and need a brain.
• Limited resouces. You have a limited amount of time (to find the bomb before it goes off) or money
(to buy the things you need), or food, drink, or sleep (so you don’t collapse), or some other resource.
Maybe you can find more resources in the game, maybe you can’t. Depending on just what you decide
to do, you may want to figure out how to do arithmetic in Prolog.
You should have a start/0 predicate (similar to the one provided in the source code of the adventure.pl file)
that I can use to start your game and find out what commands you have added. Don’t make me look at the
code to figure out how to run your program!
Also include an inventory command (abbreviation: i) to tell what the player is currently holding.
Play the game by running Prolog and typing queries into it. Prolog can easily read Prolog terms, but
reading anything else is awkward, and not worth learning how to do. (However, if you want to ask the user
for a number, you can use the read(X) predicate; a number is a term. Just remember to type a period after
the number.)
You may simply re-create the game that you made for the first assignment (as long as it meets all of the
requirements), or you may do something completely new.
Deliverables. Submit your .pl source code, a transcript of a sample run of your program, and a readme.txt
file that briefly describes your game, and in particular briefly describes your locked door, hidden object,
incomplete object, and limited resource. Make sure to also include the query file (or, at the very minmum,
clear instructions on how to run your game) in order to receive credit.
4
CECS 342 Assignment 5 – Ancient Languages with Fortran 77
The purpose of this assignment is to give you some experience programming
with older programming languages. You will be using Fortran 77 for this assignment (and not a newer
version of Fortran!).
Write a program in Fortran 77 to sort an array of numbers entered from the keyboard and then using
binary search, search for a number in the array. If the number is not found then it should ask for another
number. The program should work in a loop to search for multiple numbers one by one without having to
execute the program again. Your program must use the 77 standard of Fortran–you may not use a later
version of Fortran to complete this assignment (eg. Fortran 95).
A good reference (probably one of the only remaining) on Fortran 77 can be found here.
Deliverables. Submit your .f source code (some compilers use *.f77 as the file extension, which is also
fine), a screenshot of a sample run and output of your program, and a text file with a writeup about your
experiences with Fortran 77 to Beachboard Dropbox.
1