Wednesday, December 7, 2011

Issue-Based Enhancements

     In earlier posts I have covered the concepts of Issue-based project management and the WattDepot based system that my development team had worked on, If you havent read my previous posts and have no idea what I am talking about, please read:
This

  Also an important issue that I will be discussing are the three prime directives of open source software, for a refresher of what those are please have a look at:
This

   For this blog post I wanted to discuss an exercise which my development team and I participated in, in which we took on the challenge of enhancing an existing system that was identical, Only in functionality, to the WattDepot Halealoha-Cli-Hash system that we had implemented. This other system that we had to enhance was non other than the infamous HaleAloha-Cli-Chair, of which I did a technical review of here:
Chair Review

  In the review I made the claim that a external can  understand and enhance the system aka prime directive number 3, but I had not actually tried to enhance it.  so in order to fully test the systems ability to be enhanced our development team each added one additional command to the HaleAloha-Cli-Chair system.  As it turns out, the system was EXTREMELY well organized and easy to understand.  After looking at the code for literally less than five minutes I had a very clear understanding of what was needed to add additional functionality to the system.  Aside from the class which I created in addition to the existing system, the only actual modification to the existing system that had to be made was the insertion of ONLY 2 lines of code. very easy! almost too easy...... so to original team Hash developer/s I would like to say great job! you made my life easy.

So lets take a look:

Here is the System

This is the additional functionality that I added to the system:


monitor-power [tower | lounge] [interval]

This command prints out a timestamp and the current power for [tower | lounge] every [interval] seconds.  [interval] is an optional argument and defaults to 10 seconds. Entering any character (such as a carriage return) stops this monitoring process and returns the user to the command loop.  

And just for fun here is the two line modification I had to make to the system:

MonitorPower monitorPower = new MonitorPower();
commandMap.put(monitorPower.getName(), monitorPower);

  As you can probably tell by now I was thrilled at how easy it was to understand and enhance this system.  Without a doubt this system satisfies the third prime directive.  Taking on the challenge of enhancing another development teams code base can be difficult, if not properly documented and implemented in a confusing way it can be a nightmare to sort through it all.  This was obviously not the case with HaleAloha-Cli-Chair.   

Tuesday, November 29, 2011

A Technical Review

  The following is a technical review of a system that is identical to the one explained in detail in my previous blog post.  It is a command line interface for an energy database that provides some utility by providing different commands a user can issue to receive energy data. This review focuses on the Three Prime Directives of open source software development, you can think of these directives at the most general guideline and standard for open source software production. I have used Green and Red arrows to denote a success/flaw concerning the system. Any of the concepts talked about in the following Technical review can most likely be found in more detail in my past blog posts.  

So what is a technical review anyway ? Look at this :

Just Kidding!
A technical review is a type of software review that involves a semi-structured process, usually including before hand preparation and a set of guidelines, including a focused area of examination of the system.  Having these attributes allows a reviewer, like myself, to more accurately review a system and give feedback which is helpful. So lets check out this system:

home page can be found here:

home page

To fully understand what we are testing please read the overview of the system on the home page.  It explains the system well.

The Continuous integration system can be found here:

CI

For those who dont know, a continuous integration system is a system that monitors the central repository of a system under development.  When the repository is changed the CI system runs a test to make sure that the change that has been made doesn't break the existing system.  this allows for early detection and correction of errors when working in development teams.


⬆  = GOOD JOB
⬇ = SOMETHING MISSING/WRONG

For this section I went to the home page, went to the downloads tab and downloaded the file. I then Unzipped the file and ran the jar file on the top level of the directory. after that I proceeded to use the system the following is what I found.

Review question 1:  Does the system accomplish a useful task?

I downloaded and ran the system without any troubles at all.
I ran a few initial tests to see if the basic commands worked, the outputs were as follows:

> daily-energy Ilima 2011-11-28
Ilima's energy consumption for 2011-11-28 was: 611.7 kWh.
> current-power Lehua-A
Lehua-A 's power as of 2011-Nov-29 17:49:06 was  6008 kW
> energy-since Ilima 2011-11-27
Total energy consumption by Ilima from 2011-11-27 to 2011-11-29 is: 1558.3 kWh.
> rank-towers 2011-11-27 2011-11-28
For the interval 2011-11-27 to 2011-11-28, energy consumption by towers were:
Ilima      1182.6 kWh
Mokihana   1186.2 kWh
Lehua      1205.8 kWh
Lokelani   1387.2 kWh

