User Tools

Site Tools


opus:spring2015:dwoodco2:journal

Data Structures Journal

January 27, 2015

First Opus Entry

This will be the first online class I have taken before, I've taken mixed classes that are part on campus, part online. I look forward to a fun semester in Data Structures. From what I have heard this class can be extremely difficult if you let it get ahead of you and don't keep up on the information/projects.

I have been working on the first project dsi0.c, this project is mostly just a refresher on getting information for arrays, manipulating arrays and dealing with functions.

A few pieces of the code I have been working on (Will post the entire code here when it is finished)

                if(menu == 1) // option 1 for building list and gaining input
                {
                        for(a=0;a<b;a++)
                        {
                                printf("Enter values one at a time to build your list\n");
                                scanf("%d",&input);
                                if(input!=-1)
                                {
                                        list[a]=input;
                                        d=d+1;
                                }
                                else
                                {
                                        b=a;
                                }
                        }
                }

February 3rd, 2015

Worked on Project 2 “SLN0” over the weekend. Or so I thought…

I read the word pseudocode atleast 9 times in the entire project page but for some reason it didn't register with me once. I just continued to think of how I was going to write the program as I read over everything.

The project this week was the start of our long journey into Nodes. It covered what they are and what they do, how they work and how they point at each other.

A node is basically a storage point for some form of data for starters a simple number say 16. With a node you always need it pointing at something if it isn't then it needs to be pointed at “0” or NULL. If not then the data will be lost forever. You want something point at the node (16), or you won't have anyway of accessing it when you need it. In this case we used the worst start as our first point in the node. So far the node looks something like this.

start→16→NULL

With this we can start to add new lines to the Node or even take them away. We learned a few of the psuedocode terms for making, copying, and removing nodes.

mknode() Creates a new node ex. tmp=mknode(17);\\
rmnode() removes a node from the list ex. rmnode(tmp);\\
cpnode() copies a node and makes a similar copy of it ex. tmp2=cpnode(tmp);\\

With this we started out understand of Nodes. The project this week had us write out the psuedocode for a few different examples of nodes.

February 10th, 2015

This week worked on the SLN1 project where I had to create three functions that basically did the psuedocode we learned last week. I created a program that takes the number you entered in and creates the node and points to NULL immediately after that.

My mknode function

        Node *newNode; // you then set value = info and point the new allocated memory at it.
        newNode  = (Node *) malloc (sizeof(Node) );
        newNode -> info = value;
        newNode -> after = NULL;

My cpnode function

        Node *tmp2; // creates the tmp2 node
        tmp2 = tmp; // sets tmp2 equal to tmp
        if(tmp != NULL)
        {
                tmp2 = mknode(tmp -> info); // uses the mknode feature
                tmp2 -> after = tmp -> after;
        }

my rmnode function

        if(tmp != NULL)
        {
                free(tmp -> after); // frees the space after tmp
                tmp -> after = NULL; // then sets it equal to NULL
        }

With these three functions you can create and remove nodes just by simply saying mknode(17) With that I just created a node with 17 inside of it and pointed it at NULL. This project took me a little while to grasp but once I got the basics behind it I was able to work through the rest of the project within an hour or two.

February 17th, 2015

This was our break week, I was out of town and away from my computer for most of the week but I was able to download the files required for the project. I will work on the project Sll0. I read through the project and it wants you to create a function that can find the first point and the last point of the list.

So far I haven't found the material super difficult, but I have had to think of things in a different way. There is a difference between a NULL list and a list with a NULL first and last node. The NULL list has to be allocated before changes can be made that is why we created the make list function in the project this week.

List *mklist(void)
{
        List *myList = (List *)malloc(sizeof(List)); // creates the blank list
        myList -> first = NULL; // points first and last at NULL
        myList -> last = NULL;
        return(myList);
}

It is very similar to the make node function just this time you are pointing first and last at NULL. With this you can make changes to the list now by adding new nodes.

February 24th, 2015

