Table of Contents

Corning Community College

CSCS2320 Data Structures

PROJECT: Make Space Invaders (MSI2)

OBJECTIVE

Complete your transition of Space Invaders to singly-linked lists by polishing your linked list implementation into a library with API.

EDIT

You will want to go here to edit and fill in the various sections of the document:

msi2

mknode() function

Node *mknode (parameters);

To make a node you need to allocate memory for it, and initialize any values that need to be, for parameters you want to pass it anything that might change between nodes, like X and Y coordinates, but anything that remains the same, like speed, can be hard-coded into the function. And don't forget that this is a non void function, meaning that it needs to return a value!

rmnode() function

Node *rmnode (Node *);

To be to use rmnode you must first use obtain. rmnode does what it sounds like it does, removes the given node. First you will want to check if the given node is NULL or not as there is no reason to remove something that doesn't exists. Now your given node has an attribute to it (→ next) which will need to be set to NULL, if not then some whacky stuff will happen. Then the node needs to set free like Mufasa from that cliff, cast into the endless void of NULL Wildebeests. And then just like Mufasa the node itself has to become NULL as well. And don't forget that since this is not a void function it needs to return a value!

mklist() function

List *mklist ();

For mklist one must name there list like they have the other struct objects in previous projects. And also just like previous projects one must allocate memory for said list! Or else there will be issues in your future! In typical faction one must set their lists attributes to NULL. And don't forget that this is a non void function, meaning that it needs to return a value!

insert() function

List *insert (List *, Node *, Node *);

Your insert function will work similarly to vim, that is it will insert before another node. You will need to pass the function the list you are adding the node to, the node you are inserting before, and the node you are inserting. With a singly linked list inserting is more complicated because you need to find the node preceding the location node without having a direct previous pointer

And don't forget that this is a non void function, meaning that it needs to return a value!

append() function

List *append (List *, Node *, Node *);

Your append function will work similarly to vim, that is it will append after another node, not necessarily at the end of the list. You will need to pass the function the list you are adding the node to, the node you are appending to, and the node you are appending. Make sure you rework the next pointers, as to not lose any nodes that were already following the location node, ie change newnode → next to be location → next before changing the location's next to be the new node

And don't forget that this is a non void function, meaning that it needs to return a value!

obtain() function

List *obtain (List *, Node **);

For obtain the goal is to get the current node and remove it from the list so that you can either freely manipulate it or simply use it as an argument for rmnode().
Things to be mindful when creating this function are:

  • Is the list made up of just that node?
  • Does myList→start == that node?
  • Does myList→end == that node?
  • Make sure whatever is before that node has its next assigned (*object)→next;
  • Assign (*object)→next to be NULL
  • Note that the parameter is Node so you want to properly de-allocate for what you end up passing in You'll also want a variable such as Node* theForsaken to be assigned that node prior to using obtain as you don't want to lose connection to that node
    Notice the type of the function is of List *, this means you will
    return a value**!

clearlist() function

List *clearlist (List *);

The purpose of the clearlist function is to have the list emptied of nodes before the list itself is destroyed. A not-bad idea would be to have the list cycle through all still remaining elements, and obtain / remove them until the list itself is empty. The end product should only have first and last, both set to NULL. Keep in mind that the primary use of this function will be inside the rmlist function.

rmlist() function

List *rmlist (List *);

With the list now clear, it is time to invoke the rmlist function. This function is simple, and very similar to how rmnode works. Simply call the clearlist function, and then free the memory for which the list was occupying. The last step is to set the now empty, non-memory-occupying list to NULL and return.

It is necessary to remove the list at the end of your game loop to manage memory properly and avoid memory leaks. If you do not remove the list, memory will not be freed and any memory occupied by the nodes you’ve added to the list will accumulate and lead to memory leak/overflow. This is also why it is important to clear your list before reinitializing/resetting your game objects. Clearing unused memory is a good habit to develop!

 

SUBMISSION

To be successful in this project, the following criteria (or their equivalent) must be met:

Submit Tool Usage

Let's say you have completed work on the project, and are ready to submit, you would do the following:

lab46:~/src/SEMESTER/DESIG/PROJECT$ submit DESIG PROJECT file1 file2 file3 ... fileN

You should get some sort of confirmation indicating successful submission if all went according to plan. If not, check for typos and or locational mismatches.

RUBRIC

I'll be evaluating the project based on the following criteria:

130:msi2:final tally of results (130/130)
*:msi2:node and list creation functions implemented and used [26/26]
*:msi2:insert and append API implemented and at least one used [52/52]
*:msi2:obtain API implemented and used [26/26]
*:msi2:functioning space invaders with working list library [26/26]

Pertaining to the collaborative authoring of project documentation

Additionally