Entry #3: Procedural Generation

Hello and welcome back to another installment of Coding the Matrix! Today we’re going to be talking about procedural generation in video games! As the name implies, procedural generation in video games involves generating content dynamically from an algorithm as opposed to having all the content created beforehand. Early in gaming’s history this was how everything was created due to the small amount of memory you had on those old game cartridges. These days though, we have enough space on discs, and hard drives to be able to have a significant amount of unique content made beforehand. Even so, most games these days mix in procedural generation regardless whether it would be for placement of their game assets or A.I. decisions.


A very well-known example of this sort of content generation occurs in the game Minecraft. Much like a random number generator, Minecraft’s worlds are generated based upon an initial seed given to the game. This makes every play through a different experience due to everything being different if you change a seed. This is partially why Minecraft has had such a huge success in the game world, no two people have the exact same experience. This same procedurally generated content system exists within other larger games such as The Elder Scrolls V: Skyrim, and Far Cry 3. These two games are free roaming, and allow the player to follow their own path through the world put in front of them. Both of these games use procedural generation to throw encounters at you while you make your way through the world. Specifically in Far Cry 3, the game was designed to throw a few enemies and encounters if you went directly from objective to objective.


A really basic implementation of this is to have in your code a random number generator that generates a number from 1-10. If it hits a certain number a certain event happens. Say you have a list of ten different animals all represented with the numbers 1 – 10. Based on the number you get, you could have your algorithm pick one of the ten animals out of the list. If you stack this with more random number generators and create what effectively becomes a flowchart, you could have something as complex as Minecraft. That is, you have a number you input initially that feeds into a random number generator that feeds into more of these random number generators that set off other algorithms to generate the entirety of what you’re attempting to procedurally generate.

Well, that’s all in this week’s entry of Coding in the Matrix! Stay tuned for next week


Entry #2: A Crash Course on Coding Concepts

Welcome back to Coding the Matrix! As you may have notice I lied about what I was writing about this week! While I will eventually get to explaining how to implement game loops, I feel like I needed to dedicate at least one week into giving everyone here a crash course in some coding concepts, lest you become confused and not read pass the first piece of technical jargon you run into on my here blog.


So brace for impact, I’m about to run you guys through roughly an entire introductory class of coding.


Before I get into the specifics, code is run from top to bottom, written in a text editor, and is all about variables and what actions you perform on them. First off, every line will be executed by your computer from the top, to the bottom for the most part. Although there are cases where this statement isn’t true, but we’ll leave it at that for this crash course. Next, all code is written in some kind of text editor, it’s just a deterministic way of representing things so that your computer can understand you, because our computers don’t see shades of grey. Lastly, almost all coding is, is that you have variables which you declare, that are of some specific type, and then you perform actions on them.


Variables in coding are exactly like they are in math, you can change them at any point in the code, and you can start off by declaring what they represent, or not. They each have some type that they’re bound by, examples being “int,” “double,” and “char.” These are called data types, and are commonly found in all languages. “int” stands for integer, which is self-explanatory, double is a double of a float, another data type which allows for you to store numbers with decimals, and “char” is character, which in reality is also an integer, but it stores a character as you’d expect.


There are a vast amount of things you can do to and with variables, and I will be only going over, operators, functions, loops, if statements.


Operators, as the name implies, are things that operate on variables. These include the basic arithmetic operators, but there are also things like increment which add one to the variable in question. There are also logic operators like “and,” “or,” “less than,” “greater than,” “equals to” and “not.” These mostly compare variables, or inverse them.


Functions, are exactly like what they were in math class, except they can return and take in data other than numbers, as well as not take any data at all. There are built-in functions and ones you can write yourselves, and they the most frequently used coding concept.


Loops are exactly what you think they are; Loops loop code. The basic ones are the for loop, and the while loop. The for loop has a variable that keeps track of a number, a condition for when the loop stops, and an operation it perform on the loop every loop. So, a for loop only loops as much as you want it to, and you have a lot of control on how many loops you want. A while loop on the other hand simply has a condition that has to be meet for it to loop, and can loop for as long as that condition is met.


There ends a crash course on coding concepts, stay tune for next week on Coding the Matrix! Hopefully I won’t have to blow your minds again!


Entry #1: Game Loops, Part 1

Hello! Welcome to my class-sponsored blog about the applications of computer science in game development! My name is Alex Ling, I’m currently a freshman at the California Polytechnic State University – San Luis Obispo (Cal Poly SLO) and every week, as per our 10-week plan, I will be discussing various concepts in game development and how they’re implemented through computer science.

To start off this blog, I will be discussing the ever present game loop. To explain this concept thoroughly, I will be using Chess as an example. As you know, Chess is a board game that involves two sides moving pieces around a board in an attempt to corner the opponent’s board. Every turn you’re allowed to move one piece your control, performing a number of actions that that piece allows. You and your opponent go back and forth until someone finally corners the other’s King and declares checkmate.

Now you can think of your opponent’s turn, and your turn as a loop. This loop ends when someone has managed to checkmate the other player. This is essentially what a game loop is. It’s the main piece of code that runs through the game’s main steps over and over, such as the turns in Chess. Although the game loop serves another purpose in video games as well; It constantly checks for user input and updates the game state. Even in a turn based game such as Chess, you need to have your video game constantly check your input device (keyboard, mouse, controller, etc) to see if your player is hitting any buttons. You also need it to draw the graphics on the screen, play sounds and perform other actions. How this is represented in code though I will be explaining in next week’s installment of Coding the Matrix. Look forward to it!