Wednesday, October 17, 2018

Bubble Sort and Bucket Sort

Bubble Sort

This sorting algorithm works by taking to elements within an array and compares the two. Depending on how it is sorting the elements in an array, will switch the two values around. For example, if we had an array [3, 17, 83, 6, 24, 52] and we want to order those elements, smallest to largest. The first two elements, 3 and 17 won’t be swapped, same applies for 17 and 83. However, with elements 83 and 6, the two will swap as 6 is less than 83. Once the algorithm has sorted through the array the first time, we should end up with [3, 17, 6, 24, 52, 83]. This array hasn't been sorted so the algorithm needs to run again or run until there are no changes to be made, which can take a while if the size of the array is large. The next pass will sort the array and give us [3, 6, 17, 24, 52, 83], which is correctly sorted, however the algorithm doesn't know that and therefore has to run a second time in order to make sure that no changes can be made and therefore give us our sorted array.
This sorting algorithm is slow to perform especially with large datasets as the increase in size means there will be an increase in possible elements that need sorting. However, this algorithm is simple to implement and get a computer to carry out.

Bucket Sort

This algorithm works by grouping elements within an array into buckets (hence the name), then if the bucket contains more than one element, that bucket is sorted using another algorithm such as bubble sort. Once each bucket has been sorted, their elements are put back into the array in its sorted ordering.
For example, if we had an array [4, 32, 13, 6, 27, 35, 19, 38] the algorithm will group the elements like so:
0 - 9 [4, 6]
10 - 19 [19, 13]
20 - 29 [27]
30 - 39 [35, 32, 38]
then each group will use the bubble sort to give us:
0 - 9 [4, 6]
10 - 19 [13, 19]
20 - 29 [27]
30 - 39 [32, 35, 38]
from this we can recreate the array to finally give us:
[4, 6, 13, 19, 27, 32, 35, 38]
The bucket sort is quicker than the bubble sort but will struggle when trying to sort arrays that do not contain numbers as if its sorting based on letters, there is a decision that needs to be made on how the elements are grouped. Do you have one bucket for each letter or do you have a bucket for a group of letters i.e. A, B and C?

Game Recommendations (September 2018)

So I might try to do this regularly (once a month), but here are a few recommendations of games that I have played recently. This month there are two games, the first being Minit and the second being The Spectrum Retreat, both being played on the Switch.
Minit is a roguelike game where you have 60 seconds or a minute to live before dying and being reset back to your house.
Pros:
  • Great soundtrack that I ended up listening to a lot after finishing the game
  • Some puzzles were challenging to solve but not overally stupid or confusing
  • Adorable graphics style both in game and out game.
Cons:
  • Managed to complete the game but missed like 50% of the game due to accidentally finding the end boss.
  • Got easily confused with some puzzles and power ups. For example, the long tree need to be chopped, my thought was to find an axe, but ended up needing some gardening gloves.
  • Some of the tasks are extremely hard to do within the 60 seconds given and were completed with less than a second to spare.
The Spectrum Retreat is a puzzle game in a similar vein to Portal, the main mechanic is swapping colours to get past force fields that match the same colour you have. There is also an intriguing narrative surrounding the game.
Pros:
  • The puzzles seemed balanced and the harder ones were completable after a few tries.
  • While some of the narrative was easy to guess it was still intriguing
  • Had a colour blindness option to switch out the three colours being used for the puzzles
Cons:
  • No checkpoint system, especially for the last level which is one long level and you restart from the beginning.
  • Some points of the narrative were easy to guess
  • Possibly due to the Switch, the engine used or both but there were a lot of lighting glitches, didn’t take away from the game but something I noticed whilst playing

Coding Challenge

So during work, my collegue had a excel sheet filled with numbers from 1 to 365 based on issues collected of a magazine, he wanted to see how many occurances of each issue number there was but also which issues were missing. I figured out the first part in excel using the countif function but that wasn't quick enough for him and I couldn't figure out a solution that would automate the process a bit more. However, I did say that I could write a program that would do all of the functionality in one go. So it became a race to see who could finish the task first. Technically I couldn't finish entirely as there was no programming facility built into the computers we were using so I had to use a online compiler (in this case cpp.sh) which meant I couldn't read in his data, but I could simulate it by randomly generating those numbers and create a quick proof of concept program. Below is the final code.

