Monday, September 5, 2016

New Project - Bullet Hell Game

So a few weeks ago I was talking to a friend at work and I found out that he has some experience working on games. We started talking about working on a game, and that's what he have done. We aren't going to sell it or anything, since I am a student and I'm using student licenses on most of the software I use.

He is going to do most of the engineering work on the game, and I will work on the art along with a friend I am in the progress of asking her to join us. We have an idea of creating a base ship, and then as the player progresses, more pieces will be added on to the base ship to show progress... "modular design" if you will.

I have been working on the base ship for a few days now, on and off. And I have now finished the first rough draft of the model. Here is a quick render from Maya:


As you can see, there is not much detail on the sides and most of the detail is on the gun or the top of the ship since this is the camera angle the player will look at the ship from. There is no point on adding detail where the player won't see it or might be too small to make a difference. The rest of the detail will come from the diffuse map and normal map.

Anyways, I am really excited to work on a game after so long. We are using Unity for it, and I will try to work on this as much as I can. Thanks for reading!

Tuesday, August 16, 2016

Texture Tuesday - Aug 16, 2016

With school starting next week, I am going to try and keep making these textures as much as possible. Hopefully it won't be just these two.

Anyways, this week I followed a different guy on YouTube since I didn't feel like making a wet metal texture like the next one on the playlist from last week. This time I found another guy that showed how to make a brick texture, and I also like it a lot: 


At the end I took a stab trying to make it a little unique instead of just following the tutorial. I like the outcome, but I think I messed up somewhere since it doesn't pop as much as the one from last week. Here are my renders from Marmoset Toolbag:



This one took me about 2 hours, a little over an hour to follow the tutorial and the rest of the time I spent just messing around and trying to add more damage to the texture.

That's all for now, thanks for reading!

Wednesday, August 10, 2016

Texture Tuesday - Aug 9, 2016

So I was thinking the other day that its been a while since I've actually posted any art on this blog of mine, it most been programming/coding related stuff for the last 8 months or so. So since Allegorithmic recently made their software free for students, I decided to get a free license and start to do some art for this blog.

Since I don't know much about Substance Designer, I looked up a tutorial to get me back into it and I created a metal floor texture following this tutorial:


I really like this guy since he takes his time to explain the tool at the beginning and all. This will be really useful for anyone that is new to the software package. Without further ado, here are a couple renders from the finished product:



It took me a bit over an hour to finish the tutorial and about 15 minutes to get a good render on Marmoset Toolbag, but I am really happy with the result. I forgot how awesome this software package is, and I look forward to working on one of these textures every week if I have time from now on.

That's all for now, thanks for reading!

Wednesday, June 15, 2016

Converting Test to NUnit

So we have been working on converting tests over to NUnit for a couple days now, and we have found a couple different things:

  1. Converting tests to NUnit is not very hard; we had to do some restructuring, but it was no big deal. 
  2. But the tests are not running in parallel like we want them to. We aren't really sure why this is, but we think it has to do with how the code was structured.
  3. We have now decided to scrap everything and start from scratch instead of trying to work with the existing code. 
So now that we have decided to start over and write everything ourselves, its probably going to take at least a month or two. While this means having to redo everything, I'm actually excited about this because it will give me the experience necessary on working on a web-testing framework done from the ground up. 

We are still going to use NUnit to run the tests, and we just have to start working on creating the proof of concept with some small test. Once we can prove that those small tests can run in parallel, we will have the green light to finish the project.

That's all for now, thanks for reading!

Friday, June 10, 2016

Parallel Test Execution

So after doing some research on how to run parallel test using Selenium Grid, I found out a few different things that I hope will be helpful to others:

First, running tests in parallel is actually not up to Visual Studio, Selenium Grid, or the language you are using (Ex: C#). That task falls onto the test runner as long as it supports it. The built in test runner on Visual Studio is called MSTest, and it doesn't support this function automatically. I read on some sites that you are able to change some stuff around to force it, but its not worth it in my opinion.

Second, there are a few different test runners that can run multiple test at once. The ones that I found are NUnit and XUnit for C# and TestNG for Java. I'm sure there are more, but those are the ones that I looked into. There are many differences between NUnit and XUnit, but it looks like NUnit is the one that is most like MSTest and therefore would require the least amount of work in converting the test to be compatible in NUnit.

Third, I had been looking for a while on some tutorials, but since I didn't really know what I was looking for I had a hard time. Once we had settled on NUnit as the test runner for the project we are converting, I was able to find a tutorial series on YouTube that explains in great detail how to run multiple tests at once and even how to run the same test using different browsers.

Now that we know what we are doing, we will be working the next few days on getting a few test converted over and see if we can get it to work properly. That's all for now, thanks for reading!

Tuesday, June 7, 2016

Test Execution Using Selenium Grid

So as I mentioned last time, I have been at work trying to figure out how to get tests to run on Selenium Grid, which wasn't that hard to figure out. The set up just needs a few manual steps, buts its really easy.

First, there is only a few lines of code that we need change in order for it to work. If you remember my last post on Selenium, I will be using the same code I did then and just update it.

The new code looks something like this:

using System;
using System.Diagnostics;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

namespace SeleniumTest
{
    class GenerateTokens
    {
        private RemoteWebDriver driver;

        public static void Main()
        {
            Generator();
            Environment.Exit(1);
        }

        private static void Generator()
        {
            var capabilities = new DesiredCapabilities();
            capabilities.SetCapability(CapabilityType.BrowserName, "chrome");
            capabilities.SetCapability(CapabilityType.Platform, new Platform(PlatformType.Windows));
            driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), capabilities);
            driver.Manage().Window.Maximize();

            driver.Url = "some-site.com";

            for (int counter = 0; counter < 10; counter++)
            {
                // Do something 
            }

            driver.Quit();
        }
    }
}

As you can see, we use a RemoteWebDriver object instead of just a IWebdriver like we did before. This basically is saying that the test will not be running locally (but it can, more on that later) and that we will be using Selenium Grid to run the test on a different machine. We specify that we want to run the test on a machine that has Chrome as the browser and that its also a Windows machine. After that, we don't really care what computer is running those test, all we care is that it meets those two requirements for the test.

But if you were to run this test now, it would fail, because it wouldn't be able to run the test locally. The test runner is looking for an instance of Selenium Grid at the address that you provided "http://localhost:4444/wd/hub" and it can't find it. Now you have to set up the grid with only one hub and at least one node to run the test. Here are the steps for the set up:
  1. First you have to have Java installed in your machine and make sure that it was added to your PATH. 
  2. Next download "Selenium Standalone Server" from the Selenium downloads page. And put it in a folder that you want, I created a folder in my C driver called Selenium for it. 
  3. You will need to open a command window and navigate to the folder and enter: "java -jar selenium-server-standalone-2.53.0.jar -role hub"
  4. You will then need to open a new command window and navigate to the folder again and enter: "java -jar selenium-server-standalone-2.53.0.jar -role node  -hub http://localhost:4444/grid/register"
At this point you have now set up a grid, comprised of just your computer but it it will get the job done for now. If you open a browser window and go to "http://localhost:4444/grid/console", you will see that your grid has one node available to run tests and which browsers are available on the node.

Now if you run the test that we wrote before, it will work. The test runner will send a test to the server and the server will then decide which "node" to send the test to. Then the server will return the test result to the test runner. That's a really simplistic way of explaining the process, but at least that's how I understand it.

We are still running into issues at work where we can't get the tests to run in parallel, but hopefully we will figure it out soon. That's all for now, thanks for reading!

Friday, June 3, 2016

Baptized by Fire

So I have now been at my new job as a Jr QA Engineer for a little over a week now, and I am no longer as nervous/scared as I was before. But I am still trying to make sure that I understand everything quickly.

