Friday, 31 December 2010

miTanks, Part 2

Something I've missed:
Android apps are written in Java plus some xml for view layouts etc.

I have started drawing up a rough class diagram for the game and started to think about how to implement destructible terrain. As we want a clean fall animation for the ground when a piece is broken below, I am currently thinking about having the entire game screen as a 3d boolean array. Animations with this will be incredably easy. Hopefully this won't be too much to process every turn.

Some minor code has been written to help visualise the working of the tank class. As this is early on in the process it is likely to be rearranged quite regularly, due to the nature of eXtreme Programming.

I will try to have the game run on both the Android and a computer. This will help for initial game development as testing on the Android Virtual Device is time consuming. Also when the game is complete I will release a run-able jar file so everyone on here can play the game.

Most likely won't be doing small releases as we go, due to the size of the app. When it is actually playable it will almost be finished. Just bug fixes, extra weapons and smoothing out code after the app works.

Here are some initial concept shots by Foo.
Initial Concept Screenshot
Second Concept Screenshot



Concept Tank 1

Thursday, 30 December 2010

Hello, Android!

Well so far Android is hard to program to. Considering I've only ever done to a screen of whatever size I decide, this is very new. Also being an app leaves me with alot of other things to consider. Layout is a huge issue.

Eclipse handles the vast majority of the initial set-up so managed to do this with 2 lines of code changed.

Good start I believe.

miTanks, Part 1

So now that I have an Android phone my next plan is to create an app. I could port some of my CLI games across very easily, but that's no fun. I'm going to remake Tanks, with the help of a friend, herein refered to as Foo.

Tanks is a simple turn-based game. Each player has a tank. On your turn you select the angle to shoot and the power, and then fire. Some minor physics determine travel of the shot. Then there is collision and damage calculations. Rince and repeat until there is only one tank left standing.

I'll get Foo to post an about Foo thing here aswell. Foo has an LG p500 (Optimus One), that runs Android 2.2. Slightly better specs than the Galaxy 580 for a similar price. Galaxy 580 runs Android 2.1, so will use that as the minimum version.

Tuesday, 28 December 2010


I just found out that Dick Smiths Electronics is having a 20% off sales for all their phones, thats ending at 5.30pm today. I've wanted an android for a while now. So I've got 1.5 hours to do some research and see which one to get.

Must be:
  • Vodafone
  • Keyboard
  • Android
  • Good
  • Preferably cheap

Option 1: Vodafone 845
Main point of difference are the price NZD$199.00. Although there is a lack of not having a keyboard. Resolution is acceptable. The main issue for me is ease of use. I don't particularly like touch screens.
Review from techradar:
The touchscreen itself is resistive rather than capacitive, and it does it's best to resist your commands a large part of the time. Swiping and moving around apps is relatively responsive, but getting the desired response from simply pressing the touchscreen can be difficult. Typing? Again, not so easy.
Review from expertreviews:
As a budget Android phone, the 845 stands out for having the latest version of the operating system, but despite a host of great features, it's no match for the Samsung Galaxy Portal with its 3.2in AMOLED capacitive touchscreen.
Final thought:
Main concern here is the ease of use.

Option 2: Samsung Galaxy 580

Coming in at twice the price of NZD$399.00, the Samsung Galaxy 580 better be good. Again no keyboard. Think I'll only have a quick look at this one.

Review from random customer at DSE:

I've finally found a phone I can use with ease. I never liked the touch screens before but the Samsung Galaxy is really easy to use,
Pro's - 3 instant brightness settings, Good volume control, Clear Icons, WiFi connectivity plus the usual extras. Con's... some apps drain the battery if you don't turn them off, but once you learn what's what, it's a great phone, and really good value for money.
Not really sure if I should be trusting this review for anything.

Final thought:
The only other phone here with Andriod OS 2.1. Will have a look in store.

