Wednesday, September 28, 2011

Another Neat Tool (Ant) Katas


            Apache Ant or more commonly referred to as Ant, is a Java based build tool that is specifically for users to build their Java project into a system. It uses XML files to describe the project’s build process and its dependencies. Ant was originally developed by James Duncan Davidson as another build system too different from Makefile.
           
            Why call it Ant? One would definitely think of the insect when seeing the name, but it has another meaning than one thinks. According to Apache Ant 101 (a pdf file located at this website: https://www6.software.ibm.com/developerworks/education/j-apant/j-apant-ltr.pdf), the name Ant is actually an acronym from the words another neat tool

            For this build system experience I had to write up the eight code katas:
           
1.      Create a script to print out “Hello World”
2.      Immutable properties in Ant
3.      Ant dependencies
4.      Compile a Java file with Ant script
5.      Execute the program with an Ant script
6.      Use Ant script to create the Javadocs
7.      Create a target in the script from code kata 4 to clean up build directory
8.      Pack everything with Ant script

The first three katas were pretty easy to get through since it was mainly to understand
how things work in Ant. For example, in code kata 2, I had to implement two <property> elements with the same name of my.property and assign a value of 1 and 2. An <property> element in Ant can be thought of as a variable that one can assign a value/path location to the <property>. However, once it is assigned the value it will be immutable; in other words it means it can’t be changed. Therefore, when the script was executed I saw the value of 1 was printed; not the value of 2 because of immutability.

            In code kata 5 I was amazed at how a few simple tags written in the XML file could execute a Java file without the use of an IDE or the use of typing the command to compile the file etc. Another code kata that I was amazed at is the final code kata. In that code kata I had to write a script that utilize the compile, execute, and Javadocs code kata before it cleans up the directory where the class and Javadocs are located. After the cleaning it combines everything and zip it into a zip file. In that file I only had to import the previous XML from code katas 4 to 6 and then a script to zip up the entire package.

            To conclude, Apache Ant gave me the experience of how to package a program into a system so I can share it with other users in the future. I also learned that by building a system it can allow other users with different operating systems and IDEs to be able to execute the program and offer suggestions or comments about the program.

           

           

Monday, September 19, 2011

My Robot Experience

            Robocode is an open source game that was originally developed by IBM. It was meant to be an ongoing project, but IBM lost interest in the project and discontinued the project. The project was picked up by Flemming N. Larsen and Parvel Savara and it is available to download on sourceforge.

            This game involves writing code in Java and having the created robot(s) battle each other by moving around, firing at enemies, or just following the enemy around the battlefield. In order to win this game it is not about using strategies but it is to create a robot from algorithms that allows the robot to predict enemy movements, firing of bullets and other actions.

            For my project or kata (a Japanese martial arts term) I had to program robots to perform the following thirteen actions:

  1. Position01: The minimal robot. Does absolutely nothing at all. 
  2. Position02: Move forward a total of 100 pixels per turn. When you hit a wall, reverse direction.
  3. Position03: Each turn, move forward a total of N pixels per turn, then turn right. N is initialized to 15, and increases by 15 per turn.
  4. Position04: Move to the center of the playing field, spin around in a circle, and stop.
  5. Position05: Move to the upper right corner. Then move to the lower left corner. Then move to the upper left corner. Then move to the lower right corner.
  6. Position06: Move to the center, then move in a circle with a radius of approximately 100 pixels, ending up where you started.
  7. Follow01: Pick one enemy and follow them.
  8. Follow02: Pick one enemy and follow them, but stop if your robot gets within 50 pixels of them.
  9. Follow03: Each turn, Find the closest enemy, and move in the opposite direction by 100 pixels, then stop.
  10. Boom01: Sit still. Rotate gun. When it is pointing at an enemy, fire.
  11. Boom02: Sit still. Pick one enemy. Only fire your gun when it is pointing at the chosen enemy.
  12. Boom03: Sit still. Rotate gun. When it is pointing at an enemy, use bullet power proportional to the distance of the enemy from you. The farther away the enemy, the less power your bullet should use (since far targets increase the odds that the bullet will miss). 
  13. Boom04: Sit still. Pick one enemy and attempt to track it with your gun. In other words, try to have your gun always pointing at that enemy. Don't fire (you don't want to kill it). 
