User Tools

Site Tools


Sidebar

projects

pct0 (bonus; due 20230823)
wcp1 (due 20230823)
abc0 (due 20230830)
btt0 (due 20230830)
pct1 (bonus; due 20230830)
pct2 (due 20230830)
wcp2 (due 20230830)
mpg0 (due 20230906)
pct3 (bonus; due 20230906)
wcp3 (due 20230906)
pct4 (due 20230913)
ttb0 (due 20230913)
wcp4 (due 20230913)
pct5 (bonus; due 20230920)
ttb1 (due 20230920)
wcp5 (due 20230920)
dap0 (due 20230927)
gfo0 (due 20230927)
pct6 (due 20230927)
wcp6 (due 20230927)
cgf0 (due 20231004)
pct7 (bonus; due 20231004)
wcp7 (due 20231004)
bwp1 (bonus; due 20231018)
cgf1 (due 20231018)
pct8 (due 20231018)
wcp8 (due 20231018)
cgf2 (due 20231025)
pct9 (bonus; due 20231025)
wcp9 (due 20231025)
cgf3 (due 20231101)
gfo1 (due 20231101)
pctA (due 20231101)
wcpA (due 20231101)
pctB (bonus; due 20231108)
waq0 (due 20231108)
wcpB (due 20231108)
pctC (due 20231115)
waq1 (due 20231115)
wcpC (due 20231115)
bwp2 (bonus; due 20231129)
pctD (bonus; due 20231129)
wcpD (bonus; due 20231129)
gfo2 (due 20231206)
pctE (bonus; due 20231206)
wcpE (bonus; due 20231206)
EoCE (due 20231214)
haas:fall2023:data:projects:cgf1

Corning Community College

CSCS2320 Data Structures

PROJECT: Card Game Fun (CGF1)

OBJECTIVE

With the cards and various properties laid out, implement and use doubly-linked lists to arrange cards in a deck, or piles, foundations, as if setting the stage to make a card game.

EDIT

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

cgf1

doubly linked lists

A doubly-linked list is a natural extension from a singly-linked list. Where in the latter you're only able to move in one direction along each node in the list, a doubly-linked list allows you to move in both directions.

To create the infrastructure needed to make our doubly-linked list, your node structure will need an additional pointer. Previously, we only had a single pointer to connect to the next node in the list. Now, we'll need a second one to point to the previous node.

struct Node {
    [ Node properties ]
    Node* prev;
    Node* next;
};

Navigating through a singly-linked list is something we're familiar with by now. Assuming the list exists, it was:

// Moves the pointer to the next node.
temp = temp->next;

Now within our doubly-linked list, we have two pointers to move through the list. Moving forward through the list is exactly the same as before. Moving backwards through the list is almost identical:

// Moves the pointer to the previous node.
temp = temp->prev;

insertion

Insertion is the process of adding a new node to your linked list anywhere except the end (that is appending in the next section). When performing an insertion, a common problem to be careful of is breaking the chain in your linked list. All of the nodes are “chained” together and if we break it then we will not be able to traverse it. Below will be examples of insertion in a doubly linked list.

The first thing you will do is Make sure you have a “start” pointer pointing at the first node in the list. Then create your new node using malloc like all your other nodes and have a temp pointer pointing to it.

- Inserting a node in the beginning

  temp -> prev = NULL;
  temp -> your_data = your_data
  temp -> next = start;
  start -> prev = temp;
  start = temp;
  

The most important thing is to ensure connection and move your start pointer last.

- Inserting a node in the middle

Move your pointer to the node that's “next” pointer will be pointing to the new node.

  temp -> your_data = your_data;
  temp -> prev = ptr;
  ptr = ptr -> next;
  temp -> next = ptr;
  ptr -> prev = temp
  ptr = temp -> prev;
  ptr -> next = temp;
  

You can see that it requires more steps than inserting at the beginning since we deal with 3 nodes rather than just 2.

appending

Appending is similar to insertion, but presumably at the end. Its still a similar process though

  newcard = (cardnode*)malloc(sizeof(cardnode));
  previouscard->next = newcard;
  newcard->previous = previouscard;
  newcard->next = NULL;

removal

