This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
notes:discrete:fall2021:projects:saf1 [2021/10/03 22:40] – [References] mpronti2 | notes:discrete:fall2021:projects:saf1 [2021/10/07 03:13] (current) – [Display] ccolocci | ||
---|---|---|---|
Line 7: | Line 7: | ||
=====Objective===== | =====Objective===== | ||
+ | |||
Using the TIC-80 fantasy console simulator on your pi, implement a program that performs a sorting of a randomized list of values, both displaying an animation of the sort, along with timing and keeping track of the approximate number of steps needed to accomplish the task for variable numbers of non-animated runtimes. | Using the TIC-80 fantasy console simulator on your pi, implement a program that performs a sorting of a randomized list of values, both displaying an animation of the sort, along with timing and keeping track of the approximate number of steps needed to accomplish the task for variable numbers of non-animated runtimes. | ||
Line 27: | Line 28: | ||
====Process==== | ====Process==== | ||
+ | |||
+ | ==Randomness in Lua== | ||
+ | |||
+ | As with the projects before, `math.random()` can be used to generate random values for the array. It may also have a different purpose depending on how you approach this project. While there are many ways to show the algorithms... rinse and repeat, or do a brand new array... one can use `math.random()` to randomize which algorithm is used to sort the array upon each new initialized array. | ||
+ | |||
+ | ==Bubble Sort== | ||
+ | |||
+ | Bubble Sort, sometimes called Sinking Sort, is a simple sorting algorithm that " | ||
+ | < | ||
+ | {5 7 3 9 2} -> {5 7 3 9 2} | ||
+ | {5 7 3 9 2} -> {5 3 7 9 2} | ||
+ | {5 3 7 9 2} -> {5 3 7 9 2} | ||
+ | {5 3 7 9 2} -> {5 3 7 2 9} | ||
+ | |||
+ | {5 3 7 2 9} -> {3 5 7 2 9} | ||
+ | {3 5 7 2 9} -> {3 5 7 2 9} | ||
+ | {3 5 7 2 9} -> {3 5 2 7 9} | ||
+ | {3 5 2 7 9} -> {3 5 2 7 9} | ||
+ | |||
+ | {3 5 2 7 9} -> {3 5 2 7 9} | ||
+ | {3 5 2 7 9} -> {3 2 5 7 9} | ||
+ | {3 2 5 7 9} -> {3 2 5 7 9} | ||
+ | {3 2 5 7 9} -> {3 2 5 7 9} | ||
+ | |||
+ | {3 2 5 7 9} -> {2 3 5 7 9} | ||
+ | {2 3 5 7 9} -> {2 3 5 7 9} | ||
+ | {2 3 5 7 9} -> {2 3 5 7 9} | ||
+ | {2 3 5 7 9} -> {2 3 5 7 9} | ||
+ | |||
+ | {2 3 5 7 9} -> {2 3 5 7 9} | ||
+ | {2 3 5 7 9} -> {2 3 5 7 9} | ||
+ | {2 3 5 7 9} -> {2 3 5 7 9} | ||
+ | {2 3 5 7 9} -> {2 3 5 7 9} | ||
+ | </ | ||
+ | You will notice that, in this specific example, the algorithm had to sweep through 5 times in order to reach the final result. You will also notice that the complete sorting was finished after pass 4, but the algorithm did a 5th one as well. This is because the algorithm has to do one whole pass without doing a swap in order for it to be considered a successful sort. You will soon read about an algorithm (next algorithm) that is very similar, except far more robust and faster. | ||
+ | |||
+ | ==Selection Sort== | ||
+ | |||
+ | Selection sort takes a more direct piecewise approach to sorting - it will run through the list again and again, each time finding the lowest element and moving it to the beginning. Simply following that process would actually only ever perform a single action, though. The details of implementation more closely follow these ideas: | ||
+ | |||
+ | < | ||
+ | x = list.findLowestFrom(0); | ||
+ | list.swap(x, | ||
+ | |||
+ | x = list.findLowestFrom(1); | ||
+ | list.swap(x, | ||
+ | |||
+ | x = list.findLowestFrom(2); | ||
+ | list.swap(x, | ||
+ | |||
+ | ... | ||
+ | </ | ||
+ | |||
+ | By placing the lowest found node one index further along in the list each time, this ensures that the previously found lowest nodes are not displaced from their rightful position at the lowest index. Additionally, | ||
+ | |||
+ | A basic example of this would look like((" | ||
+ | |||
+ | < | ||
+ | { 5 2 4 1 3 } | ||
+ | find lowest after 0 | ||
+ | swap with index 0 | ||
+ | { 1 2 4 5 3 } | ||
+ | find lowest after 1 | ||
+ | swap with index 1 | ||
+ | { 1 2 4 5 3 } | ||
+ | find lowest after 2 | ||
+ | swap with index 2 | ||
+ | { 1 2 3 5 4 } | ||
+ | find lowest after 3 | ||
+ | swap with index 3 | ||
+ | { 1 2 3 4 5 } | ||
+ | only one index remains, list must be in order | ||
+ | </ | ||
+ | |||
+ | This certainly isn't the only approach, but that should give a basic illustration of what the animation may represent. | ||
+ | |||
+ | ==Insertion Sort== | ||
+ | |||
+ | Insertion sort somewhat combines the incremental nature of bubble sort with the position-seeking ideas of selection sort. In insertion sort, the list is searched for the first element which is out of order (in our case, the first element which is lower than its predecessor) and then it is moved downward until it reaches a point where the element below it has a value which is lower than its own. Once that point is reached, it will continue searching for the initial situation of a lesser ancestor from the point which was reached in the previous operation and repeat until the last element is reached. | ||
====Display==== | ====Display==== | ||
+ | |||
+ | In order to meet project specifications, | ||
+ | |||
==A Note on the Print Function== | ==A Note on the Print Function== | ||
- | print() is a very versatile tool; there are so many things to play around with and so many different arguments to take advantage of. For example, these are the arguments for print(): text [x=0 y=0] [color=12] [fixed=false] [scale=1] [smallfont=false]. The first three are pretty self-explanatory, | + | print() is a very versatile tool; there are so many things to play around with and so many different arguments to take advantage of. For example, these are the arguments for print(): text [x=0 y=0] [color=12] [fixed=false] [scale=1] [smallfont=false]. The first three are pretty self-explanatory, |
+ | |||
+ | Alternatively, | ||
=====References===== | =====References===== | ||
https:// | https:// | ||
+ | |||
+ | https:// | ||
https:// | https:// | ||
+ | https:// | ||
+ | |||
+ | https:// | ||
=====Submission===== | =====Submission===== | ||
+ | |||
+ | To submit the game file, our " | ||
+ | |||
+ | //Of course, if you are using the TIC-80 application on your Pi then the file will exist there when saved.// | ||
+ | |||
+ | To submit this project using the **submit** tool, run the following command at your lab46 prompt: | ||
+ | |||
+ | <cli> | ||
+ | lab46: | ||
+ | Submitting DESIG project " | ||
+ | -> GAMENAME.tic(OK) | ||
+ | |||
+ | SUCCESSFULLY SUBMITTED | ||
+ | </ | ||
+ | |||
+ | NOTE: " | ||
+ | |||
I'll be looking for the following: | I'll be looking for the following: | ||