Option 3: Sony Ericsson X10 Mini Pro
Sony ericsson xperia x10 mini pro
At the same price of the above Samsung Galaxy 580 of NZD$399.00, with a keyboard, the Sony Ericsson X10 Mini Pro seems a more likely option.
Review from cnet:
The addition of a keyboard makes the X10 Mini Pro surprisingly usable, as long as you don't mind its little screen. It's not a phone for media lovers or Web junkies, but, if you're seeking smart-phone prowess in a ridiculously small package, the X10 Mini Pro could be worth a look.
Review from techradar:
The phone itself is much more powerful and responsive than any of the other phones in its entry-level price bracket, so much so that comparing this with the similarly price Vodafone 845 feels quite wrong. The X10 Mini Pro is streets ahead of it.
With such a lack of competing Android QWERTY phones out there on the market, the Sony Ericsson Xperia X10 Mini Pro is going to have the whole sector to itself, we suspect.
In fact, the Mini Pro feels as fast in use as many of the top-spec phones of today like the HTC Desire, so we can imagine it'll also win over quite a few of the 'enthusiasts' out there as well. It's quite an achievement.
And don't fear the small screen – Sony Ericsson has made a smartphone so user friendly you're in no way hindered.In short, the Sony Ericsson Xperia X10 Mini is quite an impressively powerful and polished phone
Final thought:
Definatly on my high list. Wonder how much of a difference this 1.6 Android OS is going to be.

Option 4: LG Optimus GT540
Same price as the above two at NZD$399.00. Again no keyboard. Also using the outdated 1.6 Android OS.
Review from techradar:
The screen is clear and bright, but sadly it's resistive, and far from being the best of its type to come our way. We didn't have to press too hard to make a connection (although it is annoying having to remember to over-press, although we guess that will become second nature eventually).
Final thought:
Another not so user friendly out of date Android mobile. This is starting to look depressing.
Option 5: Sony Ericsson Xperia X8
Sony ericsson xperia x8
Another Android at the familar price of NZD$399.00. Again without a keyboard. Let's check the reviews.
Review from techradar:
The good news is the X8's touchscreen uses capacitive technology, so it's immediately more usable than other entry-level Android phones like the LG GT540 and Vodafone 845, which use the cheaper, less sensitive resistive technology. And don't work.
Ok, this looks promising. Again this is using the 1.6 old Android OS. Keep reading.
As a result, the X8 finds itself in a bit of a bad place where it's outsmarted on all fronts by other models – even Sony Ericsson's own X10 Mini is a better option. If you're not concerned about having the latest (or even a particularly recent) version of Android, the X8 will do, but it's hobbled by an unresponsive touchscreen and the many difficulties that brings.

Final thought:
From that last line alone, I'm crossing this off my list.

Option 6: LG Optimus One p500
Recommended by a friend a little too late. Thought I'd add it here anyway. Same price of NZD$399.00.
Review from techradar:
The Optimus One is a solid phone, but there's little in the way of outstanding features to get excited about. The main selling point here is your chance to get Android 2.2 on a budget. That's it.
But in the crowded 3.2-inch smartphone scene, it deserves a second look. There really is no cheaper way to get Android 2.2 out there right now. The way LG has left Android relatively untouched means a basic but functional experience, and it's a refreshing change compared to the overly customised manufacturer skins out there that add needless layers of complexity to the user experience.
Final thought:
Aside from the Android OS 2.2, it seems this phone doesn't have much going for it. And from what I've seen with the actual OS the difference between 2.1 and 2.2 is very minor. The other point of difference is the price. Unfortunatly, the others here are all the same price or cheaper.

In conclusion:
I'm heading down to the store to have a look at options 2 and 3, Samsung Galaxy 580 and Sony Ericsson X10 Mini Pro. Will edit this when I get back.

Went down to the shop. Asked Vodafone, DSE and the warehouse to test some working models of the Galaxy 580 and the X10 Mini Pro. No-one had any, although at every store the assistants had one of their own Galaxys. They all gave amazing reviews and said from what they have tried the X10 is terrible. So I got the Galaxy 580. Also found an even better deal at The Warehouse. Bonus.

Any and all comments welcome.
And if I do get to have a go with any of the others I'll update this accordingly.

Sunday, 26 December 2010


So I found this awesome Robot class in Java that allows you to easily tell the computer where to click or what buttons to press on the keyboard etc. Sounds awesome right? I thought so. At the time I played a lot of games over at If anyone is familiar with LetterBlox, it's basically boggle. They give you some letters and from those letters you have to create words. Words are worth some value of points depending on rarity and size. The highest points win.