For the last week I haven't been doing much, other than getting to know what the automated tests look like that we run on our website. But now I have been given my first assignment, luckily I won't be working on it alone. Another guy started at the company a few days before I joined the team last week, and while he has a ton more experience we are both new to QA Engineering in general, so they decided to pair us up.

We are going to be working on a few different things:

  1. Moving the automated test from an old TFS server and getting it all migrated to GitHub. 
  2. Update the test to make sure they run on Selenium Grid.
  3. Update the tests to that we can run multiple tests at once in parallel using Selenium Grid.
  4. Make the tests run/kick-off from GitHub instead of TFS when a new build gets pushed to the QA environment.
That last one I am not really sure how we are going to do at all, but the other ones I have been researching for the last few days... but there is a problem. All the documentation that I've found is either old, outdated, or for Java and not C# (which is the language which all the test are written in).

I think I am getting close to getting the test to run on Selenium Grid, I am still not sure how to get multiple tests to run at once in parallel. I know that we have to use a testing framework that allows for multi threading, but so far I haven't figured it out.

I will keep looking into it, and when I figure it out I promise to make a tutorial on this site and Youtube. I hate how hard this has been and if I can help someone else, I will do my best.

Anyways, that's all for now and thanks for reading!

Wednesday, May 25, 2016

To Do App - Finished

So the last few days I've been working hard to get a finished To Do web app finished. Its not like I have to finish it by a certain date, but I really wanted to finish it before I started my new position. And I am happy to say that I have succeed on the most part, but there are a few things that I still want to do. Let me explain in the following screenshots:


The screenshot above is of my home page, its really similar to my mockup that I created a few days ago. The biggest difference is that I added tabs to the task list. One tab shows tasks that are outstanding, and the other shows the tasks that have been marked as completed.


The reason I added the separate tabs is that I didn't really know what to do with the tasks that were marked as done. I didn't want to delete them from the database, and I didn't want to leave them in the same list as the outstanding tasks. I decided that having a list of completed tasks would be the best thing to do.


Adding a new task also didn't work out as I wanted it to. In my mockup, I had planned to use a modal that would keep the user in the same page, but I couldn't figure out how to do it that way. The only way I could add a new item was to go to a dedicated page for adding a task, and then take the user back to the homepage with the new task.

On the home page, each task has three buttons that allows the user to perform an action on the task that it belongs to: Edit, Details, & Delete. Delete is self explanatory, it simply deletes the task from the SQL database and by extension from the list.


Edit and details are almost the same, so I will cover them at once. Edit allows you to go into the task and update any information for it. For example: if you need to add notes or change the due date you can do that in the edit page. The you save it and it updates in the database as well as on the list. This is also the page to mark the task as "Done" when you have completed the task. I was trying to figure out how to do it from the home page, but I couldn't.

The details page is exactly like the edit page, but its a "read-only" version and you can't change any of the information, you have to go to the edit page to do so.


And finally here is my database that I set up on MySQL. Its a really simple table with only 6 columns. The book that I got on SQL really helped me out on how I should set up the table. I am not done with the book yet, I think I am only a 1/4 of the way done with the book, but I already know way more than I did a week ago about SQL.

I will try to keep working on the app if I have time to make it better and work from a single page, but for now I am done. I am super nervous at the moment since I start my new job in the morning (its almost 1 AM), and I don't really know what it will be like. But I am ready and I hope that I leave a good impression so I can stay on the team after the 90 day trail ends. That's all for now, thanks for reading!

Sunday, May 22, 2016

To Do App - Mockup

Since I don't have any experience with web development, I have been looking into how to build my to do app using Microsoft's MVC framework. For now I have an idea of how I want the final thing to look like, here are a couple of images of the mockup I made:


This is the home page, where it will show the list of outstanding tasks with a few buttons for actions on each task.


To add a new task, I want to create a modal that would allow the user to type in all the important information and then add it to the list.

As I mentioned before, this is just a mockup, so none of it is actually being persisted on a SQL database. I don't really know how I'm going to do all this, but I am still working on it. All that you see up there is just some tweaking that I made to the sample project and some simple UI updates using Bootstrap.

That's all for now, thanks for reading!

Friday, May 20, 2016

Prepping for the New Job

So since I got the new good news a couple days ago about my new position next week, I have started to try and learn more in the areas that I didn't do well during the interview.

Over the next few days I plan to learn as much as I can about SQL and websites using the MVC framework.

The first is obvious, like I've said before, my knowledge of SQL is very limited. I know that I won't become a SQL master over the weekend, but I hope to know at least the basics. My job actually bought me a book that I can use called Teach Yourself SQL in 10 Minutes. There are plenty of free resources available online to help me, but my manger thought this would be a better option so they got me the book for free. I really love working there.

I will also try to build a simple website using ASP.NET and the MVC framework because that is usually what new developers do in the company. For the first few weeks, new developers have to build a simple To Do List web app. Basically its an app that should allow a user to keep track of tasks, a user should be able to: Create, Read, Update, and Delete tasks. These tasks should be persisted to a database of some kind. Normally they use a NoSQL data base like RavenDB, but since I am learning SQL I will use MySQL DB for this web app. I don't know a single thing about web development, but I will try my best.

That's all for now, thanks for reading!

Wednesday, May 18, 2016

So I Got the Job...

So a couple of days ago I posted about an interview I had at work for a Jr QA Engineer position, and by what I can only call luck... I got the job! I start next week after my current sprint is over at work.

Basically what happened is that a couple of other people had applied for the position, but on the day of their interview (yesterday), they canceled since they had accepted job offers somewhere else. So I guess by default I got it?

I know that I shouldn't be happy that I got the position by pure luck, but I am truly grateful that they decided to give me an opportunity since they could have easily just kept looking for someone else. Since there was a lot of stuff I didn't know about databases in general, I am actually joining the team as a temp. If I do well in the first 90 days, then I get to stay on the team. I am going to give it my all and try to learn as much as possible in this position. I hope that with this job I will get the required experience needed and one day be a full fledged QA Engineer one day.

Needless to say, I am super happy right now and I can't wait for this next challenge. I am also super nervous, but I will just face it as it comes.

That's all for now, thanks for reading!

Monday, May 16, 2016

Jr QA Engineer Interview

So today I had an interview for a Jr QA Engineer at my work place, and since it was my first engineering interview I didn't really know what to expect. And I have to say that I was not ready for some of the stuff that they were going to ask me.

The interview started with some SQL and database questions. I had tried to study some basic SQL stuff over the weekend, but I didn't think that they were going to ask me anything about it, I figured they would focus more on my C# experience. Since my experience with SQL and databases is very limited, I think its safe to say that I failed this part of the interview.

Next they moved on to some OOP (Object Oriented Programming) questions and I'm happy to say that I did much better in this sections. They asked me a few different questions on what inheritance was, when would you implement inheritance, and a few other questions. I struggled a bit on explaining myself, but I got through it.

Next was probably my favorite part, actual coding on a white board. They asked me how I would write a function that would calculate the factorial of a given number. This part I spent probably a couple of minutes since it was really straight forward. This is the code I wrote:

public static int Factorial(int n)
{
    int result = 1;

    for (int i = n; i > 0; i--)
        result = result * i;

    return result;
}

They looked at the code, and told me it was good. Then they asked me to rewrite the function using recursion. I struggled a bit on this part, I had trouble trying to put into code what I had already done in a different way. They gave me a hint saying that 5! = 5 * 4! and that was all I needed. Here is the code I wrote:

public static int FactorialRecursive(int n)
{
    int current = n;

    if (n == 1)
        return n;

    int next = FactorialRecursive(n - 1);

    return current * next;
}

