Tuesday, August 31, 2010

04.FizzBuzz

The whole premise of the FizzBuzz problem is very interesting.  After reading:
one can understand the significance of the problem. If indeed there are many programmers out there who aren't capable of producing this simple code on the spot, there is a just concern. The details of the FizzBuzz exercise are as follows:
  • The FizzBuzz program should print out all of the numbers from 1 to 100, one per line
  • If the number is multiple of both 3 and 5,  print "FizzBuzz".
  • Else if the number is a multiple of 3,  print "Fizz".
  • Else if a multiple of 5, you print "Buzz" .
The FizzBuzz problem is fairly trivial as long as one understands exactly what is being asked. However, if you are under pressure to solve this problem,  the order of the constraints can throw you off. When I originally devised the solution, I wrote each line of code corresponding to the order of how it was explained:

The FizzBuzz program should print out all of the numbers from 1 to 100, one per line, except that when the number is a multiple of 3, you print "Fizz", when a multiple of 5, you print "Buzz", and when a multiple of both 3 and 5, you print "FizzBuzz". 

Although I got it working, It was messy and I had arrows describing where chunks of code should be moved. 

Since I developed a working solution during my ICS413 Software Engineering class, the exercise of implementing FizzBuzz with Eclipse was easy. The exercise took roughly ~5 minutes for me to implement the code and run the program. I had no problems creating a new project in Eclipse nor with receiving any erroneous output. My code snippet is as follows:

package com.kteichma.FizzBuzz;
Public class FizzBuzz {

  
/**
    * @param args
    */
  
Public Static void main(String[] args) {
       FizzBuzz fizzbuzz
= New FizzBuzz();
      
      
For (int i = 1; i < 101; i++)
          
fizzbuzz.printCorrectOutput(i);
  
}
  
/**
    * @param i
    */
  
Public void printCorrectOutput(int i) {
      
If ( (i%5 == 0) && (i%3 == 0) )
          
System.out.println("FizzBuzz");
      
Else If ( i%3 == 0 )
          
System.out.println("Fizz");
      
Else If ( i%5 == 0 )
          
System.out.println("Buzz");
      
Else
          
System.out.println(i);
  
}
}

It should be noted that in my first implementation of this assignment,  the cases contained in the method printCorrectOutput(int i); were included in the for loop. After being informed about the shortcomings of other programmers mentioned in the required readings provided by Professor Johnson, I have become increasingly interested in becoming capable in problem solving and writing code. I look forward to the upcoming assignments.

02.OSS.Experience

Overview:
http://colossus.sourceforge.net/
Colossus is a Java clone of the boardgame Titan, a turn-based fantasy wargame for 2-6 players. Each player moves stacks of creatures around a strategic board, recruiting more creatures and fighting enemy stacks on tactical maps.

Original Titan game information can be found here: http://en.wikipedia.org/wiki/Titan_(game)

Prime Directive 1:
Did this application/system successfully accomplish a useful task?
I would be inclined to say "yes". I've never played the Titan game, but overall this game looks/feels pretty good. This game accomplished the task of holding my attention for a lengthy duration of time. Frustration drove me to figure out how to win. I will also be gracious enough to say that I would at least play this game one more time after posting the required journal entry in my Engineering blog.

Playing against "Simple AI" proved to be the best way to learn the basics of the game and develop elementary strategy. In a nutshell, the game functions in very similar fashion to another board game which you might have heard of called Risk. In Colossus, however, instead of incorporating the usual Risk strategy of boxing yourself in one has to develop multidimensional attacking stratagems to survive. Movement and coordinated attack are significantly rewarded. I had to search for useful strategies on the internet to save time (it's not fun to lose to "Simple AI"). I managed to find a few useful ideas on the Titan Wikipedia page mentioned above.

Prime Directive 2:
Do I believe an external user could successfully install and use the game?
If the user is able load all the files into Eclipse and "Run Application," then I believe he/she has all the necessary tools to run this game. I did not need to download any 3rd party modules/plugins, everything was self contained. This was not the case for many other open source game projects I tried to load before stumbling upon this one. I went through eight open source games, each of which gave me a headache. As far as I could tell, installation support was nonexistent. I did manage to get one other game running easily. However, all the documentation was in Russian.

It took roughly 30 seconds to get the Colossus application up and running. This was a huge plus for me. I suspect that once I receive additional training in Java, I will not have such a hard time making the red error marks in Eclipse go away.

Prime Directive 3:
Can an external developer successfully understand and enhance the system?
Colossus has great user documentation when it comes to playing the game and understanding the controls. It also has great support for potential developers. The Colossus team maintains a forum on http://sourceforge.net/projects/colossus/forums/ which serves as a conduit for getting information about the source. They also have mailing lists that one can subscribe to (colossus-developers) for discussion of design and coding issues.

http://colossus.sourceforge.net/docs/index.html also provides another source of documentation and support. Developers can reference this link to learn things like:
  • Building Colossus
  • Coding standards
  • Variant-HOWTO
  • File formats
  • Split prediction
  • Network design
  • New savegame / network events
  • Adding a marker set
The Java documents associated with the source code are self explanatory. I feel that even as a complete novice with no UML diagram, I would still be able to pick my way through their code and implement new functionality.