My first big C++ attempt and also part of my MSc dissertation.