D2X-XL Worklog
Notes on features and problems from the development of D2X-XL, newest first.
Applying For A Job In The Gaming Industry |
|
The Task
Recently I did something rather different than usual. Ok, not that different - I was still coding - but I had applied for a job as senior programmer in a computer game company, and had been given the task to create a small prototypic game simulation including a debug visualization; all that within 8 hours. The simulation should take place on a rectangular grid containing some obstacles, some predators and their prey. Predators should start to hunt prey when they heard or saw it and eat it once they reached it, while prey should try to hide from predators they noticed that hadn't seen them or run away from them if they were hunting. So far so good. The Way Since I had been told that 8 hours was rather scarce for the task I was confident that I wouldn't do too bad, and after having read the task description and thought about how to structure my code into classes and methods started to happily type away. The hours went by way too fast, and the further time advanced the more I became aware that the ambition and goal I had set myself for how I wanted the code and application to look had probably been aimed a bit too high, and it was clear to me that I wouldn't be able to even start with a visual interface. So I concentrated on the core simulation. I still wasn't able to finish it. Bleh. Interestingly enough I was told that my solution looked like I had dived into coding head first, while I know that the very opposite was true and I have had a clear concept what entities (classes) to use, how to have them interact, what functionality to provide, and what to prioritize. I just didn't even have the time to test anything. The Result In the end took me well over a 40 hours to create something I liked, and my only comfort is that I believe that the simulation is quite well written,
uses and shows good structure and programming as well as some extra thought, beefed up with the application of advanced techniques in the
realm of path finding and flavored with a real nice interactive interface wrapped around it. Actually I think that my solution is totally exaggerated
for the task, but I so much love to create nice, good looking, well working things with that extra 'Oomph'. Anyway, 40 hours is enough, and if you would like to
you can download the application and its source code here and play around a bit with it yourself.
You will need 7zip v9 (beta) to unpack it and Visual Studio 2008 to compile the source code (C++ and C#/.NET 3.5). Executables are provided, so
you won't need an IDE unless you want to poke around in the code. Here's a screenshot to bring a bit color into this mass of text:
You can see the hearing and view range of the selected object (prey), the tiles it can see and hear, the path it is trying to follow, and predator it is hiding from.
The lines between red and blue objects show which predators hunt what prey. Program settings are stored in an XML file (handling XML with C#
is a breeze). Actually my little program offers much more functionality than what had been asked for and presents it in a very accessible and
concise way, making it easy to follow certain objects or track them down and examine them in a debugger, and it's those little extras that can
make a big difference. The Question The big question for me is whether I had just aimed to high and put too many C++ features and thought about AI behavior into my solution, or whether I should have been faster even given the approach I had chosen. I hope it was just a matter of my strategy since I can easily adjust that should I ever have to in the future. I would love to see and examine a solution for this task that had been finished, or close to being finished, after 8 hours, and compare it to what I have done - just to know whether I can relax, or whether I should be seriously concerned about my coding skills. Thinking back I have to say though that trying to fill in the gaps in the task description regarding the AI somewhat broke my back. It took me too long to think and try my way through different variants of predator and prey behavior and make a clear cut there. The behavior specification for prey e.g. seems to be contradictive when it says this:
First of all when the predator starts to hunt the prey, the prey doesn't necessarily have a movement tick right away, so you need
to delay processing of that information and properly sort it out when it is the prey's turn. This means a complication to the regular
prey turn processing. Now what if the prey detects some closer predator that is hunting some other prey? The specification
says the prey should start to run. This will override running away from the predator that hunts the prey, which doesn't quite seem to make sense.
And what if the predator starts to hunt some prey when that prey cannot see or hear it anymore because it has moved behind some cover?
The specification says the prey should still run, but does it make sense here?
The next question is what happens when several predators start to hunt the same prey. Which will precede? The last one? Simple to code, but a bad solution. The closest one?
Better, but more effort to code. It is easy to burn time here because the specification is unclear, tempting you to try and correct it,
and depending on the number and complexity of potential solutions for such a conflict you can find yourself in hot water there very quickly. The Conclusion
Looking at the outcome of the test, I should have created something as simple and close to the specification as possible and blame the specification for
the flaws (at the danger of people saying "Yes, it works, but geez, that stuff looks like it was built by a student and not by an IT pro who knows how
to create object oriented code!"). Chosing between delivering something that is built to the specs but doesn't really work,
and something that makes sense can be a tough choice. My way out of this quandary was to try and build something that in
my eyes could stand the test of object orientation and technological sophistication ... but obviously I had chosen the wrong path. Another thought I am having about this task is that while you can throw a brief task description at people and have them start to code after a short while of reading and understanding it, there is no way to create a big and complex application that way. Sure, you will break it into small, manageable pieces, but yet it's an entirely different story. You really will need to take your time to create well designed classes and application structure. So at the end of the day I am asking myself what my test result really says about my capability to efficiently participate in creating a 'real' program. It probably says a lot more about my priorities and my diligence when creating any application. Well, I had been asking for it, and there I got it. |





A better way to specify this would probably have been to say that the prey should run away from the closest predator that is hunting it,
and only deal with other predators if it doesn't get hunted.