No Problems with the functionality as far as I can tell. when entering incorrect information an appropriate message is sent to the user:

The command inputted was not recognized (Enter "help" to see a list of available commands)

There is a typo in the error message, but no big deal.

when inputting incorrect arguments into the commands I found that the daily-energy repeats the error message in this instance, but again not really a big deal.

> daily-energy Ilima 212-334-4324
The date 212-334-4324 is invalid (Enter "help" to see command usage)The date 212-334-4324 is invalid (Enter "help" to see command usage)

I also found that that the system is case dependent, which is not necessarily good or bad.
Overall the system works great as far as I can tell, friendly and informative error messages are given to the user if an error occurs, and I was unable to break the system. It absolutely accomplishes one useful task.

For this section I did basically the same thing as I did above, but I looked into the documentation a bit more including the Wikiʻs that can be found under the wiki tab. After getting the system running once again I tried to put in bad input to break it.

Review question 2: Can an external user can successfully install and use the system?


When Inspecting the home site, the project home page is informative and well written.  the system is clearly described.

At the time of inspection [Nov 29, 6 pm] there was No UserGuide present in the Google Projects website under the Wiki tab.

There is a downloadable .zip file which contains the .jar file, very easy to download and run.
The download also has a version number, all is well with the distribution.

As I did above here are some more example of exercising the system, All seems well:

