Tuesday, August 30, 2011

What The FizzBuzz?

So, I know that there are numerous blogs discussing the "FizzBuzz test" that is given to interviewees as a "weed-out" measure to eliminate bad programmers.  As an exercise in simplicity and timing, I have done a timed trial of implementing the program using Java as the programming language.  The environment used was Eclipse 3.7, which drastically reduces the time needed to complete the exercise as typing is much faster than writing code by hand.

Here is a sample of my code for the simple version:



This took me a total of 3 minutes and 50 seconds after opening Eclipse, but only 2 minutes and 48 seconds from the moment I started typing in the editor to the moment that I saved, compiled, and ran the program.  Now, to be honest this was my third time writing this particular program.  I have previously written it by hand, which took me over 4 minutes to write after first seeing the problem.  I was happy to say that my very first attempt at this problem was actually correct, albeit the algorithm was not quite so simple and had the redundancy of checking modulo 15 twice.  It was the first time I was actually timed when writing code and the experience was flustering to say the least.

After being exposed to a potential solution after my initial test, I decided to implement it at home so that I could play around with the JUnit testing aspect.  This exercise was not timed.  Below is the code I used for that brief exercise:



Also, here is the code for the test-file:



I chose not to fully document everything as it was a personal exercise out of curiosity.  I simply wanted to get my hands dirty experimenting with some JUnit tests.

So, why did I start out with a "time-trial" of such a simple program, when I have already become familiar with it?  Part of the reason is that I want to gain practice producing code "under pressure".  Another reason is to see how well my time had improved after becoming familiar with the problem, as well as the Eclipse Integrated Development Environment.  The fact that it was being timed also resulted in the simplistic code, not having any comments, and the absence of a method implementation approach for ease of testing.  Overall, this was a very simple exercise and I did not run into any obstacles with Java or Eclipse.  It was encouraging to see that my time had improved a little, which is to be expected after repetition.

Furthermore, I am well aware of the fact that all interviews are different and that practicing potential and otherwise trivial problems proves nothing of my capabilities as a software engineer.  I simply think that it is a good idea to practice in different areas.  As such, writing code against a clock is a good way to begin to think in terms of potential "crunch-time" scenarios were a solution needs to be generated as quickly as possible to solve a serious problem.  It is always ideal when given a problem to generate an elegant, well thought out, and creative solution.  Wisdom would dictate that not all scenarios are ideal and so it is a good idea to be prepared for situations which are not ideal.

Monday, August 29, 2011

The Prime Directives Applied to BZFlag

BZFlag is an open source game that is designed for entertainment purposes, which utilizes several programming languages to create a three-dimensional tank simulation game.  The source code is written primarily in C++, but it also incorporates modules that are written in PHP, Perl, and Python.  The homepage for the project can be found at: http://bzflag.org/  Alternatively, you can access the project via sourceforge.net at: http://sourceforge.net/projects/bzflag/

The name BZFlag is derived from "Battle Zone capture the Flag", although the game engine now supports other scenarios via server settings such as Free For All and Rabbit Hunt.  According to their homepage, BZFlag boasts that it is "...one of the most popular open source games ever."  Whether or not this is truly the case, the game works on several different platforms including Mac OS, Windows, Linux, and many other platforms.  Intended as a cross-platform multiplayer game, being available on so many different platforms is a tremendous feat.  This is especially true, considering all of the differences in various operating systems.

Since this is an open source project, what standards can we apply to measure its success and usefulness?  The Three Prime Directives of Open Source Software provide us with useful means of comparative analysis.  So then, how does BZFlag meet each of the Prime Directives?


1. The system successfully accomplishes a useful task.

Okay, some may argue that games by their very nature do not accomplish ANY useful tasks.  In relation to productivity, no they do not succeed in this endeavor.  However, in the context of creative expression, entertainment, and leisure, games do indeed serve a purpose.  As such, BZFlag accomplishes these tasks quite well.  It offers variable gameplay modes with the option of single player or multiplayer environments.  I was able customize server settings, create my own server, and join existing games on servers created by other people.  It is by no means competitive compared to top-tier mainstream video games, but it is quite impressive for a game that is available cross-platform and with no cost.  I certainly appreciated the customization available for server settings, and I tried out a variety of scenarios.

2. An external user can successfully install and use the system.

BZFlag is exceptionally easy to install on Mac OS.  All I have to do is download the zip file from their website, or via sourceforge.net.  Once I open the zip file, I simply move the application file into my application folder and I am finished.  Of course, the game will work from any directory on Mac OS; having the program file in the applications folder just makes it easy to find.  Once it is installed, I simply double click the application icon and the game starts up.  The menus are easy to navigate, and within moments I can have a server up and start blasting away at other tanks.  The controls are relatively basic and intuitive, and the user interface is simple yet informative.

3. An external developer can successfully understand and enhance the system.

While it does take a bit of navigation through the project structure, the project is relatively well organized.  There are files for the game client, for the server, and for server administrator tools.  The C++ code is not consistently commented, although with enough exploration and examination it makes sense.  I have to admit that I did not have any prior experience with program structure for a game with a Graphical User Interface.  As such, some of the code is currently beyond my expertise or understanding.  This project is definitely not for the feint of heart, or those with no prior C++ experience.  I have a little understanding of the code, which is enough to modify the game here and there.  In fact one of the things I would like to attempt is to modify the movement controls to allow for strafing and eventually a toggle for y-axis movement.

All in all, if you are familiar with 3D game client structure and such, it would be relatively easy to understand and enhance BZFlag.  There is a wiki-page with information about the project, forums for use and development, and plenty of developer-level documentation available online.  Also included in the source code directories are plenty of the documentation files which are available on the website.

Here are some screen shots from the program:
Start Menu




 

 

 

Just Cruisin

 

 

 

 

 


Firing a Shot