tl;dr Plays letterblox for you.

This is part of the miGamer package I am working on. As we were having tournaments at university for who can play this game the best, and because it is easier, I went with another GIUless application. For this to work you must edit the code. As I am doing software engineering, having Eclipse open in the background was the norm. This allowed me to edit and run my program quickly and easily.

  1. To prevent an outright win, I have not perfected the program. That is it won't do every single combination.
  2. Due to computer system restrictions and to prevent overloading the site, at most 10 combinations are attempted in a second.
  3. To use the application you must change the char[] letters = {'F', 'A', 'D', 'R', 'T', 'S'}; to the letters produced for each round.
  4. The application has a short delay before it starts to type the 'words' in. During this delay you should alt-Tab back to the game and click on the game. Otherwise you will see text typed into whatever is currently open.
  5. Due to the game being clever I have allowed the application to attempt typing multiples of the same letter, even if there is only one. This will simply leave off the last occurrences. This causes some of the problems with missing some words, see note 1 for why this has not been fixed.
  6. Again to due problems with typing when the game is over, this once caused my account to be disabled and ip suspended on the site, the application terminates after 60 seconds regardless of how far it has actually gotten to all attempts.
  7. A suggestion I have had is rather than typing hundreds of incorrect or repeated answers, is to store a dictionary of words and use a look up to see if the word exists before typing. This, however, would cause the program to run a lot slower and finding the same dictionary used by the game would also be very difficult.
  8. Again this code uses very little object oriented design ans so had I known how to do this in C, I would have.
The solution is in no way a perfect solution to the play the game. Although while using the application I have not lost a single match and so I believe it to be effective enough for the purpose it is built.


import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;

public class LetterBloxHack extends Robot implements ActionListener{
 // The timer allows a combination to be created every .1 seconds
 private final Timer TIMER;
 // The counter allows the timer to be stopped after 1 minute
 private long counter = 0;
 // An array of the letters
 private int[] LETTERS;
 // An array of the order of the letters
 private int[] press;
 // The current length of word
 private int size = 1;

