TIL: Learn to Code in C++ by Developing Your First Game (Section 2, Part 6)

40 more videos to go! Mind you the course is still in progress, so there’s a real possibility that there will be more to watch by the time these are done. I must say, I really like Ben Tristem’s teaching style. I feel like I want to make some Houdini tutorials at some point (I’ve had this in my head for over a year now… but it’s rather difficult to make happen now that I live in a tiny apartment with a small child…) and I can think of ways that Ben’s teaching style will influence mine. But enough on that, it’s time for me to do some more learnin’.

Section: 2 – Bulls & Cows Word Game – Your First C++

Lecture 40: Win or Lose “Screen”

It’s not satisfying to simply wrap up a game without giving the player a pat on the back. It’s a good idea to have a win-state of some sort.

The mission in this lesson was to Define a PrintGameSummary() method which either congratulates or consoles the player depending on whether they were victorious. This is a pretty simple task as we simply need to create a new void PrintGameSummary() and then define it. It consists of an if statement to check whether we’ve one, and then std::out an appropriate message.

Lecture 41: Introducing Big O Notation

A beginner’s guide to Big O notation

While the number of isograms in the English language are limited…. we want to ensure that our code is optimized. O Notation is a way of figuring out optimization of algorithms. In our case, we will end up using tables to store our letters so we can quickly exit as soon as we get a duplicate.

Lecture 42: TMap and std::map Data Structures

First of all, there are many data structures available to us in UE. This blog post helps describe them:UE4 LIBRARIES YOU SHOULD KNOW ABOUT. In addition, you can get more info about std::map here. We’ll start using the map, and later sort out how to convert it for UE.

first we need to enter: #include <map>, and then we need to #define TMap std::map. See: #define.

Lecture 43: Range-based for Loop

While we’ve created brute forced for loops already, a better way to do it is with a range-based for loop so that we don’t need to know how many items we’ll be processing. You can read more on this type of loop via the Unreal website: http://www.unrealengine.com/blog/ranged-based-for-loops.

std::unordered_set or Unreal’s TSet are both valid alternatives to the TMap. Map is more versatile.

When it comes to the range-based loop, we can use for (char Letter : Word). It’s the : that is essential here as it says essentially “all letters ‘in’ the Word”.

The loop ends up looking like:
rangedfor

Lecture 44: Design a Helper Function

We need to get a test that works for lower case letters only.

One thing to take note of, is our nested if statement… it’s best when possible, to avoid Implicit Dependencies. It’s better to not make assumptions about what order the if statements need to be in. This way we can remove a statement if necessary, and not worry about the code inside. Try to keep statements independent of one another when possible.