Lab 9: Crossword Anagram

This assignment assumes that you have read up through Chapter 8 (Strings). Please bring your book to lab, as you will need it as a reference. Each lab assignment is more work than the previous one, so get started early.

This project may be done in pairs of students. We suggest that you sit together at the same computer and apply the pair programming technique. Take turns as the driver and navigator. (If you prefer to work alone, that is ok too.)

The objectives for this assignment are for you to:

  • Demonstrate an understanding of strings as a special case of arrays.
  • Learn how to use the string handling functions in the standard library.
  • Get even more practice in decomposing programs into small functions.
  • Getting Started

    As in the previous lab, start by creating a directory just for this assignment, and changing to that directory:
    mkdir cse20211/lab9
    cd cse20211/lab9
    

    Crossword Anagram

    Write a program (crossword.c) that, given a list of words, creates a blank crossword anagram puzzle that can be played with paper and pencil. The program also provides a solution for the player who gets stuck.

    The resulting crossword will be a board where most of the cells are filled in. The blank spaces on the board indicate places where the player must fill in a complete word. Where the spaces intersect, the words must share a common letter. A clue for each word is given by giving an anagram, which is simply the word with all of its letters shuffled.

    Your crossword generating program should work as follows:

    1. Begin by prompting the author to enter a list of up to 20 words of up to 15 letters each.
    2. Stop when the user enters a period "." instead of a word, or if 20 words have been provided.
    3. Create a 15-by-15 board that is initially empty. Select the longest word given, and place it horizontally in the middle of the board.
    4. For each of the remaining words in descending length, place them on the board in a way that intersects with exactly one identical letter already on the board. All letters of a word must be separated from other words by at least one blank space, except where it intersects with another word.
    5. Continue until all words have been placed. If it is absolutely impossible to place the next word according to the rules, then indicate that with an appropriate message, do not place any further words, and continue to the next step.
    6. Display the solution to the puzzle, with all the words placed.
    7. Display the unsolved puzzle and generate the anagram clues.
    For a given input, there are multiple legal puzzles, so it is ok if you find different ways for the words to intersect, as long as they satisfy the rules. Be sure that your program handles the following boundary conditions:
  • Words may only contain the letters A-Z.
  • Both upper and lower cases are accepted as input, but only upper case should be displayed in the generated puzzle.
  • Any invalid input or other problem discovered should be handled gracefully by producing an appropriate error message.
  • Hints:
  • Review the functions in ctype.h for converting between upper and lower characters.
  • Review the functions in string.h for comparing, copying, and modifying strings.
  • Divide your program into many short functions that each do simple things.
  • Accelerate the testing of your program by creating several test files with various lists of words. For example, if you put a list of words into the file list1.txt, you can feed it to your program with the command ./crossword < list1.txt
  • Example Output

    Anagram Crossword Puzzle Generator
    ----------------------------------
    
    Enter a list of words:
    Artsy
    smell
    baseball
    YELL
    .
    
    Solution:
    
    ...............
    ...............
    ...............
    ..........S....
    ..........M....
    ..........E....
    ..........L....
    ...BASEBALL....
    ....R..........
    ....T..........
    ....S..........
    ....YELL.......
    ...............
    ...............
    ...............
    
    Crossword puzzle:
    
    ###############
    ###############
    ###############
    ########## ####
    ########## ####
    ########## ####
    ########## ####
    ###        ####
    #### ##########
    #### ##########
    #### ##########
    ####      #####
    ###############
    ###############
    ###############
    
    Clues:
    
     3, 7 Across LSEBAAL
     4, 7 Down   STARY
     4,11 Across LYLE
    10, 3 Down   ELLMS
    

    Turning In

    This assignment is due on Monday, November 25th at Noon. Late assignments are not accepted.

    Please review the general instructions for lab reports.

    Turn in crossword.c and report.txt to either one of the partner's dropbox directories. (But not both.) The lab report should clearly indicate who the partners are, how the program works from the user perspective, how the program works internally, and how you verified that the output of the program is correct.