With Sll0 done we moved on the sll1 which had multiple functions in it that allowed you make changes to the list you created. we created a function called append.c this function lets you add a new node into the list behind the one you selected. This function gave me the most trouble until I worked on it in class. This actually helped me to realize how the lists and nodes work a little more. The functions just need to be very, very specific. My append has around 12 if statements and else statements all checking for very specific events.

          if(place == myList -> last)
                        {
                                tmp = myList -> last;
                                if((myList -> first == NULL) && (myList -> last$
                                {
                                        myList -> first = newNode;
                                        myList -> last = newNode;
                                }
                                else
                                {
                                        myList -> last -> after = newNode;
                                        myList -> last = myList -> last -> afte$
                                }
                        }

I was able to work on the display backwards function and the copy list function and got them to work 100% on the first attempt since I was thinking of every specific incidence well writing them.

                        if(mode == 0)
                        {
                                fprintf(stdout,"NULL");
                                while(tmp != NULL)
                                {
                                        fprintf(stdout," <- %hhd", tmp -> info);
                                        position = position - 1;
                                        tmp = setpos(myList,position);
                                }
                                fprintf(stdout,"\n");
                        }

March 3rd, 2015

I worked on the last few parts of sll1 and started on sll2 this week. Things are starting to get more difficult I really do need to start working much much harder on these programs. I think I found them not to difficult at the start of the semester and things got out of hand for much pretty quick.

For this week we created functions that let us swap nodes in a lit, pull a node from the list and sort a list.

                                else
                                {
                                        if((*thatNode) == myList -> first)
                                        {
                                                myList -> first = myList -> first -> after;
                                        }
                                        else if((*thatNode) == myList -> last)
                                        {
                                                pos = getpos(myList,myList -> last);
                                                tmp = setpos(myList,pos - 1);
                                                myList -> last = tmp;
                                                myList -> last -> after = NULL;
                                        }
                                        else
                                        {
                                                pos = getpos(myList,(*thatNode));
                                                tmp = setpos(myList,pos);
                                                tmp2 = setpos(myList,pos-1);
                                                tmp2 -> after = tmp -> after;
                                        }
                                }

some of my obtain code, I was able to get all of the tests for obtain to work this time. If I don't write everything down things get out of hand and my programs segfault a lot…

        if(myList != NULL)
        {
                free(myList -> first);
                free(myList -> last);
                myList = NULL;
        }

For the remove list function it was similar to the remove node function with this you are just deallocating the first and last position in the list and setting it equal to NULL.

I wasn't able to get sort done since I am still having trouble with the compare function I am going to work on these in the lab and try to get them done as soon as possible.

March 10th, 2015

This week we started working on sll3 with groups of lists. They are very similar to lists and nodes just groups have multiple lists and each list has multiple nodes in it. The functions would work similarly just they are checking multiple lists instead of multiple nodes now. I started working on the make group and remove group functions.

Group *mkgroup(void)
{
        Group *myGroup = (Group *)malloc(sizeof(Group)); // creates blank group
        myGroup -> first = NULL;
        myGroup -> last = NULL;
        return(myGroup);
}
Group *rmgroup(Group *oldGroup)
{
        if(oldGroup != NULL)
        {
                free(oldGroup -> first);
                free(oldGroup -> last);
                oldGroup = NULL;
        }
        return(oldGroup);
}

March 17th, 2015

SLL3 deadline was extended this week so we worked on it more. I was able to get the getpos and setpos functions working this week.

long int lgetpos(Group *myListGroup, List *given)
{
        List *tmp;
        int pos;
        if(myListGroup == NULL)
        {
                pos = -1;
        }
        else
        {
                if(myListGroup -> first == NULL)
                {
                        pos = -1;
                }
                else
                {
                        pos = 0;
                        tmp = myListGroup -> first;
                        while((tmp != given) && (tmp != NULL))
                        {
                                tmp = tmp -> after;
                                pos = pos+1;
                        }
                        if(tmp == NULL)
                        {
                                pos = -2;
                        }
                }
        }
        return(pos);
}
List *lsetpos(Group *myListGroup, long int pos)
{
        List *tmp;
        int i=0;
        if(myListGroup != NULL)
        {
                tmp = myListGroup -> first;
                while(tmp != NULL)
                {
                        if(i != pos)
                        {
                                tmp = tmp -> after;
                                i++;
                        }
                        else
                        {
                                break;
                        }
                }
        }
        else
        {
                tmp = NULL;
        }
        return(tmp);
}

March 24th, 2015

The project due date was pushed back till the week after our break week. I was able to get the insert function done the week before we started our break.

Group *lobtain(Group *myListGroup, List **thatList)
{
        int pos=0;
        List *tmp, *tmp2;
        if(myListGroup != NULL)
        {
                if((*thatList) != NULL)
                {
                        if((myListGroup -> first != NULL) && (myListGroup -> last != NULL))
                        {
                                if(myListGroup -> first == myListGroup -> last)
                                {
                                        myListGroup -> first = NULL;
                                        myListGroup -> last = NULL;
                                }
                                else
                                {
                                        if((*thatList) == myListGroup -> first)
                                        {
                                                myListGroup -> first = myListGroup -> first -> after;
                                        }
                                        else if((*thatList) == myListGroup -> last)
                                        {
                                                pos = lgetpos(myListGroup,myListGroup -> last);
                                                tmp = lsetpos(myListGroup,pos - 1);
                                                myListGroup -> last = tmp;
                                                myListGroup -> last -> after = NULL;
                                        }
                                        else
                                        {
                                                pos = lgetpos(myListGroup,(*thatList));
                                                tmp = lsetpos(myListGroup,pos);
                                                tmp2 = lsetpos(myListGroup,pos-1);
                                                tmp2 -> after = tmp -> after;
                                        }
                                }
                        }
                }
        }
        return(myListGroup);
}

March 31th, 2015

Break week this week. I worked on the new DLL0 project and worked on finishing the SLL3 programs.

long int ldisplay(Group *myListGroup, long int pos)
{
        int value = 0;
        List *tmp;
        if(myListGroup != NULL)
        {
                if((myListGroup -> first == NULL) && (myListGroup -> last == NULL))
                {
                        value = 0;
                        fprintf(stdout,"<EMPTY>\n");
                }
                else
                {
                        tmp = myListGroup -> first;
                        if(pos == -1)
                        {
                                while(tmp != NULL)
                                {
                                        displayf(tmp,0);
                                        tmp = tmp -> after;
                                        value++;
                                }
                        }
                        else if(pos > 0)
                        {
                                tmp = lsetpos(myListGroup,pos);
                                value = pos;
                                fprintf(stdout,"<%d>:",value);
                                displayf(tmp,0);
                                value = 1;
                        }
                        else
                        {
                                fprintf(stdout,"<0>:");
                                displayf(tmp,0);
                                value = 1;
                        }
                        tmp -> qty = lgetpos(myListGroup,myListGroup -> last);
                }
        }
        else
        {
                value = -1;
                fprintf(stdout,"<NULL>\n");
        }
        return(value);
}

April 7th, 2015

We worked on DLL0 more this week DLL0 is the start of doubly linked lists basically it is a list of nodes that have two pointers. instead of just going down a list 1→2→3→NULL, now you can go 1→2 or 1←2 with this we are able to do functions like display all in one program instead of writing two different forward and backward functions. Now we can use the command prior like after only now we can go back down a list instead of just forward.

                        else if (mode == 1)
                        {
                                while(tmp != NULL)
                                {
                                        fprintf(stdout,"[%d] %hhd -> ", pos, tmp-> value);
                                        tmp = tmp -> after;
                                        pos++;
                                }
                                fprintf(stdout,"NULL\n");
                                state = DLL_SUCCESS;
                        }
                        else if (mode == 2)
                        {
                                tmp = myList -> last;
                                while(tmp != NULL)
                                {
                                        fprintf(stdout,"%hhd -> ", tmp -> value);
                                        tmp = tmp -> prior;

With this You have to actually tell the program that the number before is prior and the number after is after in programs like insert where you are adding a new node into the list.

                        else
                        {
                                tmp = place -> prior;
                                tmp2 = tmp -> after;
                                tmp -> after = newNode;
                                newNode -> after = tmp2;
                                tmp2 -> prior = newNode;
                                newNode -> prior = tmp;
                                state = DLL_SUCCESS;
                        }

This made some of the programs difficult at first until I figured that feature out and started implementing it.

April 14th, 2015

We started stacks this week, they were a pretty difficult for me probably the one I struggled with the most out of them all. A stack is basically a list that goes upwards so you can only put new nodes into the list on the top. As it states in the assignments page FILO (First In Last Out) so the first node you put into the stack/list is at the bottom and can't be altered until you remove all of the other nodes on top of it. We implemented the top command to show which node is at the top of the stack so we can alter that one.

my mkstack function

        if((*newStack) == NULL)
        {
                (*newStack) = (Stack *)malloc(sizeof(Stack));
                (*newStack) -> data = (List *)malloc(sizeof(List));
                (*newStack) -> top = (*newStack) -> data -> first;
                (*newStack) -> size = size;
                state = DLS_SUCCESS | DLL_EMPTY | DLS_EMPTY;
        }
        else
        {
                state = DLS_FAIL | DLS_CREATE_FAIL;
        }

Once I figured out that stacks are nothing but a list with rules on how you can alter the nodes in it this made them much simpler to understand. I wasn't able to finish all of the stack functions but I hope to go back and work on them at a later time.

A sample of my pop function it lets you take the node off the top of the stack and then you have to alter which node is counted as the top of the stack.

if((*myStack) -> data != NULL)
                        {
                                if((*myStack) -> data -> first != NULL)
                                {
                                        (*newNode) = (*myStack) -> data -> first;
                                        (*myStack) -> data -> first = (*myStack) -> data ->$
                                        (*myStack) -> data -> first -> prior = NULL;
                                        (*myStack) -> top = (*myStack) -> data -> first;
                                        (*myStack) -> data -> qty--;
                                        state = DLS_SUCCESS;
                                }
                                else
                                {
                                        state = DLS_NULL | DLS_FAIL;
                                }
                        }

April 21st, 2015

This week we moved onto queues, they were pretty simple for me to understand. They are just like a grocery line where the first person into the line is the last person out. So FIFO (First In First Out). with this queues didn't give me much difficult at first. I was able to get most of the functions to work almost 100% with the unit tests until I chanced something with my enqueue function that threw most of my other functions off and they wouldn't run correctly anymore. I set up the back of my queue to the last node in the list and the first in the list to the front of the queue.

my enqueue function (places a new node into the queue)

        if((*myQueue) -> data -> first == NULL)
                        {
                                (*myQueue) -> back = newNode;
                                (*myQueue) -> data -> first = newNode;
                                (*myQueue) -> data -> last = newNode;
                                (*myQueue) -> front = newNode;
                                (*myQueue) -> data -> qty++;
                                state = DLQ_SUCCESS;
                        }

then my dequeue function where you take a node from the back of the line.

             if((*myQueue) -> data -> first != NULL)
                        {
                                (*newNode) = (*myQueue) -> front;
                                state = state | obtain(&((*myQueue) -> data), (&(*myQueue) $
                                if(((*myQueue) -> front == NULL) && ((*myQueue) -> back == $
                                {
                                        state = DLQ_EMPTY | DLQ_SUCCESS;
                                }
                                else
                                {
                                        state = DLQ_SUCCESS;
                                }
                        }

April 28th, 2015

We started on the EoCe0 basically the final for the class this week. We also were given the final part of the types of data sorting for the semester Trees. Trees don't use any of the features queue and stack use with lists. They are individual nodes branching out from parent nodes. They have a root which is the top of the tree then the root has two nodes branching off. We set it up so that the lower value node is to the left (prior) and the greater value node is to the right(after). Then from there they are sorted greater and lower all the way down. Each node that has nodes underneath it is called a parent node.

Trees were a little difficult to understand but not as difficult as stacks were to me. I was able to understand them pretty easily just the implementing them into code was tough. My addnode function which adds a node into the tree based on its value.

                                while(tmp != NULL)
                                {
                                        if(newNode -> value <= tmp -> value)
                                        {
                                                if(tmp -> prior == NULL)
                                                {
                                                        tmp -> prior = newNode;
                                                        state = DLT_SUCCESS;
                                                        break;
                                                }
                                                else
                                                {
                                                        tmp = tmp -> prior;
                                                }
                                        }
                                        else
                                        {
                                                if(tmp -> after == NULL)
                                                {
                                                        tmp -> after = newNode;
                                                        state = DLT_SUCCESS;
                                                        break;
                                                }
                                                else
                                                {
                                                        tmp = tmp -> after;
                                                }
                                        }
                                }

It goes through the tree searching for the spot the new node should go depending on its value.

This is my search function to search the tree for a specific node with the value inside it that you are looking for.

             if(searchVal <= tmp -> value)
                                        {
                                                if(tmp -> prior -> value == searchVal)
                                                {
                                                        (*match) = tmp -> prior;
                                                        state = DLT_SUCCESS;
                                                        break;
                                                }
                                                else
                                                {
                                                        tmp = tmp -> prior;
                                                }
                                        }

May 5th, 2015 through rest of the semester

Now that we are done with the data structures the EoCE0 is to re-implement the single linked list and double linked list functions into C++. A lot of the basic structures look to be similar just with less features needed to work the program. A lot of the things you needed to check for in the C versions don't need to be done in C++. I will be spending the remainder of the semester working on the EoCE and if I have time I will go back and work on older projects that I wasn't able to complete 100%.

Systems Programming Journal

January 27, 2015

First Opus Entry

We started class last Tuesday and talked about the plans for the semester and the first project then split up into groups. My group talked about a couple of different games and looked into what parts would be difficult to design and what parts would be easy to get out of the way.

We decided on the game Astroids, the original one. We looked into how we would work the ship and how the meteors would enter. We talked about special effects like explosions and the fire behind the ship as it moves.

After working out all the different parts of the game we decided to use the newer SDL2 and set up a week for us to study up on it before we started working on the actual game. We also created our GitHub repository for the game to be stored on and so we could access it at home and make changes there.

I have been practicing SDL2 through a really handy guide I found online http://lazyfoo.net/tutorials/SDL/ it goes over a lot of different parts of SDL2 and how to design games through it. I am really looking forward to a fun Semester designing games and learning about there backgrounds and process for development.

February 3rd, 2015

I missed most of last week because of me getting my wisdom teeth taken out on Wednesday, I mostly spend the week studying SDL2 some more and emailing my team mates. They set up the Github account and I was added to that so I can pull and push changes to the project. We got the basic images we plan on using together and created folders for them. We mostly spent this week studying SDL2 still.

The guide we are using does work with Windows computers but it seems SDL2 has a bug with one of its folders and doesn't let you compile the code at all. There was a post on their website explaining it is being fixed and should be ready any day now so hoping that works. For now all I can do is study the code they post and test it / practice with it in the LAIR. Looking forward for next week when we get the actual code set up and start working on it.

February 10th, 2015

Worked on the images a little more this week cropping them a little better and changing the sizes. For the main game itself well I was out my partners got the basic background image set up with the ship moving in a straight line upward. They also got the first wave of asteroids appearing and moving across the screen. I worked on setting up the main menu for the game a little but for now had to push that to the side since we decided to get the actual main game working correctly first then we would add in a menu.

February 17th, 2015

I was finally able to get my old desktop up and running again I had to replace a few minor parts and clean it out. Then I wiped it clean and installed Linux onto it with all of the SDL2 files I need and tested them out. I was able to load what we have from the game so far and now I can work on the project from home much easier since I can actually test the changes I make.

I started working on the rotation for the ship this week. There is a lot to rotating the ship I've found, there is also a couple of different methods. Since we are short on time I decided to go with the SDL_gfx method where I can spin the image on an centered position. “Well I was typing that it actually gave me a great idea to fix something with my code”. The SDL_gfx folder has a special feature rotozoom.h that lets you rotate or zoom in on an image. Since I don't want to zoom in on the image though I just set the zoom to 1.0.

The program itself is giving me a couple of errors still so I may have to wait till I can go in on Monday to get some help with it. I found a video that gives a basic guide for the rotozoom.h function he loads an image and rotates it he also goes over how to move the image up and down well rotating which is exactly what we need for the game. The problem is the video is in SDL1 not SDL2 so I have to go through and change a few minor things. I will pretty much be staying in the LAIR as often as I can this coming week.

February 24th, 2015

I was able to get the ship to rotate on its fixed surface this week, through calculating the sin and cos of the current angle of the ship you can get the shop to move in the angle you want. Then you just have to constantly change what the center of the ship is so the ship rotates on its center always.

       int angle=90;
       bool move[4]={0,0,0,0};
       float playerX=600, playerY=325;

With this I set the angle to 90 since SDL2 has 0 at the top then 90 on the left all the way around to 270 then 360 again. The actual calculations happen real time as you hold the up key down to move the ship.

                               if(move[0] == TRUE) // UP key
                                {
                                        playerX-=cos(angle*M_PI/180.0)*7.0;
                                        playerY-=sin(angle*M_PI/180.0)*7.0;
                                        PLAYER.playerPos.x = playerX;
                                        PLAYER.playerPos.y = playerY;
                                }

After getting the ship to rotate it was still off by a little the image wasn't following the actual angle very well so I spent a while working on that then decided I needed to work on other features like the ability to shoot. I added in the ability to shoot with the ship for 1 bullet which wasn't hard I needed to have it work with the current angle of the ship then when you hit space it blits an image of the bullet moving foward from the angle and position of the ship.

March 3rd, 2015

We started our new project this week. With the first project we learned a lot about game designing and how tedious and difficult it can be. We spend Tuesday discussing multiple things we learned and how we are going to go forward with this new game. This time we are going to work as a class and design a massive space adventure type of game. We set up the repository on github and got everything ready to go. We decided to spend the weekend reading over make files and how to compile multiple programs together since we are going to split the program up into different files this time to make things easier for everyone to work on.

Last time each group had trouble pushing and pulling changes to the main repository since it didn't like when two people tried to push different changes at the same time. This time we are going to work on different files and different parts of the game. We haven't split up who is going to work on what just yet but I am looking forward to starting a new project and learning a lot about SDL and C++, also just the main workings of game designing.

March 10th, 2015

We attempted to start the project by getting a background to show up with a ship in the middle of it we met as a group and discussed ideas and plans for the game. It is pretty difficult to discus these things since most of the class doesn't show up anymore.

    //game loop
    while (!quit)
    {
        SDL_WaitEvent(&event);
        switch(event.type)
        {
        case SDL_QUIT:
            quit = true;
            break;
        }
        SDL_RenderClear( renderer );
        SDL_RenderCopy(renderer, texture, NULL, &shipPos);
        SDL_RenderPresent( renderer );

    }

This is about all we got. We have a black background with the spaceship in the middle of it. We also worked on getting the make function working for our program so we can compile and run it much easier.

March 17th, 2015

We didn't get much done this week since only 3-4 people showed up to class and we talked about other things in class. I was able to read up makefiles a little more though and understand how they work. I used the makefile we use in Data Structures as a base. They just take the program you want to compile and all the files you want to include in them and compile it together instead of saying gpp -o game game.c -game.h

March 24th, 2015

We didn't work on much again this week, only the same 3-4 people showed up to class again. We spent the days in class basically hanging out and discussing different forms of programming or computer features. I enjoyed them a lot since we talked about a lot of different things.

March 31st, 2015

This was our break week I attempted to look into the game a little but I mostly worked on other class work this week.

April 7th, 2015

Since not many people have been showing up to class and we haven't been able to get much done with the game we started to take a difference course with the class and started focusing more on the system programming side of it with linux and the commands like ls to view the files in your current folder. Next week we will be covering

April 14th, 2015

We started working on Linux commands this week we started with chmod function that allows you to change file permissions, with this you can take a file really anything we tested a couple of different ones with this and change who can access it. This was a little difficult for me to understand, I can understand the file permissions and everything just the actual code I struggled with.

        while(*(*(argv+1)+i) != '\0')
        {
                c= *(*(argv+1)+i);

                if(c >= '4')
                {
                        mode = mode | S_IRUSR >> i*3;
                        c = c-4;
                }
                if(c >= '2')
                {
                        mode = mode | S_IWUSR >> i*3;
                        c = c-2;
                }
                if(c >= '1')

                        mode = mode | S_IXUSR >> i*3;

                i++;
        }
        chmod(argv[2],mode);

April 21th, 2015

We created a function that lets you see who has logged into lab46 and shows all of the logins over a period of time with the utmp function.

        fd = open("/var/log/wtmp", O_RDONLY); // open wtmp to read
        if(fd == -1)
        {
                fprintf(stderr, "Error opening wtmp file\n");
                exit(1);
        }

        read(fd, uentry, sizeof(struct utmp));

        fprintf(stdout, "A utmp struct is %lu bytes\n", sizeof(struct utmp));

        while(read(fd, uentry, sizeof(struct utmp)) == sizeof(struct utmp))
        {
                fprintf(stdout, "%s\n", uentry -> ut_user);
        }
opus/spring2015/dwoodco2/journal.txt · Last modified: 2015/05/14 16:14 by dwoodco2