Thursday, February 16, 2017

Game Development: Algorithms

Recently, I was reading a book, called Algorithmic Problem Solving, by Roland Backhouse, and it was rather interesting. Unfortunately, however, I didn't get to finish the book, but I did manage to get a good read of the first chapter, algorithms.

So what is an algorithm?

What is an algorithm? Well, the definition algorithm means "a well-defined procedure, consisting of a number of instructions that are executed in turn" (Roland Backhouse, 2011). Essentially, what this means is that its a set of instructions for a computer, which has to be really precise when being written. People nowadays think that computers are really smart. Sure, they seem to be smart, but in actual fact, they are rather "dumb" (Backhouse, 2011). They are smart in terms of the complex instructions they can execute, but they are also dumb because the algorithm that is sent to the computer must be precise and very detailed, as to what you want the computer to execute. Like what my programming lecturer said, during my first day at SAE, he said:
"Imagine that there is this person inside the computer. He has access to everything the computer has, but he is very stupid. Whenever you code or program something, make sure to be very precise and very detailed in what you want to do. This means you have to be careful with your spelling, case sensitive words and more". I will include an example in C#:

1) using System;
Console.WriteLine("Hello World");
-----
2) Console.WriteLine("Hello World");

In example number 1, it shows "using System;". What this means is that you're telling the computer to (in the words of my lecturer) retrieve a book which has ALL the definitions, keywords and functions that the computer has stored in its memory, such as the keywords Console.ReadLine, Console.ReadKey and more. What this means is that, without the line "using System;", the program wouldn't be able to understand what "Console.WriteLine" is, which leads onto the second example. If we were to run the 2, example 1 would print "Hello World" onto the screen, and example 2 will not print out anything, but will give an error., saying that "Console.WriteLine" is not defined.

Algorithms have an input-output relationship (Backhouse, 2011), meaning that algorithms will normally require an input, and with this, the computer should compute an output, such as the example in the book:
"Four people wish to cross a bridge. It is dark, and it is necessary to use a torch when crossing the bridge, but they have only one torch between them. The bridge is narrow, and only two people can be on it at any one time. The four people take different amounts of time to cross the bridge; when two cross together the proceed at the speed of the slowest. The first person takes 1 minute to cross, the second takes 2 minutes, the third 5 minutes and the fourth 10 minutes. The torch must be ferried back and fourth across the bridge, so that it is always carried when the bridge is crossed. 

Show that all four can cross the bridge within 17 minutes. 

A typical instruction for this problem would be: "person x and y cross the bridge" or "person z crosses the bridge". The sequence of instructions solves the problem if the total time taken to execute the instructions is (at most) 17 minutes." 











References:
Backhouse, R. (2011). 1. Introduction 1.1 Algorithms. In Algorithmic Problem Solving (pp. 3-6). John Wiley & Sons.
Hartnett, K. (2016, May 27). What people can learn from algorithms — and algorithms can learn from people [Digital image]. Retrieved February 16, 2017, from https://www.bostonglobe.com/ideas/2016/05/27/what-people-can-learn-from-algorithms-and-algorithms-can-learn-from-people/R7XJ1TgLnyZCOnmzBryh5H/story.html













No comments:

Post a Comment