As you can see, the list of actions can be separated into three categories. The first category is mainly for you to understand how the robot moves around the battlefield, and get familiar with the methods provided. Position 4 and 5 in this first category gave me the hardest time because it involved using trig functions. I was unfortunate in implementing a code that directly uses trig functions in calculating the robot’s angle. Therefore, I have the robot move linearly to the center and corners as specified for those positions. Currently I am still in the process of experimenting with how to incorporate trig functions into calculating the angle and have the robot directly move to center or the corners.
            The second category involves picking an enemy robot and follows it around; which doesn’t involve any trig functions. Generally speaking, for the three exercises in this category I have the robot get the name of the enemy robot and follow it around, and if the one being followed lost contact with my robot I have it rescan for other robots to follow.
            In the final category, it involves exercises to either fire at an enemy or have the gun follow the enemy. For the first three exercises in this category, it was relatively easy to understand how to scan for a robot and fire at it. In the final exercise I had problems of trying to have the gun track the enemy relative to the distance from enemy to my robot. I had to calculate the angle of my robot and its gun relative to the enemy so that the robot knows where to follow the enemy.
            Overall, I think this project is great for people to get familiar with coding standards and learn how to read up API of a project. It is crucial to read up an API of a project because it provides descriptions of all the methods used in the class. This project also helps one to be familiar in using an IDE such as Eclipse to code their projects because it provides many features to help one implement their code.

           


           

     

Tuesday, August 30, 2011

FizzBuzz Experience

            Before I took ICS 211 I initially used Textpad to implement Java codes, but everything changed when I attended ICS 211. On the first day of class my professor introduced Eclipse to the whole class, which I had doubts about being easier than Textpad. Initially, it took me a while to get used to such a new environment to implement code. Fortunately, with the help of the tutorials and Internet I got used to using Eclipse to implement my Java codes.

            For this particular assignment the time to implement the code didn't take much time. The implementation only took me about 2 minutes. The most time I took was thinking up meaningful variable/method names. My intention was to give the variables/methods a name that is short and unique (non-repetitive names). The time it took me to implement the whole FizzBuzz code was about 5 minutes 20 seconds.
           
After I have implemented the code I wanted to try something new to test out my code. Usually I would execute the code and review the output to check if it matches the requirements. For this particular code I tried out the feature called JUnit to perform testing on whether the code contains any errors. Initially, the hard part about JUnit was figuring out how to get the code to run. Therefore, I referred to the Help Contents and searched online for examples on how to execute a code with JUnit.

Overall, this assignment gave me the experience of using an alternative method to test my program than using the traditional method (e.g. console output). For example, this time I used JUnit to perform couple test cases to ensure the program prints what I would expect based on the requirements. I also learned that implementing a code is not all about being fast, most important thing is making sure everything (e.g. syntax) is implemented correctly.







Friday, August 26, 2011

Sweet Home 3D: a free interior design software


             As hardware improves, software also improves to meet the standards of what the general public wants. This is why developers have developed many software suitable for both professional (e.g. fashion designers), and general public users. Open source projects have also contributed to producing software for both types of users to use either at home or at work. This software called Sweet Home 3D is an example of an open source project that both types of users can use.

            Sweet Home 3D is an interior design software, written in Java, that allows one to create a plan for a potential dream interior design of one’s home or work office. In this software a user can draw out a plan or scan in a blue-print and then perform all of the necessary modifications the plan needs. All it requires is the person’s imagination to create a beautiful, glamorous-looking design that may one day come to fruition.

            The software looks simple base on the interface, but is it successful? In a human computer interaction perspective, the software is successful if the design must meet the requirements of the usability goals. The goals include effectiveness, efficiency, safety, utility, learnability, and memorability. In software developer’s perspective, a software is successful if it meets The Three Prime Directives. The directives applies not only to published software, it also applies to open source software found on sites such as sourceforge.

Prime Directive 1:
            Sweet Home 3D allow users to perform the basic task of drawing out spaces for rooms, add boundaries (e.g. walls or dimensions of the land), add background, modify wall colors, object textures and sizes, and many other tasks. One useful feature of this software is the viewing option. Users can select between an aerial view and a virtual view. In aerial view, users views the design from a top view and are able move the plan around with the cursor. Virtual view allows users to view design just as they are touring a site. Difference between the two views can be seen as being transported from one dimension to another.

Prime Directive 2:
            After the software is downloaded it only takes less than a couple minutes to installed the software. If the user wants to consult for specifications, they can log on to http://sourceforge.net/projects/sweethome3d/ or http://www.sweethome3d.com/index.jsp (software’s parent website). The software’s parent website contains a link to a users’ guide allowing first time users to get a clue of how to use the software’s features. If the user unfortunately runs into a problem during installation or usage of the program they can report it under the support section on the parent website.

Prime Directive 3:
            I was able to locate the documentation specifying which Java structure were used to create the software and its plug-ins. Unfortunately I wasn’t able to locate the original code of the software. The structure of this software is based on using Java Applet and Java Swing. The documentation can be found at this website http://sourceforge.net/projects/sweethome3d/files/SweetHome3D-source/SweetHome3D-3.3-src/SweetHome3D-3.3-javadoc.zip/download?_test=crossmerch



NOTE: The software can be downloaded at either of the following websites. http://sourceforge.net/projects/sweethome3d/  or http://www.sweethome3d.com/index.jsp