Removing a node on a double-linked list is a somewhat easy process first you have to set the previous node's next pointer to the node you want to remove's next, and then you want to set the next node's previous to the current node's previous. Make sure to set the start and end of the list if the node to be removed is at the start or end of the list.

  if(node->next!=NULL){
    node->next->previous=node->previous;
  }
  if(node->previous!=NULL){
    node->previous->next=node->next;
  }
  if(node is at start of list){
    move start of list forward;
  }
  if(node is at end of list){
    move end of list backward;
  }
  node->previous=NULL;
  node->next=NULL;

Thus you can detach the node from the list that it is from, to instead delete the node you would follow up the last if statement with a free(node);

Randomizing Deck

To randomize your deck you can implement the Fisher-Yates shuffle algorithm which implements the rand() function and an array. To start you can make your array two different ways.

First way:

    int[52] cardValues = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
                          2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
                          2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
                          2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};

Second way:

int[52] array
for (int i = 0; i < 52; i++) 
{
     array[i] = i;
}
 

Once you have created your array using one of the above methods it is time to shuffle the cards. To do so, use the following snip of code. It is the Fisher-Yates shuffle algorithm.

for (int i = 52; i > 0; i--) {
    // Generate a random index between 0 and i.
    int j = rand() % (i + 1);
 
    // Swap cardOrder[i] and cardOrder[j].
    int temp = cardOrder[i];   // Store the value at cardOrder[i] in a temporary variable.
    cardOrder[i] = cardOrder[j];  // Replace the value at cardOrder[i] with the value at cardOrder[j].
    cardOrder[j] = temp;   // Set the value at cardOrder[j] to the value stored in the temporary variable.
}

Your array is now shuffled and you can implement it into your card game to randomize your deck.

You could also use srand() with a seed so that every time you open the game the deck is shuffled differnetly. To do this you will need time.h and use the time to seed srand() then just use rand() as normal but now it is really random.

card game

 

SUBMISSION

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

  • Project must be submit on time, by the deadline.
    • Late submissions will lose 33% credit per day, with the submission window closing on the 3rd day following the deadline.
  • Executed programs must display in a manner similar to provided output
    • output formatted, where applicable, must match that of project requirements
  • Processing must be correct based on input given and output requested
  • Output, if applicable, must be correct based on values input
  • Code must be nicely and consistently indented
  • Code must be consistently written, to strive for readability from having a consistent style throughout
  • Code must be commented
    • Any “to be implemented” comments MUST be removed
      • these “to be implemented” comments, if still present at evaluation time, will result in points being deducted.
      • Sufficient comments explaining the point of provided logic MUST be present
  • No global variables (without instructor approval), no goto statements, no calling of main()!
  • Track/version the source code in your lab46 semester repository
  • Submit a copy of your source code to me using the submit tool by the deadline.

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:

104:cgf1:final tally of results (104/104)
*:cgf1:doubly linked list implemented and used [52/52]
*:cgf1:functional card game of some sort [52/52]

Pertaining to the collaborative authoring of project documentation

  • each class member is to participate in the contribution of relevant information and formatting of the documentation
    • minimal member contributions consist of:
      • near the class average edits (a value of at least four productive edits)
      • near the average class content change average (a value of at least 1024 bytes (absolute value of data content change))
      • near the class content contribution average (a value of at least 1kiB)
      • no zero-sum commits (adding in one commit then later removing in its entirety for the sake of satisfying edit requirements)
    • adding and formatting data in an organized fashion, aiming to create an informative and readable document that anyone in the class can reference
    • content contributions will be factored into a documentation coefficient, a value multiplied against your actual project submission to influence the end result:
      • no contributions, co-efficient is 0.50
      • less than minimum contributions is 0.75
      • met minimum contribution threshold is 1.00

Additionally

  • Solutions not abiding by spirit of project will be subject to a 50% overall deduction
  • Solutions not utilizing descriptive why and how comments will be subject to a 25% overall deduction
  • Solutions not utilizing indentation to promote scope and clarity or otherwise maintaining consistency in code style and presentation will be subject to a 25% overall deduction
  • Solutions not organized and easy to read (assume a terminal at least 90 characters wide, 40 characters tall) are subject to a 25% overall deduction
haas/fall2023/data/projects/cgf1.txt · Last modified: 2023/10/05 09:02 by 127.0.0.1