#include <iostream> #include <string> #include <vector> #include <stdio.h> #include <stdlib.h> /* srand, rand */ #include <time.h> /* time */ #include <algorithm> std::vector<int> GenerateNumbers(int count, int min, int max); std::vector<int> FindAllMissingNumbers(std::vector<int> _numbers, int count); void FindOccurances(std::vector<int> _numbers, int count); int main() { srand (time(NULL)); std::vector<int> numbers = GenerateNumbers(365, 1, 365); std::cout << std::endl; FindOccurances(numbers, 365); std::cout << std::endl; std::vector<int> missingNumbers = FindAllMissingNumbers(numbers, 365); int temp; std::cin >> temp; } std::vector<int> GenerateNumbers(int count, int min, int max) { std::vector<int> tempNumbers; for (int i = 0; i < count; i++) { int randInt = rand() % max + min; tempNumbers.push_back(randInt); std::cout << "Number Generated: " << randInt << std::endl; } return tempNumbers; } std::vector<int> FindAllMissingNumbers(std::vector<int> _numbers, int count) { std::vector<int> tempMissingNumbers; for (int i = 0; i < count; i++) { std::vector<int>::iterator it; it = std::find (_numbers.begin(), _numbers.end(), i); if (it != _numbers.end()) { std::cout << "Element: " << *it << " found" << std::endl; } else { tempMissingNumbers.push_back(i); std::cout << "Element: " << i << " not found" << std::endl; } } int missing = tempMissingNumbers.size(); std::cout << "Total Missing: " << missing << std::endl; int found = count - missing; std::cout << "Total Found: " << found << std::endl; return tempMissingNumbers; } void FindOccurances(std::vector<int> _numbers, int count) { int total = 0; for (int i = 0; i < count; i++) { int occurance = 0; for(std::vector<int>::iterator it = _numbers.begin(); it != _numbers.end(); ++it) { if (i == *it) { occurance++; } } std::cout << "Element: " << i << " occured: " << occurance << " times" <<std::endl; total += occurance; } std::cout << "Total amount of occurances: " << total << std::endl; }

Tuesday, October 16, 2018

Celeste

So like last month I have some recommendations for games to play. This was going to be one of those posts but I have so much to talk about with this game that a single post dedicated to it was needed. That game is Celeste, a precision platformer, where you play as Madeline (or whatever name you give her) and you have challenged yourself to climb Celeste, a mysterious mountain.

If you follow me on twitter you may have seen a few tweets I've made about the game, I really enjoyed it but I was hesitant to even buy the game, watching the trailer made the game seem impossible but it really wasn't. Sure I died a lot and got frustrated at times but nothing was impossible.

There's plenty of content in the game to challenge you further besides the main story, you can collect all of the strawberries, find all of the crystal hearts or unlock the b-sides and c-sides of the levels. There is also a Pico-8 version of the game built into the game itself, which is impressive from a technical standpoint but also allows the player to try the original version of the game.

If there's anything I would complain about is the directional dash. For a game that requires precision, there were a lot of times where I died due to dashing in the wrong direction even though I believe to be pushing the left analogue stick in the correct direction. Maybe I wasn't but it was frustrating to deal with and possibly could have be solved by changing some of the settings as you can change the game speed, thus allowing me enough time to make sure to dash in the correct direction.

Again I'm not 100% sure of the cause but it's something that was frustrating and actually used that experience to help decide how to handle the dash input within my dissertation project as there was a suggestion to use a similar control scheme to Celeste but only being able to dash left and right, instead of the current way in which the bumpers are used to dash either left or right. It minimises the amount of mistakes that player can make.

Besides being able to modify the game speed, the player has a variety of options as well to make the game more suited to them, such as infinite stamina or dash. This means that you can still play the game and enjoy the story in a way that suits you best, ultimately giving you the best experience possible.

This also impacted my dissertation project as while the prototype games difficulty would dynamically change between levels, the player still might need something to get them over the edge of they are stuck on a level or a specific part. While I didn't implement an assist system like Celeste's, I have one planned out that would borrow some features from Celeste's assist mode and include some of my own.

The art is incredible, both in terms of the pixel art and the high resolution art. With the pixel art you can easily identify everything, you know straight away if something will kill you or is there to help. But it also still conveys emotion, even though you can't actually see any facial features besides the high resolution art. You can still see and feel the emotions that Madeline has.

This also makes the story even more incredible as you start to become attached to Madeline and you get a connection between the player and Madeline. When she becomes anxious and/or scared, you actually start to worry and care about her. That's powerful stuff!

Finally, the music is awesome, each track matches the theme of each chapter but also doesn't get repetitive after dying countless times, which can be hard to achieve. The b-sides remixes also provide a fresh take on the originals and I haven't unlocked any c-sides levels so I'm not sure if there is another remix of those original tracks but if there are I'm sure it would be something different but the same as the original as well.

So yeah I highly recommend that you buy Celeste and give it ago, try it as the developers intended because you might discover that you can actually do a lot better than you expect! But if not there's always the assist mode!

Also to the developers, thanks for making such an amazing game and unknowingly providing a reference point helped inform my decisions on my dissertation project. My dissertation project has been one of my favourite projects to work on so far and that's thanks to you guys!

Tuesday, October 9, 2018

Notes on Unity Cinemachine Set Up

Unity Cinemachine
Requires the timeline plugin and the cinemachine plugin

Set up for 3D:
The main camera needs a cinemachine brain component
If there is already a virtual camera then that can be assigned within the brain component
Otherwise a new virtual camera can be created

Within the timeline we can add a cinemachine track
On that track we can create clips that use specific virtual cameras to achieve different shots
I.e. one clip can be stationary and tracks the player but the following clip can be following the player using a set offset

A blend state can be created between clips to create a transition between the two shots instead of a sharp cut

Each virtual camera has specific settings that can be modified, so you can assign a transform to either the look at variable or the follow variable to decide the behaviour of the camera

Dead zone is the area in which the camera will track the object its looking at
If the object is not in the dead zone it will not track that object and will wait until that object is.
Decrease the dead zone for a continuous pan
Increase the dead zone for a pan that happens close to the edge of the screen

Soft zone controls how much an object can move within the shot
A large soft zone provides a natural feel
A small soft zone provides a mechanical feel

Original Video