Overall I think I did much better in the second part of the interview than the first. I am not too hopeful on getting the position, but at least now I know what I need to work on and I am ready for the future. That is all for now, thanks for reading!

Wednesday, May 11, 2016

Learning Selenium WebDriver

So as you can probably tell my my recent blog posts, I have been trying to get more into coding and learning different things that will help me become a developer in the future.

Since I am a QA Specialist, I've heard the buzzwords "selenium" and "automated test" thrown around the office, but I didn't really know what any of those were. So I decided to start looking into it and try to understand how Selenium works and how to make automated test.

After spending sometime looking at some videos on Pluralsight, I got the basic idea that basically you can use a programming language like C# and write a "script" on what you would like to do in a website. I did some basic examples, but I didn't really think about it until yesterday.

In my current project at work, we are currently working on migrating our existing database from RavenDB to MartenDB. There are many documents that we have saved in the Raven database, and we are going to migrate each type of document. But in order to test it correctly, we were trying to find a simple way that would allows us to generate a lot of activity on the site, like customer's trying to reset passwords and see if it would affect the migration.

I had the idea that I could write a Selenium script that would do this for us on the site. Here is what I came up with:

using System;
using System.Diagnostics;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

namespace SeleniumTest
{
    class GenerateTokens
    {
        public static void Main()
        {
            Generator();
            Environment.Exit(1);
        }

        private static void Generator()
        {
            IWebDriver driver = new ChromeDriver(@"C:\Libraries\");
            driver.Url = "some-site.com";

            Debug.Assert(driver.PageSource.Contains("A message has been sent with directions on how to reset your password.") == false);

            for (int counter = 0; counter < 100; counter++)
            {
                driver.FindElement(By.Id("forgot-link")).Click();

                IWebElement email = driver.FindElement(By.Name("Email"));
                email.SendKeys("some-email@some-domain.com");

                driver.FindElement(By.ClassName("btn-primary")).Click();

                driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(2));

                Debug.Assert(driver.PageSource.Contains("A message has been sent with directions on how to reset your password.") == true);
            }

            driver.Quit();
        }
    }
}

This script would essentially go to a site and go through the steps a customer would take to recover their password on their account. The script would repeat it 100 times (but it can be increased if we wanted) and we wouldn't have to worry about doing it ourselves manually. The downside to this script, is that it would perform the same action for the same account/email address provided. I was thinking of maybe modifying this script to read a text file that contained a lot of different email address that it would just input on the site.

I don't think this script will actually get used at work since I am not a QA Engineer, and I think they might have a better approach at doing this with some internal tool, but I thought that it was interesting how easy this was to write.

Anyways, that's all for now. Thanks for reading!

Tuesday, May 10, 2016

The End of Disney Infinity

As most people know by now, Disney Infinity has come an end... by the sound of things is was kind of a surprise to everyone that Disney decided to end the production of the game.

I haven't worked at Avalanche since September of last year, so I don't really know what went down but all my friends that still worked there are really shocked at the news. I just hope that everyone there is able to find another position at other studios soon.

I was only a game ester in my short time at Avalanche, but I loved my time there and it thanks to them that I am now a software tester.

That's all for now, thanks for reading!

Sunday, May 8, 2016

Caesar Cipher in C#

So I was talking to a co-worker the other day and the topic of a Caesar Cipher came up in our conversation. We talked about how it wouldn't be too hard to code something quick that would be able to "encrypt" some text.

So I was kind of bored over this weekend, and I decided that it would be a good exercise to write a Caesar Cipher. Here is my code:

class CaesarCipher
{
    private string Sentence;
    private int EncryptShift;
    private int DecryptShift;
    private bool IsEncrypted = false;

    public CaesarCipher(string input, int shifting)
    {
        Sentence = input.ToLower();
        EncryptShift = shifting;
        DecryptShift = -shifting;
    }

    public string Encrypt()
    {
        if (IsEncrypted)
            return Sentence;

        char[] char_array = Sentence.ToCharArray();

        Shuffle(char_array, EncryptShift);

        Recunstruct(char_array);

        return Sentence;
    }

    public string Decrypt()
    {
        if (!IsEncrypted)
            return Sentence;

        char[] char_array = Sentence.ToCharArray();

        Shuffle(char_array, DecryptShift);

        Recunstruct(char_array);

        return Sentence;
    }

    private void Shuffle(char[] char_array, int shift)
    {
        for (int index = 0; index < char_array.Length; index++)
        {
            char letter = char_array[index];

            if (letter >= 'a' && letter <= 'z')
            {
                letter = (char)(letter + shift);

                if (letter > 'z')
                    letter = (char)(letter - 26);

                else if (letter < 'a')
                    letter = (char)(letter + 26);
            }

            char_array[index] = letter;
        }
    }

    private void Recunstruct(char[] char_array)
    {
        Sentence = null;

        foreach (char letter in char_array)
            Sentence += letter;

        IsEncrypted = true;
    }
}

That's all for now, thanks for reading!

Wednesday, May 4, 2016

Max & Min Heap

So now that class is over and I took my final for my CS2420 class last night, I find that I have come to love programming and I miss not having an assignment to work on. So today I decided that since I had already created a Max Heap class, that I should also create a Min Heap class.

While I was working, I found that 99% of the code was going to be the same, and I didn't want to just create a copy and tweak a few lines. So instead I decided to create a abstract Heap class that I could inherit from.

So I created the base class and moved most of the code to that file. Then I made the Max and Min Heap classes and made the changes required in each class to make it work. While this also wasn't that hard, I think that it was a good exerciser. I did something similar in the Components assignment, but I think this was a much better example of how to use inheritance.

Here is my code:


That's all for now, thanks for reading!

Friday, April 29, 2016

Stack Class in C#

So this week there is no more homework for my C# class since the semester is coming to an end and we have a final exam next week.

Since I was bored at work, I started thinking that we never created a stack for one of the class assignments. So I decided to create my own, which wasn't that hard since its essentially just a wrapper around an array.

I started to work on it yesterday for a couple hours and finished it this morning.

Here is my code:


Thanks for reading!

Wednesday, April 27, 2016

CS 2420 - Assignment 9 - Max Heap

This week's assignment is not as hard as the last one, we just have to create a heap data structure. We had the choice of either creating a min heap or max heap, so I went with Max since it made the most sense to me.

While the assignment its self wasn't too hard, it took me a while to do all the conditional logic behind the Sink() function.

Here is my code:

using System;
using System.Collections;
using System.Collections.Generic;

namespace Assignment9
{
    class MaxHeap<T> : IEnumerable<T> where T : IComparable
    {
        private T[] UnderlyingArray;
        private int ElementCount = 0;
        private int OldCount = 0;
        private bool IsHeap = true;

        public MaxHeap(int starting_size)
        {
            UnderlyingArray = new T[starting_size];
        }

        public MaxHeap()
        {
            UnderlyingArray = new T[5];
        }

        public int Count
        {
            get
            {
                return ElementCount;
            }
        }

        public void Clear()
        {
            UnderlyingArray = new T[UnderlyingArray.Length];
        }

        public T this[int index]
        {
            get
            {
                return UnderlyingArray[index];
            }
        }

        public void Add(T new_value)
        {
            if (!IsHeap)
                BuildHeap();

            if (ElementCount == UnderlyingArray.Length)
                Resize();

            UnderlyingArray[ElementCount] = new_value;
            Swim();
            ElementCount++;
        }

        public T PopTop()
        {
            if (!IsHeap)
                BuildHeap();

            T max = UnderlyingArray[0];

            Swap(0, ElementCount - 1);
            UnderlyingArray[ElementCount - 1] = default(T);
            ElementCount--;
            Sink();
            
            return max;
        }

