Kami 2 Solver

I love the game Kami on my iPhone, by State Of Play games. When they brought out the sequel, Kami 2, I was very excited! But it proved to be a lot harder than the original, and before no time I was stuck and had run out of hints. So I wondered if it was possible to solve this puzzle with a program. I’d written myself a solver for Soduku in C# using the algorithms I used in my head to solve the problems. I figured I could do something similar with Kami. The first solver I found was by…
Read more →

Unity – Constructors with Parameters

Microsoft Unity is a great library to use for a dependency injection container. It has support for constructor, property, and method call injection. Typically you’ll use constructor injection. I wanted to use it for a class whose constructor took parameters. Here’s an example I’ve created to show what I wanted to do: First I have an interface for logging – ILogger:

Then I have an actual class that implements this interface – FileLogger:

In my program I create the Unity container. I then want to register my FileLogger class as an implementation of the ILogger interface. This part…
Read more →

Kinect Point Cloud Normals Rendering – Part 4

In this post I’ll create a WPF front-end to the C++ template code I’ve been using so far. I’ll use a CLR wrapper to achieve this. The first step is to create a WPF project. I like to use MVVM Light Toolkit for my WPF projects. I’ve installed the Visual Studio plugin so it comes up as on option when I’m creating a new project. I started by created a project called DepthViewer2D: Once I created this project I added a new project to the solution called DepthImageRenderer. This is a C++/CLR class library project. You’ll find it under “Other…
Read more →

Polymorphism and Abstract in C#

Let’s say you want to define a base class that other classes will inherit from:

We want to make sure that everything that inherits from this class will implement its own version of the CreateBrushes() method. If this method isn’t implemented then we will get a runtime exception every time our inherited class is instantiated. This is one way of ensuring that inherited classes provide an implementation of a method. However, we only find out the problem at runtime. A better solution would be to get an error at compile time. This is where the abstract keyword comes in….
Read more →

Polymorphism in C++ and C#

I went for an interview for a C++ job one time and they showed me the following code and asked me what the output would be:

Really this is a question about inheritance and polymorphism in C++. The class description is the base class and the classes sphere and cube inherit from it. Because the description has declared it’s method print() as virtual a vtable is created under the hood for that class and method. Any class that derives from description is allowed to override it’s definition of print() and use its own. The definition of the print() method…
Read more →