Description
Submit a single file, assassin_list.c on Canvas.
This assignment will give you practice with recursion. You are to rewrite the functions in the file
assassin_list.c that allows a client to manage a game of assassin using recursion. Use your
solution from Assignment 1 to rewrite. If you had bugs, fix before you rewrite the functions. The
functions that you need to rewrite are
list_add
print_kill_ring
print_grave_yard
grave_yard_contains
kill_ring_contains
You may want to consider using helper functions to implement recursion.
Each person playing assassin has a particular target that he/she is trying to assassinate. One of
the things that makes the game more interesting to play is that initially each person knows only
who they are assassinating (they don’t know who is trying to assassinate them nor do they know
who other people are trying to assassinate). You are working on a program for the “game
administrator” who needs to keep track of who is stalking whom and the history of who killed
whom.
The game of assassin is played as follows. You start out with a group of people who want to play
the game. For example, let’s say that we have five people playing whose names are Joe, Sally,
Jim, Carol and Chris. A circular chain of assassination targets is established (what is called the
“kill ring” in the sample log of execution). For example, we might decide Joe should stalk Sally,
Sally should stalk Jim, Jim should stalk Carol, Carol should stalk Chris and Chris should stalk Joe.
Joe –> Sally –> Jim –> Carol –> Chris
^ |
| V
+——–<——–<———<——–+ When someone is assassinated, the chain needs to be relinked by “skipping” that person. For example, suppose that Jim is assassinated first (obviously this would have been by Sally). Sally needs a new target, so we give her Jim’s target: Carol. Thus, the chain becomes: +——–>——–+
^ |
| V
Joe –> Sally Jim Carol –> Chris
^ |
| V
+——–<——–<———<——–+
The main program has been written for you and is called main.c. It reads a file of names,
shuffles the names, and creates a variable of type alist. The main program then asks the user for
the names of the victims in order until the game is over (until there is just one player left alive),
calling functions of the assassin_list to carry out the tasks involved in administering the game.
Your assassin_list will keep track of two different lists: the list of those currently alive and the list
of those who are dead. Each is to be stored in a linked list. I am requiring you to use my node
struct which is called anode (assassin_node.h). The anode struct has three data fields: one for
the name of the person, one for the name of the killer and a “next” field to keep track of the
next value in the list.
For this particular program, it can be convenient to store the kill ring in what is known as a
“circular” linked list. Normally lists have the value “null” stored in the next field of the last node
of the list. Such lists are known as “null terminated” lists. In a circular list, the final element
stores a reference to the first element in the list. The assassin task involves a circular chain of
targets, so this can be a convenient structure to use. It can also lead to infinite loops and other
problems.
You will probably want to write your own testing program. When your code is in good shape,
you can use the main program to make sure it works properly. A log of execution for program
appears at the end of this write-up. Your program should exactly reproduce the format and
general behavior demonstrated in the log, although you won’t exactly recreate this scenario
because of the “shuffling” of the names that main performs.
In terms of correctness, your program must exhibit the behavior in the executable. In terms of
style, I will be grading on your use of comments, good variable names, consistent indentation
and good coding style to implement these operations.
Submission Instructions: Submit the code on Canvas under Assignment 3 Submission link
as assassin_list.c.
Log of execution (user input underlined)
Current kill ring:
Bobby Warner is stalking Joe Martin
Joe Martin is stalking Ruth Martin
Ruth Martin is stalking Tad Martin
Tad Martin is stalking Phoebe Wallingford
Phoebe Wallingford is stalking Erica Kane
Erica Kane is stalking Anita Santos
Anita Santos is stalking Jackson Montgomery
Jackson Montgomery is stalking Bobby Warner
Current graveyard:
next victim? Joe Martin
Current kill ring:
Bobby Warner is stalking Ruth Martin
Ruth Martin is stalking Tad Martin
Tad Martin is stalking Phoebe Wallingford
Phoebe Wallingford is stalking Erica Kane
Erica Kane is stalking Anita Santos
Anita Santos is stalking Jackson Montgomery
Jackson Montgomery is stalking Bobby Warner
Current graveyard:
Joe Martin killed by Bobby Warner
next victim? Joe Martin
Joe Martin is already dead.
Current kill ring:
Bobby Warner is stalking Ruth Martin
Ruth Martin is stalking Tad Martin
Tad Martin is stalking Phoebe Wallingford
Phoebe Wallingford is stalking Erica Kane
Erica Kane is stalking Anita Santos
Anita Santos is stalking Jackson Montgomery
Jackson Montgomery is stalking Bobby Warner
Current graveyard:
Joe Martin killed by Bobby Warner
next victim? Tad Martin
Current kill ring:
Bobby Warner is stalking Ruth Martin
Ruth Martin is stalking Phoebe Wallingford
Phoebe Wallingford is stalking Erica Kane
Erica Kane is stalking Anita Santos
Anita Santos is stalking Jackson Montgomery
Jackson Montgomery is stalking Bobby Warner
Current graveyard:
Tad Martin killed by Ruth Martin
Joe Martin killed by Bobby Warner
next victim? Bobby Warner
Current kill ring:
Ruth Martin is stalking Phoebe Wallingford
Phoebe Wallingford is stalking Erica Kane
Erica Kane is stalking Anita Santos
Anita Santos is stalking Jackson Montgomery
Jackson Montgomery is stalking Ruth Martin
Current graveyard:
Bobby Warner killed by Jackson Montgomery
Tad Martin killed by Ruth Martin
Joe Martin killed by Bobby Warner
next victim? Erica Kane
Current kill ring:
Ruth Martin is stalking Phoebe Wallingford
Phoebe Wallingford is stalking Anita Santos
Anita Santos is stalking Jackson Montgomery
Jackson Montgomery is stalking Ruth Martin
Current graveyard:
Erica Kane killed by Phoebe Wallingford
Bobby Warner killed by Jackson Montgomery
Tad Martin killed by Ruth Martin
Joe Martin killed by Bobby Warner
next victim? Anita Santos
Current kill ring:
Ruth Martin is stalking Phoebe Wallingford
Phoebe Wallingford is stalking Jackson Montgomery
Jackson Montgomery is stalking Ruth Martin
Current graveyard:
Anita Santos killed by Phoebe Wallingford
Erica Kane killed by Phoebe Wallingford
Bobby Warner killed by Jackson Montgomery
Tad Martin killed by Ruth Martin
Joe Martin killed by Bobby Warner
next victim? Menaka Abraham
Unknown person.
Current kill ring:
Ruth Martin is stalking Phoebe Wallingford
Phoebe Wallingford is stalking Jackson Montgomery
Jackson Montgomery is stalking Ruth Martin
Current graveyard:
Anita Santos killed by Phoebe Wallingford
Erica Kane killed by Phoebe Wallingford
Bobby Warner killed by Jackson Montgomery
Tad Martin killed by Ruth Martin
Joe Martin killed by Bobby Warner
next victim? Phoebe Wallingford
Current kill ring:
Ruth Martin is stalking Jackson Montgomery
Jackson Montgomery is stalking Ruth Martin
Current graveyard:
Phoebe Wallingford killed by Ruth Martin
Anita Santos killed by Phoebe Wallingford
Erica Kane killed by Phoebe Wallingford
Bobby Warner killed by Jackson Montgomery
Tad Martin killed by Ruth Martin
Joe Martin killed by Bobby Warner
next victim? Ruth Martin
Game was won by Jackson Montgomery
Final graveyard is as follows:
Ruth Martin killed by Jackson Montgomery
Phoebe Wallingford killed by Ruth Martin
Anita Santos killed by Phoebe Wallingford
Erica Kane killed by Phoebe Wallingford
Bobby Warner killed by Jackson Montgomery
Tad Martin killed by Ruth Martin
Joe Martin killed by Bobby Warner