        public void Sort()
        {
            if (!IsHeap)
                BuildHeap();

            OldCount = ElementCount;

            for (int i = 0; i < OldCount; i++)
            {
                Swap(0, ElementCount - 1);
                ElementCount--;
                Sink();
            }

            IsHeap = false;
            ElementCount = OldCount;
        }

        public void BuildHeap()
        {
            if (IsHeap)
                return;

            int last_item = OldCount - 1;

            for (int index = 0; index < OldCount / 2; index++)
            {
                Swap(index, last_item);
                last_item--;
            }

            ElementCount = OldCount;
            IsHeap = true;
        }

        private void Swim()
        {
            int current_index = ElementCount;

            while (current_index != 0)
            {
                int parent_index = FindParent(current_index);

                if (UnderlyingArray[current_index].CompareTo(UnderlyingArray[parent_index]) == 0)
                    break;

                else if (UnderlyingArray[current_index].CompareTo(UnderlyingArray[parent_index]) > 0)
                    Swap(current_index, parent_index);

                current_index = parent_index;
            }
        }

        private void Swap(int first, int second)
        {
            T temp = UnderlyingArray[first];
            UnderlyingArray[first] = UnderlyingArray[second];
            UnderlyingArray[second] = temp;
        }

        private void Sink()
        {
            int current_index = 0;

            while (current_index < ElementCount)
            {
                int max_child_index = current_index;
                int left_child_index = FindLeft(current_index);
                int right_child_index = FindRight(current_index);

                if (left_child_index >= ElementCount)
                    break;

                if (right_child_index >= ElementCount)
                    max_child_index = left_child_index;

                if (right_child_index < ElementCount &&
                    UnderlyingArray[left_child_index].CompareTo(UnderlyingArray[right_child_index]) == 0)
                    max_child_index = left_child_index;

                if (right_child_index < ElementCount && 
                    UnderlyingArray[left_child_index].CompareTo(UnderlyingArray[right_child_index]) > 0)
                    max_child_index = left_child_index;

                if (right_child_index < ElementCount && 
                    UnderlyingArray[left_child_index].CompareTo(UnderlyingArray[right_child_index]) < 0)
                    max_child_index = right_child_index;

                if (UnderlyingArray[max_child_index].CompareTo(UnderlyingArray[current_index]) == 0)
                    break;

                if (UnderlyingArray[max_child_index].CompareTo(UnderlyingArray[current_index]) > 0)
                    Swap(current_index, max_child_index);

                current_index = max_child_index;
            }
        }

        private int FindParent(int current_index)
        {
            return (current_index - 1) / 2;
        }

        private int FindLeft(int current_index)
        {
            return (current_index * 2) + 1;
        }

        private int FindRight(int current_index)
        {
            return (current_index * 2) + 2;
        }

        private void Resize()
        {
            T[] new_array = new T[UnderlyingArray.Length * 2];

            for (int index = 0; index < UnderlyingArray.Length; index++)
                new_array[index] = UnderlyingArray[index];

            UnderlyingArray = new_array;
        }

        public IEnumerator<T> GetEnumerator()
        {
            for (int index = 0; index < ElementCount; index++)
            {
                T temp = UnderlyingArray[index];
                //Console.WriteLine("Current Value: {0}", temp);
                yield return temp;
            }
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }
    }
}

That's all for now, thanks for reading!

Wednesday, April 20, 2016

CS 2420 - Assignment 8 - Components

This week's assignment is a bit more fun that usual since we are got to build a "game."

The point of this week's assignment to learn how to use components to build a game, instead of hard coding everything like we usually do. We also had a chance to review inheritance and understand how it works.

This time around there is too much code involved for me to put it here like I usually do, but if you are interested in looking at the code you can look here:

https://github.com/fushinoryuu/EAE2420/tree/master/DataStructuresAndSorts/Assignment8

I created these main class files: Component, Entity, Grid, Point, and Power Up.

The Grid was essentially a 2D array and everything ran through this file, it represented the map the player was going to play on. It also updated itself on the position of each enemy and the player and then displayed itself on the console.

The player and the enemies in the game all inherited from the Entity class and used a bunch of components to make each unique. For example, enemies had a component that allowed them to wrap around the Grid but the player was bound and couldn't go past the edges of the grid. To do this there was two components and I just had to make sure to give one to the player and the other to the enemies.

Power Ups are a type of component, but they don't inherit from the component class. I made it so they would modify the player's action. For example I had a Teleport Power Up. When they stepped on it, they would get randomly taken to an empty spot in the map.

I had a lot of fun with this assignment, but it took a little longer than I anticipated.

Anyways, that's all for now. Thanks for reading!

Tuesday, April 12, 2016

CS 2420 - Assignment 7 - Hash Table

This week we had to write a hash table, also known as a dictionary. Hash tables are really nice because you can index with more than just integers, and they are faster running times than a regular array or a linked list.

Here is my code:


That's all for now, thanks for reading!

Wednesday, April 6, 2016

CS 2420 - Assignment 6 - A Star

So this week we had to create a node graph and write our version of the A* (A Star) algorithm to find the shortest path. Here is the map we were given:



The map is not to scale, here are the coordinates of each node: 

A: -19, 11        B: -13, 13      C: 4, 14          D: -4, 12      E: -8, 3           F: -18, 1
G: -12, -8        H: 12, -9         I: -18, -11       J: -4, -11     K: -12, -14     L: 2, -18
M: 18, -13       N: 4, -9          O: 22, 11        P: 18, 3

I have seen multiple implementations of A* around the web, but they all use a matrix and it can get really complicated really quickly. I like this implementation better because its simple, but it works.

Here is my code:


That's all for now, thanks for reading!

Wednesday, March 30, 2016

Breadth First Search - Matrix

So yesterday during class, we discussed how to make a path finding algorithm for a 2d map. I immediately thought of the example of flooding the map with water like I have seen before.

We didn't have to code it in class, we just had to know how one would write the algorithm. Last night I decided that I would try to code it and here is my work:


In my grid I make the starting cell marked with an X and the destination is marked with a D. The final path would be calculated by simply following the cell values in descending order to the final destination.

That's all for now, thanks for reading!

Thursday, March 24, 2016

CS 2420 - Assignment 5 - Part 5

So I just turned in my assignment a few minutes ago, and this is probably the hardest assignment yet. Most of the assignment was really simple actually, but the most challenging part was building the Expression Tree in the correct order.

This is because you have to keep the order of operations in mind when building the tree, Once the tree has been built in the correct order, its just a matter of doing a post-order traversal and evaluating as you go up the tree.

I kept thinking about how I should do this, and after talking to one of my friends, we realized that node rotations would be the simplest way to do it. So here is my code:

using System;
using System.Collections.Generic;

namespace Assignment5
{
    public TreeNode<string> root;

        public ExpressionTree(string input)
        {
            root = null;
            ExpressionParser parser = new ExpressionParser(this, input);
        }

        private class ExpressionParser
        {
            private Stack<TreeNode<string>> numberStack, operatorStack;

            public ExpressionParser(ExpressionTree tree, string input)
            {
                numberStack = new Stack<TreeNode<string>>();
                operatorStack = new Stack<TreeNode<string>>();
                string[] expressionArray = new string[input.Length];
                expressionArray = input.Split();

                BuildNodes(tree, expressionArray);
            }

            private void BuildNodes(ExpressionTree tree, string[] expressionArray)
            {
                foreach (string item in expressionArray)
                {
                    double tempNumber;
                    if (double.TryParse(item, out tempNumber))
                    {
                        TreeNode<string> number_node = new TreeNode<string> 
                            { Data = tempNumber.ToString() };
                        numberStack.Push(number_node);
                    }
                    else
                    {
                        TreeNode<string> operator_node = new TreeNode<string> 
                            { Data = item };
                        operatorStack.Push(operator_node);
                    }
                }
                BuildTree(tree);

            }

