Mini Project Blog (S)

I wanted to create a snake game program using python/pygame because I grew up playing snake on my Nokia phone and I wanted to not only test my ability in coding python but also refreshing myself with pygame since I had not created a program with it in a long time. Some of my friends were also quite interested if I would be able to create the game and to try playing it when I was finished. My program would be designed almost identical to the generic snake games you can find online. It would consist of the player controlled snake, the map of which it roams about, the food that is spawned in and the score counter. The basis of the game is that the player would use their arrow keys to change the direction of the snake where their goal would be to collect the highest amount of food which in turn would increase their score count as well as making the snake longer and move faster so that it’s more difficult to control. If for any reason the head of the snake touches any portion of its own body, the game will then reset.

 

Basic plan of code:

import pygame

import sys

import time

import random

screen_width, screen_height = 320, 240

pygame.time.clock()

class Snake(object):

def lose(self):

def move(self):

class Apple(object):

def randomize(self):

def check_eat(snake,apple)

Code link: https://docs.google.com/document/d/1bmr6Xvq5_cWLmHK-M5UYHPH8IzcYDIit3zkZZ2qb9JE/edit

Overall I think I was pretty successful in completing the goals that I set out at the beginning of the project. I was able to create a functional snake game that I can play with my friends from scratch using my skills in python. Some problems that I ran into throughout this project was during the coding portion of the project because I wasn’t super familiar with pycharm so I had to read a lot of documents and articles of how to use the commands.

 

Creating Apps Reflection 3 (F)

In lessons 7-9 we went over how to use if, elif and else statements. We also learned how to make dropdown menus and apply it in our code. Lastly, we implemented AND, OR, NOT operators into if statements to make it more complicated. The final exercise was to determine whether a section of code fulfilled one of the AP criteria shown on the screen. I determined it did fulfill the criteria since it utilized a mathematical concept in the form of ==.

APCSP (S) – Sorting and Searching Methods

 

Selection Sort (Daniel)

 

Binary search (Bahram)

 

The algorithm maintains two subarrays in a given array.

1) The subarray which is already sorted.

2) Remaining subarray which is unsorted.

 

The selection sort algorithm sorts an array by repeatedly finding the minimum element (considering ascending order) from the unsorted part and putting it at the beginning.

 

In every iteration of selection sort, the minimum element (considering ascending order) from the unsorted subarray is picked and moved to the sorted subarray.

 

Inefficient with large lists

 

arr[] = 64 25 12 22 11

// Find the minimum element in arr[0…4]
// and place it at beginning
11 25 12 22 64

// Find the minimum element in arr[1…4]
// and place it at beginning of arr[1…4]
11 12 25 22 64

// Find the minimum element in arr[2…4]
// and place it at beginning of arr[2…4]
11 12 22 25 64

// Find the minimum element in arr[3…4]
// and place it at beginning of arr[3…4]
11 12 22 25 64

 

Worst-case performance О(n^2) comparisons, О(n) swaps

Best-case performance О(n^2) comparisons, О(n) swaps

Average performance О(n^2) comparisons, О(n) swaps

Inefficient with large lists

Has performance advantages over more complicated algorithms in certain situations, particularly where auxiliary memory (secondary storage) is limited.

 

I collaborated with my partner along with other people in the HKIS community by asking them if they know of any algorithms and if they had known what Binary search or selection sort was. If they didn’t know what they were I used my knowledge that I obtained throughout the project to explain to them what they are and what they do.

 

Website URLs:

https://www.geeksforgeeks.org/selection-sort/

 

https://en.wikipedia.org/wiki/Selection_sort

 

https://www.tutorialspoint.com/data_structures_algorithms/selection_sort_algorithm.htm

 

https://www.hackerearth.com/zh/practice/algorithms/sorting/selection-sort/tutorial/

 

Citations:

 

“Selection Sort Tutorials & Notes | Algorithms.” HackerEarth Blog,

www.hackerearth.com/zh/practice/algorithms/sorting/selection-sort/tutorial/.

 

“Selection Sort.” GeeksforGeeks, 10 Jan. 2019, www.geeksforgeeks.org/selection-sort/.

 

“Selection Sort.” Wikipedia, Wikimedia Foundation, 8 Jan. 2019, en.wikipedia.org/wiki/Selection_sort.

 

tutorialspoint.com. “Data Structures and Algorithms Selection Sort.” Www.tutorialspoint.com, Tutorials Point, www.tutorialspoint.com/data_structures_algorithms/selection_sort_algorithm.htm.

 

APCSP (S) – Create a card trick algorithm

Research three different card tricks:

 

https://www.youtube.com/watch?v=GUDrxGbtSkw

 

https://www.thesprucecrafts.com/best-card-trick-2267052

 

https://www.youtube.com/watch?v=A9Vu9n7YxrI

 

I stuck with the first one because I understood how to explain the trick using a math algorithm

 