> @#$%^&*(
The command inputted was not recognized (Enter "help" to see a list of available commands)
> 3412513 435345 345345
The command inputted was not recognized (Enter "help" to see a list of available commands)
> DaIlY-EneRgY IlimA 2011-11-27
The tower or lounge IlimA is invalid (Enter "help" to see available sources
> rank-touers 2011-11-27
The command inputted was not recognized (Enter "help" to see a list of available commands)
> current-power 2021-11-27
The tower or lounge 2021-11-27 is invalid (Enter "help" to see available sources
> current-power xxxx-xx-xx
The tower or lounge xxxx-xx-xx is invalid (Enter "help" to see available sources
> QITH
The command inputted was not recognized (Enter "help" to see a list of available commands)
> Help
Available commands for this system:

energy-since [tower | lounge] [date]:
 Returns the energy used since the date (yyyy-mm-dd) to now.

current-power [tower | lounge]:
 Returns the current power in kW for the associated tower or lou nge.

daily-energy [tower | lounge] [date]:
 Returns the energy in kWh used by the tower or lounge for the specified date (yyyy-mm-dd)

rank-towers [start] [end]:
 Returns a list in sorted order from least to most energy consumedbetween the [start] and [end] date (yyyy-mm-dd)

quit:
 Terminates execution

Note: Hale Aloha towers are Mokihana, Ilima, Lehua and Lokelani
Lounges are the tower names followed by a "-" followed by one of A, B, C, D, E. For example, Mokihana-A.

Overall the system works well, cant break it, it works with good inputs VERY USEFUL !
You need a UserGuide.

The following involves a lot of concepts such as testing, coverage, documentation and code standards, SVN checkouts, and issue-driven project management. If you are unfamiliar with any of these concepts and wish to learn mor about them I would read my previous blog posts because they cover most of the main concepts addressed in the following section. These are also basic concepts in software development so there is a lot of information out there about them. 

Note: Jacoco is a coverage tool that this project used. It runs all of the test cases that are provided for the system and checks to see what percentage of the code was actually used, and which percentage was never used. remember coverage != good testing, good testing = good coverage. 

Issue-driven management:

blog post on Issue-driven management

Review question 3: Can an external developer successfully understand and enhance the system?


DeveloperGuide:

Indicate whatever quality assurance standards are being followed for this project
How a new developer can ensure that any code they might write adheres to these  standards
coding standards?
Are these documented?
Development process that is being followed aka Issue-driven?
explains the way that the developers for this project have implemented this process?
provide a link to the CI server associated with this project?
explain how to generate JavaDoc documentation?
   - system says verify will run java docs bust doesn't explicitly explain how to and then where to find the documentation for the system

Project Checkout
Generate JavaDocs
Well Written/ Clear.
Thorough documentation.

The documentation seems well organized and well written, there is no confusion of what each class/package does.  There seems to be no indication of information hiding. Overall good documentation.

project builds
Generate coverage




There is some missing coverage but upon inspection you can see that the missing code is all catch statements or error printouts.  It seems at though all of the non error related code is exercised in the test cases.

The testing methodology appears to be very thorough.  Each teas class addresses a number of different inputs, correct and incorrect, for each class. Each class has an associated Test class to exercise it.  From this inspection it looks well done.  The amount and span of testing provided leads me to believe that if changes were made to the system that would cause the current system to fail, the test cases would catch it.

Code:

coding standards are followed
code is commented appropriately
easy to understand
- The code is commented appropriately and can be understood.  there are a few places in the code that I would like some explanation on, but it should be noted that I like a lot of documentation in the code I write and read. Overall the documentation of the code is good.

Issues:
Is it clear what parts of the system were worked on by each developer?
could the Issues page be used to determine which developer would be the best person to ask?
Does the current system appear to result from approximately equal input from all of the developers
some developers appear to do much more than other developers

It seems to me like there is an unequal distribution of work within the team, which unfortunately happens, Mr. cshf...@gmail.com seems to have done a lot of the work, while the other team members contributed less.

CI server :
corrected promptly
worked on in a consistent fashion
commits associated with an appropriate Issue
A lot of builds were done today on the 29th, these most recent builds are not associated with issues. During what seems to be the core of the development phase all builds were associated with issues.


Overall we can see that this system is good, it is tested pretty well, it runs well, it is documented well except for a user guide. It passes the three prime directives.

Sunday, November 27, 2011

Issue-Driven Project Managment

  In order to work in any sized development team the project at hand needs to be modularized in such a way that every developer on the team has a task to do.  Ideally, throughout the duration of development, each member of the team would always have a task to do, to avoid any wasted time.  It would also be ideal for each member to know which new task they can begin after completion of their current task.  In this way there is no confusion on the role of each developer in the team, this is more of less the goal behing issue-driven project management.  When managing a project utilizing an issue driven approach there are a few seemingly simple guidelines that I have used and found effective:

1. Divide up the work into tasks.
2. Make sure that each task is not too big, for the project I am currently involved in each task ideally takes no longer than 2 days to complete.  Large/lengthy tasks can lead to problems.
3. Each task is specified by an issue.  For examples of some issues please see These Issues
4. Each issue should have a single owner - as shown in the example above, this allows independent work.
5. At all time each developer should have a task they are working on.
6. Every commit or change to system should be associated with an issue and be documented accordingly.

  Although these guidelines seem more or less simple, actually implementing and upholding them in a real project can be challenging.  This became very clear to me as my team took on a simple project to develop a command line interface for a Wattdepot server. The home page along with a description of the functionality of the project can be found here : Halealoha-Cli-Hash
  In summary our team had to develop a small system that runs ont the command line that takes in a limited set of user commands, retrieve the appropriate information from the WattDepot servers, and returns the answer. the list of commands was as follows:

-current-power [tower | lounge]
Returns the current power in kW for the associated tower or lounge.
-daily-energy [tower | lounge] [date]
Returns the energy in kWh used by the tower or lounge for the specified date (yyyy-mm-dd).
-energy-since [tower | lounge] [date]
Returns the energy used since the date (yyyy-mm-dd) to now.
-rank-towers [start] [end]
Returns a list in sorted order from least to most energy consumed between the [start] and [end] date (yyyy-mm-dd)
-quit
Terminates execution
-help
Prints out this list

   As you can see, not too difficult, but despite the fact that the overall project was not too difficult we did run into some problems trying to use issue driven project management.  The first unseen difficulty was to divide up the work in such a way that no one persons work was dependent on the completion of another work.  This could end up stalling development especially when some group members work faster than others.  We were able to work out this problem, and it should be noted that having SHORT issues makes this problem a lot easier.  After our team got really going on the project we had few other difficulties.  We did have an unequal distribution of work in our team, but that is to be expected when dealing with a group of students with different work loads.  Our team was able to complete the project, and ahead of schedule, with the help of issue-driven management.  Overall I found using this type of project management to be simple and effective.  
If you want to check out the project you can find a download of it here: HaleAloha-Cli-Hash
Just check out the WIKI page for instruction on how to download and use the project.
Mahalo.

Wednesday, November 9, 2011

Jenkins

Jenkins is a continuous integration system, which for me means a system to check out, build and verify a project that I have created on google project hosting. My first Jenkins project can be found here:
Jenkins Green-Machine project
As you can see its been set up to monitor my Green-Machine Robocode project, It is configured to build the project using a jenkins.build.xml file which depends on a verify.build.xml file, which tests the project. Upon a build fail Jenkins will send a email to all of the project members, this is very advantageous because it allows early detection of any update that breaks there system.
I ran a test to see if Jenkins was working by breaking the project and I received this email.


------------------------------------------
[...truncated 77 lines...]
[javac] ^
[javac] :80: class, interface, or enum expected
[javac] public void onHitRobot(HitRobotEvent event) {
[javac] ^
[javac] :86: class, interface, or enum expected
[javac] gunTurnTo((int) getHeading() + (int) event.getBearing());
[javac] ^
[javac] :88: class, interface, or enum expected
[javac] setBulletColor(Color.RED);
[javac] ^
[javac] :89: class, interface, or enum expected
[javac] fire(Rules.MAX_BULLET_POWER);
[javac] ^
[javac] :90: class, interface, or enum expected
[javac] }
[javac] ^

...
..
.
As you can see the email actually indicated where the problem is(very cool). because i commented out teh class declaration for Green_machine I received a lot of errors.

Tuesday, November 8, 2011

WattDepot

WattDepot is an open source, RESTful web service that collects electricity data (such as current power utilization or cumulative power utilization) from meters and stores it in a database. The data can then be retrieved by other tools for visualization and analysis. It is designed to provide infrastructure for experimentation and development of "Smart Grid" applications."
From: WattDepot
  My last post was about energy and the unique energy situation we have here in Hawaii.  If you havent read over that post please feel free to do so here:
Lets Talk Energy
  WattDepot, as mentioned above, is a tool which allows us to collect and retrieve energy data from a database and use that data as we wish.  WattDepot is therefore a great tool for the analysis of energy data that can be used to monitor energy trends and usage and can be used educate, a good example of which is the kukui cup at the University of Hawaii at Manoa.
Kukui Cup
  To help us explore this new system we can apply the exercise of code katas ! Please refer to my older blog posts to learn about code Katas, and how I have used them in the past to explore new systems.  Befor we look at the Katas you can get a distribution of the WattDepot system here:
Distribution
Lets take a look at the Katas that I took on to help me understand how to write a WattDepot client.  I was able to finish them all, but they were not a walk in the park.





Kata 1: SourceListing

Implement a class called SourceListing, whose main() method accepts one argument (the URL of the WattDepot server) and which writes out the URL argument and a list of all sources defined on that server and their descriptions, sorted in alphabetical order by source name.  Use the System.out.format method to provide a nicely formatted list.  For example:

Server: http://server.wattdepot.org:8190/wattdepot/

Source                 Description
Bar                    Represents the energy consumed by the Bar building.
Baz                    Represents the energy consumed by the Baz floor of the Bar building.
Foo                    Energy generated by the Foo power plant.
Qux                    The energy meter associated with the Qux household.


Kata 2: SourceLatency

Implement a class called SourceLatency, whose main() method accepts one argument (the URL of the WattDepot server) and which writes out the URL argument and a list of all sources defined on that server and the number of seconds since data was received for that source, sorted in ascending order by this latency value.  If no data has every been received for that source, indicate that.  Use the System.out.format method to provide a nicely formatted list.  For example:

Server: http://server.wattdepot.org:8190/wattdepot/

Source                 Latency (in seconds, as of 12-Oct-2011 14:32:12)
Baz                    9
Bar                    10 
Foo                    14
Qux                    No data received.

Kata 3: SourceHierarchy

Implement a class called SourceHierarchy, whose main() method accepts one argument (the URL of the WattDepot server) and which writes out the URL argument and a hierarchical list of all sources defined on that server.  The hierarchy represents the source and subsource relationship between sources. For example:

Server: http://server.wattdepot.org:8190/wattdepot/

Source Hierarchy
Baz
  Bar
  Zob
    Zob-A
    Zob-B
Foo
Qux 

Thus, the source Baz has two subsources, Bar and Zob.  The source Zob has two subsources, Zob-A and Zob-B.  Foo and Qux have no subsources. The hierarchy is represented by two space indentation.

Kata 4: EnergyYesterday

Implement a class called EnergyYesterday, whose main() method accepts one argument (the URL of the WattDepot server) and which writes out the URL argument and a list of all sources defined on that server and the amount of energy in watt-hours consumed by that source during the previous day, sorted in ascending order by watt-hours of consumption.  If no energy has every been consumed by that source, indicate zero.  Use the System.out.format method to provide a nicely formatted list.  For example:

Server: http://server.wattdepot.org:8190/wattdepot/

Source                 Energy consumed in watt-hours (19-Oct-2011)
Baz                    932
Bar                    1025 
Foo                    1436
Qux                    2357

Kata 5: HighestRecordedPowerYesterday


Implement a class called HighestRecordedPowerYesterday, whose main() method accepts one argument (the URL of the WattDepot server) and which writes out the URL argument and a list of all sources defined on that server and the highest recorded power associated with that source during the previous day, sorted in ascending order by watts.  Also indicate the time when that power value was observed. If no power data is associated with that source, indicate that.  Use the System.out.format method to provide a nicely formatted list.  For example:


Server: http://server.wattdepot.org:8190/wattdepot/

Source                 Highest recorded power in watts (12-Oct-2011)
Baz                    10,034 10:30am
Bar                    10,456 2:45pm
Foo                    14,876 12:30pm
Qux                    23,578 4:15pm

This is a little tricky due to the presence of both virtual and non-virtual sources. For non-virtual sources, you could retrieve all of the sensor data and just iterate through to find the maximum power value. However, virtual sources represent an aggregate of non-virtual sources, so there is no sensor data associated with them directly, and it is unlikely that the sensor data timestamps for its constituent sources will be synchronized exactly.


One reasonable way to deal with this is to request the computed power at (say) 15 minute intervals for the entire day, which provides 96 data points per source whether it is virtual or non-virtual.

Kata 6: MondayAverageEnergy

Implement a class called MondayAverageEnergy, whose main() method accepts one argument (the URL of the WattDepot server) and which writes out the URL argument and a list of all sources defined on that server and the average energy consumed by that source during the previous two Mondays, sorted in ascending order by watt-hours.  Use the System.out.format method to provide a nicely formatted list.  For example:

Server: http://server.wattdepot.org:8190/wattdepot/

Source                 Average energy for last two Mondays in watt-hours (24-Oct-2011, 17-Oct-2011)
Baz                    10,034 
Bar                    10,456 
Foo                    14,876 

Qux                    23,578 

   Some of these Katas were more difficult than others, Kata 3, building the hierarchy caused me some hours of trouble, and learning how to manipulate Gregorian calendars also took me a while to become competent in.  Other than that there is a close relation between the last three Katas which made life a little easier.  I found implementing and utilizing a simple data structure to sort the sources as very useful.  Good Luck and Have Fun !! 

Friday, October 28, 2011

Lets Talk Energy

    Hawaii is in a very unique situation when it comes to the issue of energy.  Energy prices in Hawaii can be from 3 to 6 times more expensive than those in the mainland US, these high prices have several causes.  One of the main reasons Hawaii has higher energy prices is because of the states dependence on oil, a very high percentage of the energy ( 77 %) created in Hawaii is done so using oil.  Oil has to be imported into Hawaii and is also more expensive initially than other resources, like coal, which is greatly used in mainland US production of energy (45 %).  Another big difference between Hawaii and the mainland US is that Hawaii has several small power grids it runs off of, while the mainland US has one huge supergrid that deals with all the power supply.  Having one large connected grid allows more flexibility than having smaller unconnected grids.
     While having more expensive energy sounds like a bad deal, which it is, there is also a silver lining to this issue.  Hawaii is lucky enough to have access to a plethora of different kinds of renewable energy resources including wind, geothermal, solar, biofuel etc. and because Hawaii is so dependent on oil when oil prices rise, the cost of oil dependent energy rises along with it.  So how could this be a good thing?  Renewable energy is expensive, and while the price of renewable energy remains greater than the price of other non renewable energy sources we will continue using these non renewable resources.  Because the prices of oil produced energy in Hawaii will continue to rise rapidly into the future and because Hawaii has access to a multitude of renewable energy resources Hawaii is bound to find itself in a situation where renewables will become cheaper than imported oil produced energy, and this transition will happen before most every place in the world.  This earlier transition along with support from local government puts Hawaii in a unique situation to get rid of its oil dependencies and also serve as a model for the mainland US, and world wide, on how to transition to renewable energy.  This is also advantageous economically because Hawaii may develop new service exports dealing with these issues.
    This is a software engineering log so lets talk software.  This transition into renewable energy resources here in Hawaii has already begun, and it has funding.  Along with the new technologies that are being developed and the studies being conducted there is a demand for software that can deal with these complex issues.  As the movement towards green energy gains momentum there will be a lot of new opportunities for developing these new systems.  This puts us future and current developers and researchers in a great situation in which we are looking at a potentially explosive field, not just in Hawaii but throughout the US, and one ground zero may in fact be Hawaii.  Hawaii will be one of the first places to adopt renewable energies on a large scale and the associated software that supports these new systems,  these new systems can potentially serve as a model for the rest of the US and other places in the world, which puts us in a very interesting and exciting situation.
    While this is very exciting, it is also very difficult.  There are many new and interesting challenges that have to be addressed and overcome and there are people that support the movement to renewable energy and those who also oppose it.  Along with the development of new software and technologies that will make this transition possible, there are also political challenges such as local opposition to building windmills and geothermal plants on the islands especially when its to support the energy consumption of another island which is the issue of the very centralized use of power on Oahu compared to the other islands and how that can be dealt with.
To learn more please check out this series:    
Click Here

Thursday, October 20, 2011

Review

What are the positives and negatives of a walkthrough code review?

Positive: cheap
Negative: unreliable Information/quality

Name 6 instances in which the verify.build.xml command can fail.

PMD, Checkstyle, FindBugs, Junit, JavaDoc, any .xml file error

Explain the What X and Y are, and their relationship to each other:
<target name="X" depends="Y"....
X is the name of the target, Y is a dependency of the target, meaning X will not execute unless Y does.

Give an example of an error that would only be found by Find Bugs.

while (true) {
....
}

What is the shared data problem in respect to a RCS.

The shared data problem occurs when two developers want to edit/work with the same data or file in a project.

Wednesday, October 19, 2011

Configuration Management and Google Project Hosting

    In order to streaming a software development process among a software team it is extremely valuable to utilize a  configuration management system, a way to control the development process when multiple software developers are writing/editing possibly interdependent code.  Without a configuration management system problems may arise during development such as inconsistant code among developers, no clear indication of when the system started or stopped working properly and what code was responsible, the problem of simultaneous updates which cause "clobbering"  aka only one persons code being uploaded and the shared data problem which arises when two developers need to work on the same file/data.

    Version control is a type of configuration management whose main goal is to maintain multiple versions of the system. Google Project Hosting is a version control system that uses Subversion, which is one of many different version control systems.  Subversion uses a central repository, or a complete and always up to date version of the software project that can be checked out, modified (on an individual basis) and committed(update change/s to repository) by developers.  Each commit made by developers is tracked by Subversion so that there is always a reference to each update in the system, which makes it easy to locate when and where an error occurred.  Subversion also prevents clobbering, by maintaing each developers version of the repository through updates,  and allows each developer to have a complete version of the system, which eliminates the shared data problem.


 

     Getting a project started with Google project hosing is relatively simple, you just have to give it a name, upload files to the repository, and provide supporting documentation for users and developers.  After that you are ready to start adding developers to the project.  Here is an example of  my first project through Google Project Hosting:






      The above is the front page of my hosted project, as you can see we have a description in the text field of the project, there are multiple tabs at the top including downloads, wiki( aka documentation), issues and source.  If you wanted to check out this project you would do so from the source tab, if you wanted a distribution of the system you could find a .jar file under downloads. please feel free to explore this project to get comfortable navigating a Google hosted project.


  This is a project which contains my competitive Robocode robot.  Please see previous posts if you are curious to what that is:

Java fueled robots
and
GreenMachine

  Setting up a project in Google Project Hosting is straight forward, things that I found can tie you up a little would be the documentation, and making sure that the files in your repository are in the correct place.  A few of the small things can be a little confusing but everything you need to know for setting up an new project can be found here if you get stuck:

Getting Started

This is a free and powerful tool for team software development, and as a side note in order to properly use a Subversion system you need to have a Subversion client on your machine, this is the one I am using for Mac.

SmartSVN

How to use a Subversion client is a whole different topic.  You can use the documentation on the above website to get started.

Tuesday, October 11, 2011

GreenMachine ! Robocode robot

  I have just completed my first battle ready Robocode robot that I named GreenMachine!  If you are unfamiliar with the Robocode project you can read up on my previous post here:
robocode 

If you want to download a distribution of my robot you can find it on my site:
Robot Distribution

The creation of this robot was inspired by a upcoming Robocode competition among some of my fellow classmates, I wish them well.. but I believe that the GreenMachine will do well given the short amount of time given for development of robots for the competition. The GreenMachine is a robocode robot that extends only the robot class, not the junior robot or advanced robot, which means that there are a lot less built in methods to utilise.  Most of my robot is composed of original code except for one method I use to linear target robots that move in 90 degree angles, (such as sample.walls).  the design ideas that I implemented are as follows:

Movment:
   For my movement I could not think of a good way to avoid being hit except to be unpredictable... so what better way to be unpredictable then to use sporadic sudo random movements.   For my movement method I use a built in Java random number generator and generate a random degree between 0-300 and a distance between 75-100 pixels.  I chose to move such a short maximum distance per turn because moving in one way for any extended time will give an opponent a chance to preform linear targeting on my robot. This movement seems to evade a lot of shots, but we will see how it preforms in competition.  A way to improve on this move method (I didn't have the time to) was to eliminate the possibility of moving directly towards or away from the enemy, as this would not change you retaliative bearing in comparison to the enemy.

Targeting/Firing:
   For my targeting I continuously scan the field between moves and acquire a target.  Once my target is acquired I will shoot a bullet at their bearing with power retaliative to their distance from my robot (farther away less power).  If a shot hits its target then the overridden method onBulletHitEvent will immediately fire a mid-power bullet to the same X any Y coordinates that the first bullet struck the enemy, it does this after it moves just in case the enemy fire a retaliation shot in the direction it was struck by my bullet.  In the event that my robot comes close to the enemy, within 100 pixels, the GreenMachine will charge its enemy full speed and on contact with the enemy fire a shot with maximum power, this method of close combat seems to work great.  In the event that a robot is moving in 90 degree angles like sample.walls, GreenMachine will change its behaviour and use linear targeting to make shots that try and intercept the enemies future location.  This behaviour was used from
walls killer 
and was the only code in my robot that I did not write. Finally in the event my robot is hit by the enemies bullet I immediately fire a retaliation shot in the direction it came from then move.

Results of my Labor:
   GreenMachine can beat most of the sample bots reliably including Walls, RamFire, Crazy, Fire,  Corners, Tracker, SittingDuck.  It does have some trouble with SpinBot because it does not have a method for dealing with circular predictive targeting, therefore it wins about half the time against SpinBot. To improve on this I need to create a way of identifying robots that move in circles and devise a way to track them. 


Lets Take a Look: I suggest watching it expanded and in HD on YouTube.








Testing:
   For my testing methods, I used Junit tests to judge my robots progress by having 10 round battle results quickly evaluated for each of the sample robots.  This allowed me to quickly see the effect of any change I mad to my robot.  In addition to these battle simulations I also tested different methods of my robot such as my firing techniques and my robots responses to events such as impact with another robot and impact with walls.  I also utilised JaCoCo to see the coverage of my tests. 


Lessons Learned:
   I learned a lot from this project, I learned about creating a more advanced robot and how complicated robots can get.  I also learned a lot of valuable skill on how to use Junit tests to test a program as well as guide the progress of software development.  Throughout this experience I was utilising the Ant build system and therefore became very familiar with how the Ant and .xml files used in ant work.  Towards the end of the development of GreenMachine I was utilizing Ant + Ivy in an efficient way.  It has also become very clear to me the value of using a build system when developing software among multiple software developers.  From a software perspective I would become very familiar with my build system before writing any code, and from a Robocode developer perspective I would search every nook and cranny of the Robocode API before beginning development to save on time and effort.  I found that writing Junit tests after I began this project was difficult, If I could do it over again I would like to try the approach of writing my Junit tests before the code they are meant to test.

Wednesday, September 28, 2011

The Power of Ant

   The development of software on a larger scale, meaning there is some sort of development team, becomes difficult for many reasons. When attempting development with a team you will be dealing with multiple developers, possibly using multiple types of systems, with different development environments and the utilisation of third party libraries. So how in the world can you work together in an effective and efficient way? One option is utilising something called a build system, like Apache Ant:

  "Apache Ant is a Java library and command-line tool whose mission is to drive processes described in build files as targets and extension points dependent upon each other. The main known usage of Ant is the build of Java applications."

so what does that mean...

  It means that Ant uses files called "build files" to execute certain commands or tasks called "targets" whose purpose is to make the software development process better by creating/allowing usability and portability between different systems and developers. Ant provides a "unifying technology and set of principals for building any software system" (Johnson)

Download Ant at:
Apache Ant Home Page

In order to learn the power and utility of a build system like Ant I recently, and successfully, took on the "Ant code Katas". Lets take a look at these simple tasks that demonstrate and teach the Ant basics.  Below in a few of the katas I have added an image of my code to give an example of what a build file looks like.
                                                                             
1. Ant Hello World

Create a script called helloworld.build.xml.  Invoking this script via "ant -f helloworld.build.xml" should print out "Hello World".  The script consists of a single (default) target called helloworld with a single line that invokes the <echo> task to print out Hello World. 

2. Ant Immutable Properties

Create a script called immutable.build.xml.   This script contains two <property> elements, one of which assigns the property "my.property" to the value "1" and the second of which assigns the (same) property "my.property" to the value "2".  Now create a target called "printproperty" that uses the <echo> task to print out the value of the property "my.property".  

If done correctly, this script demonstrates that build properties are immutable: once they are set, their value cannot be changed. 

3. Ant Dependencies

Create a script called dependencies.build.xml.   It should contain targets called "foo", "bar", "baz", "qux", and "elmo".  Each target should consist of a single <echo> task that prints out the name of its target. The default target is foo.

The targets should have the following dependencies:
  • foo should depend upon bar.
  • bar should depend upon baz and elmo in that order.
  • baz depends upon qux.
  • qux depends upon elmo. 
  • elmo has no dependencies.
Now invoke the build script using "ant -f dependencies.build.xml".   What is the order of targets. In particular, where is elmo called and why

Try invoking "ant -verbose -f dependencies.build.xml".   Note that Ant now tells you how it seriallzed the dependency structure.

Now make elmo depend upon bar and reinvoke the script.  Make sure you understand what happens.                                                                                        
4. Hello Ant Compilation

Create a file called HelloAnt.java, which contains a Java class called "HelloAnt" and a main method that prints out "Hello Ant" to the console.  This file should be in a src/ subdirectory.

Create a second file called compile.helloant.build.xml that contains a single target called "compile".  This target contains a single <javac> task that compiles the HelloAnt program.  You do not need Ivy.   You should be able to compile the program with "ant -f compile.helloant.build.xml".   These class files should be written to a build/classes subdirectory.

You may want to create src.dir and build.dir properties. 



















5. Hello Ant Execution

Create a file called run.helloant.build.xml that compiles and runs the HelloAnt program.  It should use the <import> task to import the contents of compile.helloant.build.xml so you have access to those targets. 

Again, make this file as simple as possible. Provide a single target called "run", and make this "run" target depend upon the "compile" imported target so that the code is always compiled before being run. You should be able to compile and run the program with "ant -f run.helloant.build.xml".  

6. Hello Ant Documentation

Create a file called javadoc.helloant.build.xml that generates the JavaDocs for the HelloAnt program.  Once again, make this file as simple as possible; it can contain a single target called "javadoc" that invokes the <javadoc> task.  

The javadoc target should ensure that the HelloAnt program compiles, so you will want to import compile.helloant.build.xml   The javadoc html files should be placed in the build/javadoc subdirectory.  You should be able to generate the JavaDocs with "ant -f javadoc.helloant.build.xml". 

You can create a few properties to support the documentation process if you like.  You must ensure that the javadoc command completes without any warnings or errors.  This means you might have to improve your HelloAnt program!

7.  Cleaning Hello Ant

Add a target called "clean" to your compile.helloant.build.xml file. It should delete the build/ directory.

8. Packaging Hello Ant

Create a file called dist.helloant.build.xml.  It should contain a single target called "dist".   The dist target should have dependencies that compile, execute, and create javadocs for the helloant system (thus checking to make sure the system works correctly).   After all of these dependencies should be the clean dependency. 

The contents of the dist target creates a zip file containing the (cleaned) version of the current directory and all its subdirectories.  This zip file should be put into the (newly created) build/dist directory. Its name should be ant-code-katas.zip,  Unzipping this file should create a new directory called "ant-code-katas" which contains your ant kata files. 

To check your work, invoke "ant -f dist.helloant.build.xml".  Now cd to the build/dist directory, invoke "jar -xf ant-code-katas.zip".  This should create a new directory in build/dist called "ant-code-katas.   Now cd into that directory, and make sure that all of your kata files (and the src/ directory) are there, but that the build/ directory is not there.  Finally, invoke "ant -f dist.helloant.build.xml" in this directory. It should create a new build/dist directory containing yet another copy of ant-code-katas.
 Overall I have found that with a little practice Apache Ant is a very easy and powerful tool.  It is easy to imagine how necessary build systems like Ant are for certain kinds of software development.