            private void BuildTree(ExpressionTree tree)
            {
                while (operatorStack.Count != 0)
                {
                    TreeNode<string> tempRoot = operatorStack.Pop();
                    tempRoot.Right = numberStack.Pop();
                    tempRoot.Left = numberStack.Pop();

                    if((tempRoot.Data == "*" || tempRoot.Data == "/") && 
                        (tempRoot.Right.Data == "+" || tempRoot.Right.Data == "-"))
                    {
                        tempRoot = tree.RotateLeft(tempRoot);
                    }
                    numberStack.Push(tempRoot);
                }
                TreeNode<string> subTree = numberStack.Pop();
                tree.root = tree.RotateLeft(subTree);
            }
        }

        private TreeNode<string> RotateLeft(TreeNode<string> currentNode)
        {
            TreeNode<string> tempNode = currentNode;
            currentNode = currentNode.Right;
            tempNode.Right = currentNode.Left;
            currentNode.Left = tempNode;
            return currentNode;
        }

        public void Evaluate(TreeNode<string> node)
        {
            if (node.Left != null)
                Evaluate(node.Left);
            if (node.Right != null)
                Evaluate(node.Right);
            switch (node.Data)
            {
                case "+":
                    double addResult = double.Parse(node.Left.Data) + 
                        double.Parse(node.Right.Data);
                    node.Data = addResult.ToString();
                    node.Left = null;
                    node.Right = null;
                    break;
                case "-":
                    double subResult = double.Parse(node.Left.Data) - 
                        double.Parse(node.Right.Data);
                    node.Data = subResult.ToString();
                    node.Left = null;
                    node.Right = null;
                    break;
                case "*":
                    double multResult = double.Parse(node.Left.Data) * 
                        double.Parse(node.Right.Data);
                    node.Data = multResult.ToString();
                    node.Left = null;
                    node.Right = null;
                    break;
                case "/":
                    double divResult = double.Parse(node.Left.Data) / 
                        double.Parse(node.Right.Data);
                    node.Data = divResult.ToString();
                    node.Left = null;
                    node.Right = null;
                    break;
                case "^":
                    double expResult = Math.Pow(double.Parse(node.Left.Data), 
                        double.Parse(node.Right.Data));
                    node.Data = expResult.ToString();
                    node.Left = null;
                    node.Right = null;
                    break;
            }
        }

        public string TraversePre(MyList<string> list, TreeNode<string> node)
        {
            list.Add(node.Data);
            if (node.Left != null)
                TraversePre(list, node.Left);
            if (node.Right != null)
                TraversePre(list, node.Right);
            return string.Join(", ", list);
        }

        public string TraverseIn(MyList<string> list, TreeNode<string> node)
        {
            if (node.Left != null)
                TraverseIn(list, node.Left);
            list.Add(node.Data);
            if (node.Right != null)
                TraverseIn(list, node.Right);
            return string.Join(", ", list);
        }

        public string TraversePost(MyList<string> list, TreeNode<string> node)
        {
            if (node.Left != null)
                TraversePost(list, node.Left);
            if (node.Right != null)
                TraversePost(list, node.Right);
            list.Add(node.Data);
            return string.Join(", ", list);
        }
    }
}

I was not able to make my Binary Search Tree self balancing. I know what I need to do, but I never had time to actually implement the code. I will try to finish writing the code and post it here when I'm done with my AVL tree.

Anyways, that's all for now. Thanks for reading!

Wednesday, March 16, 2016

CS 2420 - Assignment 5 - Part 4

So I've been working more on my Expression Tree and after talking to another student, I realized that I could restructure my files.The Expression Tree works with a total of 3 class files: the Node, the expression parser, and the tree class itself.

At first I had created each class in separate class files, but it was kind of weird how I was parsing the input and how I was building the tree. So I decided to move my Expression Parser class to be nested within my Expression Tree class. This would allow me to do all the parsing and building of the tree within one class file instead of two where it can get messy and confusing.

Here is my new code, thanks for reading:

using System;
using System.Collections.Generic;

namespace Assignment5
{
    class ExpressionTree
    {
        public TreeNode<string> root;
        private int node_count;

        public ExpressionTree(string input)
        {
            root = null;
            ExpressionParser parser = new ExpressionParser(this, input);
        }

        private class ExpressionParser
        {
            private Stack<TreeNode<string>> numberStack, operatorStack;

            public ExpressionParser(ExpressionTree tree, string input)
            {
                numberStack = new Stack<TreeNode<string>>();
                operatorStack = new Stack<TreeNode<string>>();
                Console.WriteLine(input.Length);
                string[] expressionArray = new string[input.Length];
                expressionArray = input.Split();

                BuildNodes(tree, expressionArray);
            }

            private void BuildNodes(ExpressionTree tree, string[] expressionArray)
            {
                foreach (string item in expressionArray)
                {
                    int tempInt;
                    if (Int32.TryParse(item, out tempInt))
                    {
                        TreeNode<string> number_node = new TreeNode<string> { Data = tempInt.ToString() };
                        numberStack.Push(number_node);
                    }
                    else
                    {
                        TreeNode<string> operator_node = new TreeNode<string> { Data = item };
                        operatorStack.Push(operator_node);
                    }
                }
                BuildTree(tree);
            }

            private void BuildTree(ExpressionTree tree)
            {
                tree.node_count = numberStack.Count + operatorStack.Count;

                while (operatorStack.Count != 0)
                {
                    TreeNode<string> tempRoot = operatorStack.Pop();
                    tempRoot.Right = numberStack.Pop();
                    tempRoot.Left = numberStack.Pop();
                    numberStack.Push(tempRoot);
                }

                tree.root = numberStack.Pop();
            }
        }

        public int NodeCount
        {
            get
            {
                return node_count;
            }
        }

        // TODO Finish Evaluate
        public void Evaluate(MyList<string> list, TreeNode<string> node)
        {
            if (node.Left != null)
                Evaluate(list, node.Left);
            if (node.Right != null)
                Evaluate(list, node.Right);
            throw new NotImplementedException();
        }

        public string TraversePre(MyList<string> list, TreeNode<string> node)
        {
            list.Add(node.Data);
            if (node.Left != null)
                TraversePre(list, node.Left);
            if (node.Right != null)
                TraversePre(list, node.Right);
            return string.Join(", ", list);
        }

        public string TraverseIn(MyList<string> list, TreeNode<string> node)
        {
            if (node.Left != null)
                TraverseIn(list, node.Left);
            list.Add(node.Data);
            if (node.Right != null)
                TraverseIn(list, node.Right);
            return string.Join(", ", list);
        }

        public string TraversePost(MyList<string> list, TreeNode<string> node)
        {
            if (node.Left != null)
                TraversePost(list, node.Left);
            if (node.Right != null)
                TraversePost(list, node.Right);
            list.Add(node.Data);
            return string.Join(", ", list);
        }
    }
}

Wednesday, March 9, 2016

CS 2420 - Assignment 5 - Part 3

I have not been able to make my Binary Search Tree self balancing. I know how the nodes should behave on paper, but I haven't been able to do it in code.

Yesterday after class, I figured out how to finish my Expression Tree and the Parser that takes the user's input.

Expression Tree:

using System;

namespace Assignment5
{
    class ExpressionTree
    {
        public TreeNode<string> root;
        public int node_count;

        public ExpressionTree()
        {
            root = null;
        }

        // TODO Finish Evaluate
        public void Evaluate()
        {

        }

        public string TraversePre(MyList<string> list, TreeNode<string> node)
        {
            list.Add(node.data);
            if (node.left != null)
                TraversePre(list, node.left);
            if (node.right != null)
                TraversePre(list, node.right);
            return string.Join(", ", list);
        }

