Tuesday, August 2, 2011

First steps - Hex Chess



Large hex chess
I thought for my first project, I would make a chess game with a difference - hex squares! While there are already variants of this, it seems the popular ones use a larger board , which will be a bit harder to implement on a small touch screen (see preview).

I choose chess for the following reasons:
  • Well known, lots of source code/ideas
  • Allows for AI programming in future
  • Allows for multiplayer/server in future

My version will be a standard 8x8 board - but with hex.
The hex variation is a bit more complicated - no existing moves/openings/AI exist as far as I am aware, and the logic for piece selection is a little more complicated. It may also be not so much fun, as there are a couple of potential problems - which will be covered in another post.

First, how to setup and draw a chess board and pieces? My chosen method is to create drawables from resources (png) and draw them to the correct location, size, and order on the screen. Order is important to be able to use transparency.  To start with, I have modified the original snake game (Android samples) to use an 8x8 layout, and to setup three 'squares' to use as board tiles.

each square is currently 150x150, and contains a hex with dimensions W = 150, S = 112, H = 130 (there is approx 10 empty pixels above and below the hex centered in the square). I used this hex grid math, very helpfull!
Of course on my Android device, 150x150 is way too big, so it is automatically scaled to fit the 320x480. Each square becomes approx 48x48 pixels, and the hex inside is 48x42 for a 'flat' orientation, this works out to be a total area of around 8.5 squares x 42 in height, and 6 squares x 48 in width (360 x 288). Of course this leaves a little area on the side, and at top and bottom.

The pieces are open source from here.

each one is 100 pixels high, with up to 100 pixels width - some (e.g. pawn) are a bit smaller at about 80.


As the hex 'squares' are 48x48, the pieces are loaded in to fit in the 'center', which is approx 32x36. As can be seen from the current results, the hexs do not align perfectly, in some cases leaving a thin margin. This is either caused by a little rounding error in the height/position calculation, the hex image file, or the android downscaling engine.

For the pieces, it can be seen that the knights are not quite centered, and the pawns are 'fat'. Also the black king is showing a bit of aliasing, or similar artefacts. I plan to fix this over the next few days - all images will be placed into the same height/width, and the drawing locations double checked for any rounding errors. In addition, I may work out how to convert the images so they are more scalable for different screen resolutions.











Saturday, July 9, 2011

Development environment

One of the first issues is to get the development environment setup. The recommended IDE is Eclipse, and as I am a regular eclipse user, I will be using that. In addition, I have an Samsung Galaxy, upgraded to 1.6 to use for debugging. This will also be the current limiting factor in what API version I use, as I want to test it in person.

The best steps I have found are at this blog:

Namely:
  1. Install latest version of Java JDK (not JRE)
  2. Install latest version of Eclipse for Java (e.g. not CDT which I usually use). This is currently 3.7/Indigo
  3. Install ADT using Eclipse plugin framework - I installed R11, then a couple of days later updated to R12 when it came out.
Now the basic setup is complete, including Android code samples.

To test this, I created a new project (Snake), from a 1.6 code sample. After creating a new Virtual Android device, it worked fine.

A more difficult job was getting my phone working for debugging. I have Samsung New PC Studio (latest version) installed, however my phone was not showing up under "adb devices". This means the USB drivers are not installed. Unfortunately, there does not seem to be any Samsung drivers around. I tried turning phone USB mass storage mode on and off, turning off and on phone Debug mode, but to no effect.

After a bit of googling, I came across the following post, which describes how to do it. You have to use the Google USB drivers (normally only for google Nexus phone), and edit the inf file. Next time when the USB drivers need to be installed, manually select this folder instead.

NOTE: The folder seems to have been moved in later releases to:
C:\Program Files\Android\android-sdk\extras\google\usb_driver

After a restart, adb was showing the phone as "I7500t1ateSN device". Now when running apps in Eclipse, if the virtual Android device is not open, they automatically run on my phone. Nice! Looks like I'm good to go.

Sunday, July 3, 2011

Split personality

When I first had the idea for the name, I signed up to a couple of websites with my existing email address. After some consideration, I thought it would be better to create a specific email, goldcoinsoftware@gmail.com, until I had a chance to register domains etc, and to not use my personal account.

Unfortunately, I had already signed up for blogger as Gold Coin Software with my personal address! However, it is quite easy to change, just follow theses steps!

I was/am also trying a couple of online hosting solutions, ProjectLocker and Unfuddle. I haven't decided which one to use yet, and they both offer slightly different environments, more on that in another post.

For Unfuddle, I could add a new account, with the new gmail address, and the existing account already had goldcoinsoftware in the url. For ProjectLocker, it had actually used my personal email address, which I could change, however the url was fixed. So I will probably have to migrate ProjectLocker to a new account if I can be bothered, and Unfuddle does not work well enough.

Next step: Deciding to register a domain name or not! (and change all the email addresses again?)

What's in a name

One of the major decisions to make is what to call the 'company', as I don't want to publish everything under my own name. The main reason is, it should be easier to make it a stand alone entity if successful, or to remove if it crashes and burns!

When coming up with a name, sometimes random objects/items help, or maybe something with meaning to the product. Of course, you should check that the name is not taken, or is not suitable! After some thought and a couple of now forgotten in between names (mainly based on my name, I thought how about "Gold coin software". The reason is Android/Iphone apps are typically cheap - $1 or $2 dollars, maybe up to $5. In NZ, we use "gold" coins for $1 and $2, the probable selling point of the software if it comes to that! And of course, there is some flexibility, as real gold coins are available at almost any price! Then to check:

Gmail account available (yes)
Website available (yes)
Blogger available (yes)

Any existing companies? Not that I can find - the only ones that seem to exist are actually software for collecting coins, which I guess makes sense, but not really related.

While there appears to be a trademark for "Gold coin" , adding software should make this specific enough not to count - although I am no lawyer!

So, now just to setup the blogger, gmail etc!

Android development from scratch

I purchased an Android phone a couple of years ago, with the intention of one day writing some software for it. I had previously downloaded the SDK (http://developer.android.com/sdk/index.html) on my laptop, but some settings interfered with my existing Eclipse, and also PDANet which allows tethering for internet on the move. Now I have my second laptop setup, I thought it's time to investigate development again.

I am a professional software developer, and for me the though process of developing software is mainly language independent. While I have learnt Java, it was a long time ago (1.4!) so I will have to relearn, and also pick up some new tricks!

The first things to do:

Decide on a name
Decide on a project
Setup development environment
Setup tools