From UBC Wiki


Authors: Edward Lee, Leslie Liang

What is the problem?

Have you ever played Shirotori or Word Chain? Many people have played this game or a varying form, the name of the game is easily forgotten so names can vary. This game is a Japanese word game in which the players are required to say a word which begins with the final letter of the previous word. "Shiritori" literally means "taking the buttocks" or "taking the end". One player starts the game with any word of their choosing which follows the rules, and the next player must answer with a word that begins with the last letter of the previous player's word.

During Project 1, Edward implemented a Prolog version of this game and we would like to see how a Haskell implementation compares. We will also expand the game with new difficulty levels and more genres.

Rules of the Game

Rules of the game:

  • Take turns to play.
  • Only nouns, verbs, and adjectives are permitted.
  • Words may not be repeated.

What is the something extra?

Players can also choose to play with words in specific genres, such as: animals, countries.

This game will also attempt to check whether or not you are cheating. If you are cheating, the game will end and you will have lost. Cheating:

  • starting with a word that does not start with the last letter of the previous word.
  • inputting a nonexistent word.
  • inputting a word that does not correspond to the game genre, like country or animal genre.
  • trying to repeat words that have already been used

Additionally, the game will have two difficulty levels. In the "difficult" mode, the game will favour words that will make the next turn more difficult. For example, it will choose words that end in 'q', 'x', 'w', 'z', over words that end in 'a', 'e', 't', etc, and vice versa for the "easy" mode.

What did we learn from doing this?

(This should be written after you have done the work.) What is the bottom-line? Is logic programming suitable for (part-of) the task? Make sure you include the evidence for your claims.


  1. Haskell is easier at handling global variables, playing around with variables that do not change. (dictionaries, difficulty variables, etc)
  2. Haskell's game is very convenient for a game round. Because there are no side effects, you can start a new game right away after losing/cheating/winning with a clean slate.
  3. Like Prolog, after the initial compile the game is extremely quick at outputting values and responses.


  1. Haskell lacks dynamic variables. It's not as easy to represent the game state which is dynamic, as compared to Prolog. We needed to encapsulate everything in one game function and thread the state of the game through the function.
  2. While in a Game round, cannot backspace and delete inputted characters. (Haskell limitation, and aesthetically displeasing)

Haskell is suitable and ideal for implementing the game "Shiritori" for the following reasons:

  • Haskell allows the storing of global variables that can be accessed when needed:
  This is very important for "Shiritori" because it needs to check to see if inputs from the player are valid and listed in the dictionaries. 
  • The convenience of a Game functions that allows users to play a game round in a fluid manner:
  For convenience, players don't have to constantly input "play ____ _____" . After the first initiation of the game, players are only required to input a word to continue the game, until either they win, lose, or cheat. 
Example: *Shiritori> play "countries" "easy" Input your next move. canada Computer's move: afghanistan. Input your next move. northkorea Computer's move: albania. Input your next move. alberta