        public string TraverseIn(MyList<string> list, TreeNode<string> node)
        {
            if (node.left != null)
                TraverseIn(list, node.left);
            list.Add(node.data);
            if (node.right != null)
                TraverseIn(list, node.right);
            return string.Join(", ", list);
        }

        public string TraversePost(MyList<string> list, TreeNode<string> node)
        {
            if (node.left != null)
                TraversePost(list, node.left);
            if (node.right != null)
                TraversePost(list, node.right);
            list.Add(node.data);
            return string.Join(", ", list);
        }
    }
}

Parser:

using System;
using System.Collections;
using System.Collections.Generic;

namespace Assignment5
{
    class ExpressionParser
    {
        private Stack<TreeNode<string>> numberStack, operatorStack;

        public ExpressionParser(ExpressionTree ETree, string input)
        {
            numberStack = new Stack<TreeNode<string>>();
            operatorStack = new Stack<TreeNode<string>>();

            ToArray(ETree, input);
        }

        public void ToArray(ExpressionTree ETree, string input)
        {
            string[] expressions = new string[input.Length];
            expressions = input.Split();

            BuildNodes(expressions, ETree);
        }

        private void BuildNodes(string[] expressions, ExpressionTree ETree)
        {
            foreach (string item in expressions)
            {
                int tempInt;
                if (Int32.TryParse(item, out tempInt))
                {
                    TreeNode<string> number_node = new TreeNode<string> { data = tempInt.ToString() };
                    numberStack.Push(number_node);
                }
                else                {
                    TreeNode<string> operator_node = new TreeNode<string> { data = item };
                    operatorStack.Push(operator_node);
                }
            }
            BuildTree(ETree);
        }

        private void BuildTree(ExpressionTree ETree)
        {
            ETree.node_count = numberStack.Count + operatorStack.Count;

            while (operatorStack.Count != 0)
            {
                TreeNode<string> tempRoot = operatorStack.Pop();
                tempRoot.right = numberStack.Pop();
                tempRoot.left = numberStack.Pop();
                numberStack.Push(tempRoot);
            }

            ETree.root = numberStack.Pop();
        }
    }
}

I will continue to work on this assignment. Thanks for reading!

Sunday, March 6, 2016

CS 2420 - Assignment 5 - Part 2

So I've been working on my Binary Search tree a bit more, and I have made some changes since last time. For example, in the assignment the traverse functions need to return a string of the numbers instead of being void.

Here is what I have now:

using System;

class BinarySearchTree
{
    public TreeNode root;
    private int node_count;

    public BinarySearchTree()
    {
        root = null;
        node_count = 0;
    }

    public void Add(int item)
    {
        TreeNode new_node = new TreeNode(item);

        if (root == null)
            root = new_node;
        else
        {
            TreeNode crawler = root;

            while (crawler != null)
            {
                new_node.parent = crawler;
                if (item >= crawler.data)
                    crawler = crawler.right;
                else
                    crawler = crawler.left;
            }

            if (item >= new_node.parent.data)
                new_node.parent.right = new_node;
            else
                new_node.parent.left = new_node;
        }
        node_count++;
        CalculateHeight(root);
        Console.WriteLine("");
    }

    public TreeNode Contains(int item)
    {
        TreeNode crawler = root;

        while (crawler != null)
        {
            if (item == crawler.data)
                return crawler;
            else if (item >= crawler.data)
                crawler = crawler.right;
            else
                crawler = crawler.left;
        }
        return null;
    }

    // TODO Finish Remove function
    public void Remove(TreeNode node)
    {
        if (node == null)
            Console.WriteLine("\nCould not remove the node you were looking for!\n");
        else
        {
            //Work needed
        }
    }

    public void Clear()
    {
        root = null;
        node_count = 0;
    }

    public int NodeCount
    {
        get
        {
            return node_count;
        }
    }

    private void CalculateHeight(TreeNode node)
    {
        if (node.left != null)
            CalculateHeight(node.left);
        if (node.right != null)
            CalculateHeight(node.right);

        if (node.left != null && node.right != null)
            node.height = Math.Max(node.left.height, node.right.height) + 1;

        else if (node.left != null && node.right == null)
            node.height = node.left.height + 1;

        else if (node.left == null && node.right != null)
            node.height = node.right.height + 1;

        else if (node.left == null && node.right == null)
            node.height = 1;
        Console.WriteLine("Node value: {0} Node Height: {1}", node.data, node.height);
        CheckBalance(node);
    }

    private void CheckBalance(TreeNode node)
    {
        if (node.left == null && node.right == null)
            return;

        else if (node.left != null && node.right == null)
            if (node.left.height > 1)
                Rotate(node);

            else if (node.left == null && node.right != null)
                if (node.right.height > 1)
                    Rotate(node);

                else if (node.left != null && node.right != null)
                {
                    if (node.left.height > node.right.height + 1)
                        Rotate(node.left);
                    else if (node.right.height > node.left.height + 1)
                        Rotate(node.right);
                }
    }

    // TODO Finish Rotate function
    private void Rotate(TreeNode node)
    {
        //Work needed
    }

    public string TraversePre(MyList list, TreeNode node)
    {
        list.Add(node.data);
        if (node.left != null)
            TraversePre(list, node.left);
        if (node.right != null)
            TraversePre(list, node.right);
        return string.Join(", ", list);
    }

    public string TraverseIn(MyList list, TreeNode node)
    {
        if (node.left != null)
            TraverseIn(list, node.left);
        list.Add(node.data);
        if (node.right != null)
            TraverseIn(list, node.right);
        return string.Join(", ", list);
    }

    public string TraversePost(MyList list, TreeNode node)
    {
        if (node.left != null)
            TraversePost(list, node.left);
        if (node.right != null)
            TraversePost(list, node.right);
        list.Add(node.data);
        return string.Join(", ", list);
    }
}

There has been a few changes to the rest of the code as well. I have been trying to figure out how to make my tree self balancing. And while I have been able to calculate the depth/height of each node, I am running into issues on how I should rotate the nodes. I am also working on removing nodes, but I haven't made much progress in that department either.

Anyways, that's all for now. Thanks for reading!

Thursday, March 3, 2016

CS 2420 - Assignment 5 - Part 1

So even though there is no assignment this week, I asked the professor to post the next assignment early. It turns out that writing my Linked List class a few days ago was a good call, because the next assignment will be Trees!

The assignment will have us built two trees: a Binary Search Tree and a Binary Expression Tree.

I have started working on both, but I have been mainly focusing on the BS Tree since to me its the easiest of the two. I am actually almost done with the BS Tree, here is what I have:

class BinarySearchTree
{
    public TreeNode root;
    private int node_count;

    public BinarySearchTree()
    {
        root = null;
        node_count = 0;
    }

    public void Add(int item)
    {
        TreeNode new_node = new TreeNode(item);
        if (root == null)
            root = new_node;
        else
        {
            TreeNode crawler = root;

            while (crawler != null)
            {
                new_node.parent = crawler;
                if (item >= crawler.data)
                    crawler = crawler.right;
                else
                    crawler = crawler.left;
            }

            if (item >= new_node.parent.data)
                new_node.parent.right = new_node;
            else
                new_node.parent.left = new_node;
        }
        node_count++;
    }

    public bool Contains(int item)
    {
        TreeNode crawler = root;
        while (crawler != null)
        {
            if (item == crawler.data)
                return true;
            else if (item >= crawler.data)
                crawler = crawler.right;
            else
                crawler = crawler.left;
        }
        return false;
    }

    public void Clear()
    {
        root = null;
        node_count = 0;
    }

    public int NodeCount
    {
        get
        {
            return node_count;
        }
    }

