< Browse > Home /

Binary Search in C++

December 28th, 2008 | 1 Comment | Posted in Algorithms by Diego | - [Full Entry]

Binary Search is a method to search through a sorted container in order to find a particular value.

Remember that one “Guess the Number” game? Let’s look at the following scenario by applying the Binary Search algorithm in order for you to understand how Binary Search works.

The Guessing Game

Pick a number from 0 – 100 and depending on your guess, I’ll either say Correct, Higher, or Lower. What would you choose?

0 1 49 50 51 99 100

Well, 50 of course! Why? Best case you get it correct. Worst case you’ll either get a “Higher” or “Lower”. Now think about the following, if you got “Higher” you eliminated 0-49, or 51-100 if “Lower”, in other words, you eliminate HALF the possibilities.

50 51 74 75 76 99 100

Well, let’s say it was “Higher”. What would you guess after? 75. Since it’s in between 50 – 100. If you didn’t guess correctly, you’ll be facing the similar scenario as before. You’ll end up eliminating half the possibilities!

Read more »

Game Source Available

August 14th, 2008 | No Comments | Posted in Game Development, OpenGL, Programming by Diego | - [Full Entry]

Just wanted to keep everyone up to date and let you all know that the source code for the Piranha Plant, Wario, and Coin Game has been posted to the forums.

Go ahead and give it a try, it will be a great experience to see what was put into making that simple game. Make a modification, or change it completely… you are free to do what you like with it.

Just as a reminder, Diego’s Pong Game will soon have another release along with source code. So stay tuned so you can take a look at the work that it takes to make a simple pong game. I know I’m waiting for it!

Here is the link to the source:
Piranha Plant, Wario, and Coin Game Source

Here is how to set up your environment
Setting up your environment is relatively easy with the following tutorial.
Codeblocks with SDL support

Enjoy!

Classic Pong

August 7th, 2008 | 1 Comment | Posted in Game Development by Diego | - [Full Entry]

I’m releasing a preview of my Pong game. This is simply the first release, the second release should be the final. So far it took me about an hour to create. Not bad eh? You too will soon be able to make games like these so stick around so you can also be proficient in Talking Binary!

For now the velocity of the ball is constant. I plan on changing that on my second release so its possible to beat the computer.

This was created using CodeBlocks and an OpenGL/SDL package from a friend of mine. So, soon once I believe the code is user friendly, I’ll release it so anyone can learn and create your own game! Don’t worry, it isn’t difficult. You use C++ and OpenGL/SDL handle all the graphics for you.

Download and comment on the game here.

Controls: You move up and down with W and S.