  * Creates the LetterBloxHack object and begins after .5 seconds
  * @param letters the letters to be sorted
  * @throws AWTException
  * @throws InterruptedException
 private LetterBloxHack(char[] letters) throws AWTException, InterruptedException {
  // Sets the timer with a 50 millisecond delay
  TIMER = new Timer(0, this);
  // Initialises the LETTERS field
  this.LETTERS = new int[letters.length];
  for (int i = 0; i < letters.length; i++){
   this.LETTERS[i] = letters[i];
  // Initialises the press field
  press = new int[letters.length];
  for (int i : press){
   i = 0;
  // Short pause
  // Begins the timer

  * Starts the program.
  * The letters to be sorted are inputed here by the user.
  * @param args
  * @throws AWTException
  * @throws InterruptedException
 public static void main(String[] args) throws AWTException, InterruptedException {
  char[] letters = {'F', 'A', 'D', 'R', 'T', 'S'};
  LetterBloxHack hack = new LetterBloxHack(letters);
  * Performs a sort every .1 seconds
 public void actionPerformed(ActionEvent arg0) {
  // Increments the counter to stop after 1800 computations
  if (counter > 1800){

  // Increment the first pointer

   for (int i = 0; i < size; i++){
    // Checks if a pointer is above the maximum
    if (press[i] >= LETTERS.length){
     press[i] = 0;
     press[i + 1]++;
     if (size == (i + 1)){
      size = (i + 2);
      for (int j = 0; j < size; j++){
       press[j] = 0;

   //  Types the characters
   for (int i = 0; i < size; i++){
   //  Types an enter
  } catch (ArrayIndexOutOfBoundsException e){
   //  Catches an exception that will represent the end of the sorting


Friday, 24 December 2010

What do you want?

This blog is supposed to be a random set of my personal programming experiences.
But, you guys are important too.
If anyone needs any advice, help with a program, or a simple program written for them; let me know here.

Also tips or tricks are greatly appreciated.
I'm in no way amazing at programming.
Having a goal to work towards is the best incentive to get things done.
I'm very confident with Java and Python, and have experience with Bash, C, MatLab and Visual Basic.
No idea about networking at the moment though; that's a plan in progress.

I'll be sure to give credit when credit is due as well.


Wiki-Hop Blog: Six Degrees

Wiki-Hop Blog: Six Degrees: "Welcome! The purpose of Wiki-Hop is to search for connections between people on Search results ..."

Found this today. Would make playing 6 degrees to Hitler so much easier.

Thursday, 23 December 2010

Christmas Computer

So Christmas is coming up, and what better gift to receive then a new computer. Well I'm quite poor so rather then buying a new computer to give away, my mum decided we should format one of the old computers she has lying around. After all, they would only use the computer for the internet and Word.

Issue 0:
Find a screen that works, keyboard and mouse.

Issue 1:
Current OS Windows Vista Enterprise has expired. Enter product key. Cannot access command line, or anything helpful from here. Nothing helpful in the BIOS either. Must find a way to format the drive.
Attempt 0:
Luckily we had an old Windows XP Professional disk lying around. Put that in, goes half through through the install process and then decides it can't read the disk.
Due to the current OS being a later version it appears that the 'upgrade' is unable to go through. Error message only says please insert disk. Hmmm...
Attempt 1:
Luckily we also had a Windows 7 upgrade. Unfortunately the computer doesn't meet the system requirements. Which seem to be a huge step up from Vista. Not too surprising. The main reason people didn't like Vista was because their computers were good enough to run it properly. Somehow, this disk allowed us to get to the command line. Strange but we'll go with it.
SOLVED got to command line.

Issue 2:
Turns out the 20Gb harddrive is partitioned into 2 parts. Not helpful. I only want one clear partition.
Part 0:
Format C:, then format D:. That worked fine. Now finding some way to get rid of the partition.
Part 1:
Found a command DiskPart. Within this you are able to view each harddrive and the partitions etc.

>list drive
'all drives are listed'
>select drive 0
>list partition
'all partitions listed, the C: of 8Gb (partition 0) and D: of 10Gb (partition 1).'
>select partition 1
'partition 1 selected'
>delete partition
>list partition
'now only the C: drive is shown of 8Gb. Where did my 10Gb go? Oh crap.'
--Restart computer.--
>select drive 0
>list partition
'C: (partition 0) is now 18Gb. Phew...'


DiskPart also has a clean command that zeroes the entire disk. I'll remember this.

Issue 3:
Now we need an OS to put on it.
Attempt 0:
Try that Windows XP disk again.
No luck. Must be a disk error.
Attempt 1:
Download Ubuntu 10.10.
Burn iso image to CD-RW using Windows 7 image burner. Very handy.
Boot from CD.

No init found. Try passing init= bootarg.

BusyBox v1.15.3 (Ubuntu 1:1.15.3-1ubuntu5) built-in shell (ash)
Enter 'help for a list of built-in commands.

Now I'm in a bash command line.
After spending an hour on two on google searching this problem, I've found two solutions.
Unfortunately both of these require booting from disk and using bash from there.
As my problem is the disk command line, this isn't going to help. A lot of basic commands aren't found; sudo being one of them. This leaves me with very few options.
Attempt 2:
Download Ubuntu 9.04.
Burn image to disk.
Boot from disk.
Change some setting and clicked install.
Ubuntu is now formatting your harddrive... Well that's convenient.
SOLVED as an added bonus, Ubuntu comes with Open Writer. Sweet.

[Last edit: 201012231820]

Wednesday, 22 December 2010


University requires we keep some form of log book. Physical or virtual. As I am doing software a virtual one sounded good. Now, I'm not rich so I use Open Office. Compatibility and laziness meant I didn't want to use any word editting software like Microsoft Word or Open Writer. Using notepad is also pretty lame. Now I don't need to know all the crap I had written in earlier; don't need to correct spelling mistakes; CLI is fine; all I need is a time stamp with each post. Didn't want an online thing, like this blog, incase I couldn't get online when I needed it. So I decided to create my own note taking program.

tl;dr Need a program to take notes and timestamp.

Decided to go with Java for this one. Just because I was using it at the time. This would probably be much better had it been written in C or something equiv. Since there is no need for high performance the language speed is irrelevent. I went with a basic CLI interface that logs each 'post' with a timestamp on an enter key press. Having seen a friend make a similar GUI version and struggle with clicking a button for each post, he was trying to include multiline posts, it seemed the CLI was a good plan. The posts are only timestamped if the times differ by more than a minute. This will probably be increased later on as up to the minute is a bit over the top for recording information in this case.


import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;
 * @author Michael Standen
 * Saves my notes, with appropriate time stamp.
public class MiNote {

  * @param args
  * @throws IOException
 public static void main(String[] args) throws IOException {
  // Initialise things.
  Scanner scanner = new Scanner(;
  System.out.println("Please enter the path of the notes file:");
  File notes = new File(scanner.nextLine());
  // Checks file exists.
  while (!notes.exists()){
   System.out.println("File does not exist. Create new? Y/N");
   if (scanner.nextLine().equalsIgnoreCase("y")){
    // Creates a new file with the name provided.
    if (!notes.createNewFile()){
     // Error in creation, get new file name.
     System.out.println("Error in file creation. Please enter new file path:");
     notes = new File(scanner.nextLine());
    } else {
     new BufferedWriter(new FileWriter(notes, true)).append("Created " +
       new SimpleDateFormat("(d MMM yyyy 'at' HH:mm z)").format(new Date())
       + '\n').close();
   } else {
    System.out.print("Please enter the path of the notes file:");
    notes = new File(scanner.nextLine());
  // Success. Outputs the current date.
  System.out.println("Success. The current time is: " +
    new SimpleDateFormat("(d MMM yyyy 'at' HH:mm z)" + '\n').format(new Date()));
  // Write the opening date and time.
  new BufferedWriter(new FileWriter(notes, true)).append("" + '\n' + "Opened " +
    new SimpleDateFormat("(d MMM yyyy 'at' HH:mm z)" +
      '\n').format(new Date())).close();

   String line = scanner.nextLine();
   if (line.equalsIgnoreCase("q")){
    // Quits the program.
   } else if (line.equalsIgnoreCase("r")){
    // Outputs the entire file.
   } else {
    writeNotes(notes, line);
  * Appends the note to the file and adds appropriate time and date stamp.
  * @param notes the file to be writen to.
  * @param line the String to be added.
  * @throws IOException
 private static void writeNotes(File notes, String line) throws IOException{
  // Make the file writable.
  // Create the file writer.
  BufferedWriter writer = new BufferedWriter(new FileWriter(notes, true));
  // Create date variables to see if time stamp is applicable.
  Calendar now = Calendar.getInstance();
  now.setTime(new Date());
  Calendar edit = Calendar.getInstance();
  edit.setTime(new Date(notes.lastModified()));
  // Create formatter for the time stamp
  SimpleDateFormat formatter;
  // Appends the date if it is different then the last edited date.
  if (now.get(Calendar.DAY_OF_MONTH) != edit.get(Calendar.DAY_OF_MONTH)){
   formatter = new SimpleDateFormat("(d MMM yyyy 'at' HH:mm z)");
   writer.append("" + '\n' + formatter.format(new Date()) + ": " + '\n');
  } else if (now.get(Calendar.HOUR_OF_DAY) != edit.get(Calendar.HOUR_OF_DAY) ||
    now.get(Calendar.MINUTE) != edit.get(Calendar.MINUTE)){
   formatter = new SimpleDateFormat("(HH:mm z)");
   writer.append("" + '\n' + formatter.format(new Date()) + ": " + '\n');
  writer.append(line + '\n');
  * Reads the file and prints the standard output.
  * @param notes the file to be read.
  * @return false if unable to read, true otherwise.
  * @throws FileNotFoundException
 private static void readNotes(File notes) throws FileNotFoundException {
  // Outputs the file.
  Scanner scanner = new Scanner(notes);

CLI programming is cool. If someone has no idea what's going on, they will be impressed. Also comments are important. Remember that.


Problem: At my work it was decided that we were to do mail drops. Rather than leaving the office and walking around the local area, we hit up local real estates offices etc and found all the addresses of houses for sale, our target audience. As it happened the real estate people were not helpful, there websites were. More helpful then these was the TradeMe website. As it turned out most of the real estate agents also listed the houses for sale on there anyway.
For a while it was my job to go through every listing and put them into a spreadsheet for some processing. After a day of this I thought it would be easier to write a web crawler to do it all for me.

tl;dr We need to get all the addresses off TradeMe, that are local and recent.

Having recently done Python at university, I decided to use that. As all I wanted was a CLI program that I could implement quickly, it seemed to be a good fit. The program searches the list of listings for the listing number and then searches each listing for the address. If it has one, it is appended to a txt file. This file can then be added to a spreadsheet using imports.
Credit must go to a couple of places for this:
daniweb is a great source for help, although I can't stand the website. Found it tricky to navigate. Google helped with that.


#!C:/Program Files/Python/Python 2.7
import urllib, time
print "miCrawler version 0.1"
f = open('addressFile.txt', 'a')
# The below URL is the houses for sale in the manukau area, in list view, sorted by most recent, page 1
# May need to be updated occassionally.
tmManukau1 = ''
tmManukau2 = '&sort_order=expiry_desc'
for i in range(0, 60):
    tmManukau = tmManukau1 + str(i) + tmManukau2
    page = urllib.urlopen(tmManukau).read()
    # Note that line 637 is the first occurance of a url for a particular listing.
    # The 9 digits following this string will represent a listing.
    auctionString = '/Trade-me-property/Residential-property/Houses-for-sale/auction-'
    pos = 1
    pos = page.find(auctionString)
    # Loops through this process until there are no more valid links on the page.
    while (pos != -1):
        # This will build a string for the URL of the listing found.
        listingURL = '' + page[pos : pos + 77]
        listing = urllib.urlopen(listingURL).read()
        # Gets the address from the listing, the 26 skips the <td> and spaces.
        addSPos = listing.find('<td>', listing.find('Location:')) + 26
        addEPos = listing.find('</td>', addSPos)
        address = listing[addSPos : addEPos]
            address = address.replace('<br />', '\t')
            print (address + '\n')
            f.write(address + '\n')
        except ValueError:
            print (address + 'HAS NO NUMBER \n')
            # Each address occurs twice, skip the second.
            pos = page.find(auctionString, page.find(auctionString, pos + 78) + 78)

This is very specific. It only searches Manukau and surrounding areas. Small changes on the urls will need to be made for that to change. The range in the loop determines which pages are to be read. Also I have no idea what that mcat number is and may need to be updated.
I suppose the main key here is this line:

 listing = urllib.urlopen(listingURL).read()

'listing' now contains the entire html code for the page. Performing some search functions on here for the auction numbers allows the program to find the relevent listing and from that page find the address. Simple enough.
The random hard coded numbers are there due to formatting. Easiest way I could think of to get around it. So that's that one. Never used all the 1,180 addresses. Kept the boss off my back for a while though.


So I've made a couple random programs. They work. Not well, and they don't look great, but they do what they are supposed to. I have a theme going where every program is prefixed with mi. Yes like Apple.

I will be releasing the code from most of my small projects, for two reasons:
Firstly, it may help someone else out there with something. I know from experience that having some example code to deconstruct helps me understand things.
Secondly, if I lose it, it will be here. Storing everything on a tiny usb is never a good idea.

Any comments, questions or suggestions are always welcome.


Tuesday, 21 December 2010

About Me

So this should probably be in here some where.

My names Michael, or Milk. I'm 19. Studying at the University of Auckland, for an Engineering Degree specialising in software. My spelling isn't great. I have a beautiful daughter, and lovely girlfriend.

Don't really do to much. Like playing Halo alot. That's always good fun. /b/ is also another of my weaknesses. So is not finishing my own projects. Once I have a semi-working prototype I'm usually happy to stop. Most of the time there is no point to my project except to prove to myself that I can do it.

Have a part time job working for Guardian Storage Ltd. It's a job. And yeah.

That's all I can think of at the moment.


First Post

Yeah so many people have told me I should start a blog. OK well that's a lie. Lectures have said I should have a logbook, and I've always thought I should have a blog. So here it is.

Not sure what's going up here or how long this is going to last. Hopefully this will give me some motivation to finish some of my projects I have going, and the spell correctly.