    public void TraversePre(MyList list, TreeNode node)
    {
        list.Add(node.data);
        if (node.left != null)
            TraversePre(list, node.left);
        if (node.right != null)
            TraversePre(list, node.right);
    }

    public void TraverseIn(MyList list, TreeNode node)
    {
        if (node.left != null)
            TraverseIn(list, node.left);
        list.Add(node.data);
        if (node.right != null)
            TraverseIn(list, node.right);
    }

    public void TraversePost(MyList list, TreeNode node)
    {
        if (node.left != null)
            TraversePost(list, node.left);
        if (node.right != null)
            TraversePost(list, node.right);
        list.Add(node.data);
    }
}

My Binary Search Tree takes advantage of the List class I wrote for assignment 4 and of a Node class that has only three properties: Left, Right, & Parent. That's all for now, thanks for reading!

Tuesday, March 1, 2016

Linked List class in C#

So today I was bored at work, and decided to write a Linked List in C# to get more practice with the language and get more familiar with Visual Studio.

I also decided to make my own enumerator for the linked list. Here is what I wrote:

Friday, February 26, 2016

CS 2420 - Assignment 4 - Part 5

So now that I am done with the List class, I have moved on to another part of the assignment. This time I have to plot the running times of my sorts.

After thinking about it for a while, I decided that I would create a new class that would just be called from the Main function and it would sort lists of different sizes and it would output the time in milliseconds to a text file. This would make it easier to actually make a graph for each sort. In a graph, X would be the number of elements in the list and Y would be the time it took to sort the list.

Here is what I have for this new class:

using System;
using System.Diagnostics;
using System.IO;

class RunningTimes
{
    public static void SortPlot(ISorter sorter, int elements, string name)
    {
        Random randint = new Random();
        Stopwatch watch = new Stopwatch();
        StreamWriter file = new StreamWriter(@"ChristianMunoz_RunningTimes.txt", true);
        long time = watch.ElapsedMilliseconds;
        int[] list;

        while(elements > 0)
        {
            list = new int[elements];

            for (int i = 0; i < list.Length; i++)
                list[i] = randint.Next(1, 200);

            watch.Reset();
            watch.Start();
            sorter.sort(list, 0, list.Length);
            watch.Stop();
            time = watch.ElapsedMilliseconds;
            Console.WriteLine(time);

            file.WriteLine("Sort: {0} Element count: {1} Time in Milliseconds: {2}", name, elements, time);

            elements = elements - 10000;
        }
        file.WriteLine(" ");
        file.Close();
    }
}

In the part that says: @"ChristianMunoz_RunningTimes.txt" that is the location and name of the text file I'm creating. You can change the name to anything you want, and you can find the file in your pc by first going to the folder where you have your C# work: Documents\CSharp\DataStructuresAndSorts\Assignment4\bin\Debug. Or you can also replace the name and tell Visual Studio a specific location by pasting in a path that you want.

This is how I call the function from my main:

RunningTimes.SortPlot(qSorter, 70000, "Quick Sort");

Since this new class isn't doing anything special, I don't have to create a new instance of the class and I can just call it from my other file. In the above example: I pass in a Quick Sort object, I tell it how big I want my list to be (in this case it will be 70000 integers), and just for kicks I pass in a string to make it easier to read the txt file of the sort that I am on. The output of the file will look like this:

Quick Sort Element count: 70000 Time in Milliseconds: 93
Quick Sort Element count: 60000 Time in Milliseconds: 72
Quick Sort Element count: 50000 Time in Milliseconds: 48
Quick Sort Element count: 40000 Time in Milliseconds: 37
Quick Sort Element count: 30000 Time in Milliseconds: 20
Quick Sort Element count: 20000 Time in Milliseconds: S
Quick Sort Element count: 10000 Time in Milliseconds: 2

That's all for now, thanks for reading!

Thursday, February 25, 2016

CS 2420 - Assignment 4 - Part 4

Since last time I have been working on implementing my own Enumerator in my List class. I started to work on it Tuesday night while in class, but I was actually stuck on this assignment until earlier today when I figured it out.

Here is the finished Enumerator class:

private class myEnumerator : IEnumerator
{
    private MyList myList;
    private int index;

    public myEnumerator(MyList myList)
    {
        this.myList = myList;
        index = -1;
    }

    public bool MoveNext()
    {
        index++;
        return (index < myList.Count);
    }

    public T Current
    {
        get
        {
            return myList[index];
        }
    }

    object IEnumerator.Current
    {
        get
        {
            return Current;
        }
    }

    // Not Needed
    public void Dispose()
    {
        //Not Needed
    }

    public void Reset()
    {
        index = -1;
    }
}

This new class is embedded in the List class, and it just spits out the next item in the list. The cool thing about this new Enumerator is that it will stop as soon as it reached the Count of the items in the list instead of the length of the array. This way if there are any empty slots in the array, they won't get printed in the list.

That's all for now, thanks for reading!

Wednesday, February 24, 2016

Python Script for Work

So a few months ago I got a job working as a software tester at a company now called Willis Towers Watson. I have to say that I have loved working there, and its also given me an opportunity to keep working on expanding my knowledge of writing code.

A couple days ago, I was actually in the middle of testing an internal tool that we use to send client information to insurance providers. This tool generates XML files from the information that we collect from our customers, and then transmits the information to the insurance providers. We call these tools "dispatchers", and each carrier/provider has its own dispatcher that we use to send the information.

Whenever there is an update to a dispatcher, we have to generate the new XML files to make sure that they have the correct information. But this process can take a while since we have to go manually check each line of the XML to make sure that the information is there. This can get tedious and its just not efficient.

One of my team mates mentioned to me that it would be nice if there was a program we could use to check verify the changes instead of doing it by hand. This got me thinking, and I realized that it wouldn't be very hard to get something working. So today I spent part of the day working on a Python script that I could use to verify the updated XML files. Here is what I wrote:


This script takes two files, one file is the XML that we want to look at and the other is just a simple text file with all the tags that you want to verify that have been added/removed from the XML. I then simply print the tags that were found in the file and done.

While testing my code I found that there is a limitation to my script. For example: if I am looking for a tag call Name, the script will say that it has found the tag in the StateName or DoctorName tags. I haven't had time to work on it further, but hopefully I can figure out a way to search for an exact match only. But if not, I still think that my script will cut down in the time it takes for us to check XML files.

Anyways, that's all for now. Thanks for reading!

Monday, February 22, 2016

CS 2420 - Assignment 4 - Part 3

Its been a few days since my last entry, and I have to say that I have made a lot of progress with my List class. I have now finished everything except for creating my own Enumerator. I still haven't figured out how to write that part, hopefully it won't be too hard.

Here is what I have so far:

using System;
using System.Collections;
using System.Collections.Generic;

class MyList : IList
{
    private T[] underlyingArray;
    private int element_count;

    public MyList(int initial_size)
    {
        underlyingArray = new T[initial_size];
        element_count = 0;
    }

    public T this[int index]
    {
        get
        {
            return underlyingArray[index];
        }

        set
        {
            underlyingArray[index] = value;
        }
    }

    public int Count
    {
        get
        {
            return element_count;
        }
    }

    private void UpdateCount(int amount)
    {
        element_count += amount;
    }

    public bool IsReadOnly
    {
        get
        {
            return underlyingArray.IsReadOnly;
        }
    }

    public void Add(T item)
    {
        try
        {
            underlyingArray[Count] = item;
            UpdateCount(1);
        }
        catch (IndexOutOfRangeException)
        {
            Resize(underlyingArray);
            Add(item);
        }
    }

    public void Clear()
    {
        for (int index = 0; index < Count; index++)
            underlyingArray[index] = default(T);

        UpdateCount(-Count);
    }

    public void Resize(T[] array)
    {
        T[] newArray = new T[array.Length * 2];

        for (int index = 0; index < array.Length; index++)
            newArray[index] = array[index];

        underlyingArray = newArray;
    }

