This is a straight port of the GDX Java code to C++ with as few changes made as possible. Part 1: AI code.