Procedure/Instructions:

 

  1. Obtain a pack of playing cards
  2. Take out the two jokers
  3. Shuffle a pack of playing cards
  4. Choose 21 cards randomly out of the deck
  5. Discard the rest of the cards
  6. Deal out the top card into pile one
  7. Deal the next card into pile two
  8. Deal the next card into pile three
  9. Repeat steps 5-7 seven times
  10. Tell the user to choose one card in any one of the piles
  11. Tell the user to indicate which pile their chosen card is in
  12. Take one of the piles that the user didn’t choose and place the pile that they did choose on top
  13. Place the remaining pile of cards on top
  14. Repeat steps 5-12 two more times
  15. The 11th card will be their card

 

Math algorithm:

 

1 ≤ v ≤ 7            v is the card position in one of the three piles

 

x=(v+7)/3      x is the card position in one of the three piles before the second deal

y=7+(x/3)  y is the card position in one of the three piles before the third deal

 

7+y=7+(7+((x+7)/3)/3) Final position of the card in the 21 card pile

 

z=7+y           z is the final position of the card within the 21 cards (the chosen card is                           always the 11th card in the final pile)

 

 

I felt like this activity was pretty fun because we could find the algorithm behind a real-world problem and create a set of instructions that anyone could follow to repeat the trick. Coming up with the actual math behind the problem also helps the user to actually understand what’s going on rather than just blindly following a set of instructions which I think makes it even more fun. After completing this activity, I have not only learned a new card trick that I can “wow” my friends with but I also now know how it uses algorithms to function.

 

APCSP (S) Secret Rules of Modern Living: Algorithms

  • Algorithms are everywhere and affect our lives
  • Secret to our digital world
  • Can’t live without algorithms
  • Face detection algorithm in phones for focusing on faces
  • Scans the image for four different distinct facial attributes
  • Algorithms aren’t exclusive to technology
  • Chocolate and Chili algorithm
  • Taps into the mathematical structure behind the problem
  • They are extremely old
  • First Algorithm was Euclidean’s algorithm to find the greatest common factor between two numbers
  • Simple algorithm using squares of the smallest side of a rectangle made up of the two numbers to find the GCF
  • Larry Page and Sergey Brin created Google the search algorithm
  • PageRank was a ranking algorithm that ranks pages based on relevancy
  • PageRank looks at incoming pages and pages that are related to those pages to see how relevant they are
  • Higher ranked if the page is linked to other pages
  • Weights pages that have a higher rank as a better resource for the importance
  • Creating them is so difficult but using them is really easy since its just following instructions
  • Computers are really good at it because its just doing repetitive tasks by following the instructions
  • Information is divided up into packets
  • Sorting algorithms put packets back into order so that users can view messages that are sent and received
  • Bubble Sort Algorithm swaps pairs depending on which one is larger
  • Does this until there are no pairs to switch around
  • Very simple and straightforward but quite inefficient
  • John von Neumann created many things
  • Merge Sort Algorithm splits everything into smaller groups
  • Merges groups until those are sorted and then repeats it
  • Much faster for larger objects compared to Bubble Sort
  • Matching algorithms for online dating
  • Stable Marriage problem
  • Ranks choices so that everyone gets their best choice available but not necessarily their first choice
  • Algorithms save lives through finding organ donors
  • Algorithms have limits
  • For example, checkers where there are millions of combinations
  • Traveling Salesman Problem
  • Finding the shortest path between cities once and then traveling back to the origin
  • Heathrow Sequencing Algorithm
  • Used for airplane flight paths
  • Runs a lot of simulations to find a more optimal order
  • Kinect Skeleton Tracking Algorithm
  • Tracks distance between sensor and person to accurately track the player’s body posture
  • Uses machine learning to distinguish different body parts and positions
  • Can’t understand what exactly is going on
  • Can be used to map out tumors in patients brains (previously only a skill that could be done by doctors)
  • Continues to adapt and change
  • Automated grocery warehouse
  • Anticipates customer demands

Unit 4 Lesson 1 – Algorithms and Pseudocode

Today we came up with a set of commands to direct someone around HKIS.

Forward(n)

Turn(n)

Stairs(n)

Stop

We were pretty successful as we all took turns controlling and being controlled without any major issues. A few obstacles we ran into were the varied size of steps and turns which made it hard to make accurate movements.

RISC: Reduced instruction set computer

Instead of StairsUp(n) and StairsDown(n) we changed it to Stairs(n).

Projects over quizzes

Despite being somewhat helpful, I believe that the two quizzes completed throughout the first semester of APCSP do not clearly reflect my progress. Over the course of this class, I have been able to demonstrate my learning and understandings of the different concepts and skills, taught throughout the class in the form of projects. Since we could work on our projects as much as we wanted as time permitted, I was able to put in my maximum effort to demonstrate all that I had learned without a very narrow time constraint. My effort and understanding of the units are then reflected in my high grades that I had received. I also believe that projects are better at demonstrating your learning since it is dynamic, compared to the linear multiple choice questions. Projects help you clearly express your ideas through different forms of mediums, which means that there are a lot more free choice and creative thinking involved which is also an important skill for coding. In conclusion, I strongly believe that projects should be taken with more consideration since it is a much clearer way to display our understanding.

December 10th

Today I completely finished my artifact by making a couple last minute touches; I added a more colorful background, shifted the placements of the images and words and added a couple arrows to show the payment flow. I then continued to work on the reflection portion of the Explore task.