    public bool Contains(T item)
    {
        for (int index = 0; index < Count; index++)
            if (EqualityComparer.Default.Equals(underlyingArray[index], item))
                return true;
        return false;
    }

    public void CopyTo(T[] array, int arrayIndex)
    {
        if (Count == array.Length)
            Resize(array);

        for (int index = Count; index > arrayIndex; index--)
            array[index] = array[index - 1];

        underlyingArray = array;
    }

    public IEnumerator GetEnumerator()
    {
        for (int i = 0; i < underlyingArray.Length; i++)
            yield return underlyingArray[i];
    }

    // TODO No yield
    public IEnumerator GetEnumeratorNoYield()
    {
        throw new NotImplementedException();
    }

    public int IndexOf(T item)
    {
        for (int index = 0; index < Count; index++)
            if (EqualityComparer.Default.Equals(underlyingArray[index], item))
                return index;
        return -1;
    }

    public void Insert(int index, T item)
    {
        if (Count == underlyingArray.Length)
            Resize(underlyingArray);
        if (index >= Count)
            Add(item);
        else
        {
            CopyTo(underlyingArray, index);
            underlyingArray[index] = item;
            UpdateCount(1);
        }
    }

    public bool Remove(T item)
    {
        for (int index = 0; index < Count; index++)
            if (EqualityComparer.Default.Equals(underlyingArray[index], item))
            {
                RemoveAt(index);
                return true;
            }
        return false;
    }

    public void RemoveAt(int index)
    {
        while (index < Count - 1)
        {
            underlyingArray[index] = underlyingArray[index + 1];
            index++;
        }
        UpdateCount(-1);
        underlyingArray[Count] = default(T);
    }

    IEnumerator IEnumerable.GetEnumerator()
    {
        return GetEnumerator();
    }
}

I know that I probably still need to fix a bunch of stuff in my class, but for now I think I'm done with it. I will now focus on writing functions that put my List class to the test.

That's all for now, thanks for reading!

Wednesday, February 17, 2016

CS 2420 - Assignment 4 - Part 2

So I have now finished the first part of this assignment, and I have now moved on to creating a List class using the IList interface and Generics.

I am going to be honest here, I had no idea how to start this part of the assignment. At first I thought I was building another Linked List class, but after talking to a friend of mine he got me started on the right direction. He told me that I had to use an array and I had to manually keep track of the items in the array.

I can't just insert items into the array at any index, I have to keep it all together and I have to manage the size of the array as well or use any built in functions. Basically, this is going to be the hardest assignment I've done so far. Here is what I have so far:

using System;
using System.Collections;
using System.Collections.Generic;

class MyList : IList
{
    public T[] underlyingArray;
    private int element_count;

    public MyList(int initial_size)
    {
        this.underlyingArray = new T[initial_size];
        this.element_count = 0;
    }

    // TODO Implement: Indexer
    public T this[int index]
    {
        get
        {
            throw new NotImplementedException();
        }

        set
        {
            throw new NotImplementedException();
        }
    }

    public int Count
    {
        get
        {
            return this.element_count;
        }
    }

    public bool IsReadOnly
    {
        get
        {
            return this.underlyingArray.IsReadOnly;
        }
    }

    // TODO Handle Exception
    public void Add(T item)
    {
        if (element_count < this.underlyingArray.Length)
        {
            this.underlyingArray[element_count] = item;
            this.element_count++;
        }

        else
            throw new IndexOutOfRangeException();
    }

    public void Clear()
    {
        this.element_count = 0;
    }

    public bool Contains(T item)
    {
        for (int index = 0; index < Count; index++)
        {
            if (EqualityComparer.Default.Equals(underlyingArray[index], item));
                return true;
        }
        return false;
    }

    // TODO Implement: Copy
    public void CopyTo(T[] array, int arrayIndex)
    {
        throw new NotImplementedException();
    }

    // TODO Implement: Get Enumerator
    public IEnumerator GetEnumerator()
    {
        throw new NotImplementedException();
    }

    // TODO Implement: Index of
    public int IndexOf(T item)
    {
        throw new NotImplementedException();
    }

    // TODO Implement: Insert
    public void Insert(int index, T item)
    {
        throw new NotImplementedException();
    }

    // TODO Implement: Remove
    public bool Remove(T item)
    {
        throw new NotImplementedException();
    }

    // TODO Implement: Remove at
    public void RemoveAt(int index)
    {
        throw new NotImplementedException();
    }

    // TODO Implement: Get IEnumerable
    IEnumerator IEnumerable.GetEnumerator()
    {
        throw new NotImplementedException();
    }
}

So far I have only worked on a couple of functions, most importantly the Add function. This function will append an item to the end of the list, but I still haven't figured out how to manage the size of the array on my own.

That's all for now, thanks for reading!

Friday, February 12, 2016

CS 2420 - Assignment 4 - Part 1

Now that we have turned in the last assignment, its time to start on the next one. This time we are switching languages to C#, which hasn't been easy getting used to the new syntax.

The assignment is split in two parts, first I have to rewrite all my sorts that I've done in past assignments but I have to implement an interface on each sort.

So far I have finished most of the sorts and implement the interface on each. Here is my Quick Sort for reference:

class QuickSort : ISorter
{
    public void sort(int[] numbers, int low, int high)
    {
        if (low < high)
        {
            int pivot_location = partition(numbers, low, high);
            sort(numbers, low, pivot_location);
            sort(numbers, pivot_location + 1, high);
        }
    }

    private static int partition(int[] numbers, int low, int high)
    {
        int pivot = numbers[low];
        int wall = low;
        for (int i = low + 1; i < high; i++)
        {
            if (numbers[i] < pivot)
            {
                wall++;
                swap_numbers(numbers, i, wall);
            }
        }
        swap_numbers(numbers, low, wall);
        return wall;
    }

    private static void swap_numbers(int[] numbers, int index1, int index2)
    {
        int temp = numbers[index1];
        numbers[index1] = numbers[index2];
        numbers[index2] = temp;
    }
  
}

I will try to finish this part of the assignment as soon as possible so I can move to the next part. That's all for now, thanks for reading!

Wednesday, February 10, 2016

CS 2420 - Assignment 3

For assignment 3, we had to do two main things: create a linked list and a quicksort.

The Linked List was actually fairly straight forward, but the quicksort gave me the most trouble. Here is my file:

Monday, February 1, 2016

CS 2420 - Assignment 2

For assignment 2, we had to write a couple different sorting algorithms and learn how to use lamdas in our code.

The sorting algorithms gave me the most trouble, but I was able to figure it out. Here is my code:

Saturday, January 23, 2016

CS 2420 - Assignment 1

So this semester I'm taking another programming class, CS 2420 called "Intro to Algorithms and Data Structures".

For the first assignment we had to write a few different functions using Python, which is great because its the language that I am the most familiar with it. Here is what I have:

Friday, January 1, 2016

2048 Clone in Python

Let me start by saying Happy New Year to anyone that may be reading my blog!

So after I came back from my short vacation, I got sick and didn't have the energy to do anything. But I did have a chance to think for a while and I decided that I needed to get back into coding and brush up on my Python. The new semester starts in a bout a week or so and I need to get back into coding, even if I will be using Java in that class instead of Python. 

I decided that I should use Pygame (like I did a year ago in CS 1410 class) and create a simple game, and I decided to create a clone of the popular game 2048. I only started the other day and I have been working on getting a skeleton up and running and start planning on how I'm actually going to do this.

So far I have a simple screen with a "game board" displayed on the screen and I have started to work on the logic of the game before I do more "graphic" work. You can see my work on Github at the following link:


That's all for now, thanks for reading!