Thursday, September 16, 2010

Competative Robocode

Overview:
This is the second AI programming assignment I've come across at school.  Generally I find these assignments to be both very frustrating and rewarding (depending on if it does what you want or not!)  Some of the things I wanted to implement didn't seem very difficult, but when you take the math that is involved, it can be hard to get the right results.

Design:
Movement:
The movement system I implemented this bot is very simple.  For the most part it will try to move in a straight line in intervals equal to half of the stage width/height.  When it hits a wall it will attempt to turn around 180° before moving again.  This can be bad sometimes if it manages to get itself stuck in a corner.

Targeting:
This bot has a fairly decent targeting system which I took from my Boom04 bot.  It will lock on the first target it scans.

Firing:
Firing on every scan can be in efficient, especially the shots are missing.  In order to make up for this there is a counter that will stop the bot from firing until it runs out of energy.  Bullet strength/speed is determined by distance to target.  The closer the target is, the stronger the bullet.

Win results against a few sample robots:
vs Sitting Duck: 100%
vs Corners: ~60%
vs Crazy: ~70%
vs Fire: ~ 50%
vs RamBot: ~60%
vs SpinBot: ~ 50%
vs Tracker: ~70%
vs Walls ~40%

Lessons Learned:
Designing a bot for the first time can be a little daunting.  I think for the first attempt you should try and keep it very simple, and build your way up from there.  I wish I knew more trigonometry so that I could express some features I would have liked my robot to have, (i.e. - predictive targeting).

Download: www2.hawaii.edu/~gaskell/ahg.CakeBot_1.0.jar

BattleBots

Tuesday, August 31, 2010

Open Source Project: TeXlipse




Simple user interface with syntax highlighting.



Overview:
TeXlipse is a Java-based plugin that adds LaTex text editing support to the Eclipse Java IDE.  

Key features include:
  • Syntax highlighting
  • Command completion
  • BibTex support
  • Automatic building
  • Spell checking

Prime Directive #1: The system successfully accomplishes a useful task?

As a first time LaTex user, it was nice using it in an IDE that I am already familiar with.  The most important feature to me was the Syntax highlighting  and automatic building.  The addon performs the these tasks wonderfully, but that was after going through the hassle of setting it up...

Prime Directive #2: An external user can successfully install and use the system.

Part 1 - Installation

Installing the plugin was fairly straightforward as it can all be done through Eclipse's interface.

Part 2 - Configuration

The guide was not as helpful as I would have liked it to have been, especially since it's written from a Windows perspective (interface is a little different).  Although after manually setting up your Builder and Viewer settings you have control over everything.  It's up to your discretion whether you want to view the PDF file in Preview or Acrobat Pro!

Prime Directive #3: An external developer can successfully understand and enhance the system.

The file from SourceForge will give you all the of the Java files a developer would need to start developing for TeXclipse.  All of the code is well documented, though the library is so expansive it would take a new developer some time to understand how everything works.

FizzBuzz

On the first day of class we were presented with a quick Java programing quiz called FizzBuzz.  A simple program which we were only given 5 minutes to complete on paper.

Unfortunately I came up a few lines short before I handed it in so I wrote it again later on that day taking about 6 minutes complete after starting up Eclipse:


/**
 * FizzBuzz program. 
 * Prints numbers 1 to 100.
 * If the number is divisable by 3 it prints out "Fizz".
 * If the number is divisable by 5 it prints out "Buzz".
 * If the number is divisable by 15 it prints out "FizzBuzz."
 * 
 * Time taken to write 4 minutes.
 * @author Tony Gaskell
 *
 */
public class FizzBuzz {
  public static void main(String[]args){
    for (int i = 1; i <=100; i++){
      if (i % 3 == 0){             // <-- If the number is divisible by 3...
        System.out.print("Fizz");
      }
      if (i % 5 == 0){             // <-- If the number is divisible by 5...
        System.out.print("Buzz");
      }
      else if (i % 3 != 0){        // <-- If the number not divisible by 3 or 5...
        System.out.print(i);
      }
      System.out.print("\n");      // <-- UGH
    }
  }
}




Nothing had really changed since the code I had written in class except for being able to get in the last else statement.

The program is a simple for loop that counts from 1 to 100.  If the counter i is ever divisible by 3 it will print Fizz to the screen, and Buzz if it is divisible by 5.  I decided to do as few checks as possible so that the program could run slightly faster.  By default if the number is divisible by both 3 and 5 it will print out FizzBuzz on one line since there's no new line characters being printed out at each check.  The final else statement catches everything that is not divisible by 15 and prints the appropriate number to the screen.  At the end of each iteration a new line character is printed.

I think the program turned out pretty well for the time that was put into it.  
I'm not too fond of the line: System.out.print("\n"); since it's not very elegant, but it gets the job done I suppose.

Luckily I have used Eclipse before in my second semester of Java programming, so I was already pretty familiar with the interface.

I was pretty surprised that I could recall my Java since I haven't touched the language in a little over eight months, but I guess the syntax is pretty much the same thing as C.