Thursday, 6 October 2011

Risk, It's All About The Magic, Shazam

Just my thought of the day after playing Risk with a group of friends in a board game extravaganza of an evening. What really are the odds to consider when attacking someone? Well, in any given 1 on 1 there are 36 combinations that can be rolled e.g. one die for each player. This results in a win percentage for the defender an average 58.3% of the time with a remaining 41.7% chance of a win for the aggressor.

So when considering that 15 out of 36 attempts by the attacker will be successful and 21 will be won by the defender we need to balance the odds. To get to our magic 50% we need 18 of our 36 rolls to be winners! Thus we need 3 more rolls than we are currently achieving, 3/15 gives us the extra number of rolls we require to win, a nice 0.2 which means I need 1.2 dice to be on equal terms with the defender.

Aha "you can't have 0.2 of a dice" I hear you say, which sadly is true so all in all I've wasted 2 minutes typing this up! Stick to the rule of two to one when attacking and you'll be dandy although the above doesn't account for SOD's law which appears to apply to me in this game more than anyone else. Damn you Mike-"Genghis"-Croft!

Monday, 5 September 2011

Love Money Management Even For Nationwide

Two blog posts in one day! You might be thinking what the heck?!?

Love Money have just released an online service to budget and manage your finances. Due to the nightmare that is the IFA in the UK automation for these kind of services is pretty terrible but they have somehow done it. Genius! I can now even connect to my Nationwide account without having to upload OFX's, CSV's and the like.

It really is looking promising, make sure you give this find of the day a go!

GWT Dialog Box With Close Button

Due to the internals of the GWT Dialog Box, extending it to add support for a close button can be a little tricky if you dont understand what your looking for. Alas below demonstrates adding an anchor to the caption area of the dialog, all that's left to do is for you to style the anchor. Happy GWT'ing.

Some people will moan that adding a library such as Smart GWT will add this functionality. Whilst true it also adds a boat load of library code you may never need. Keep compile times short and sweet and use the minimum amount necessary.

// Create anchor we want to accept click events
final Anchor myAnchor = new Anchor("My Anchor");

// Add handler to anchor
myAnchor.addClickHandler(new ClickHandler() {
  public void onClick(ClickEvent event) {
    Window.alert("Anchor was clicked");

// Create dialog
final DialogBox myDialog = new DialogBox();
myDialog.setText("My Dialog");

// Get caption element
final HTML caption = ((HTML)myDialog.getCaption());

// Add anchor to caption

// Add click handler to caption
caption.addClickHandler(new ClickHandler() {
  public void onClick(ClickEvent event) {
    // Get x,y caption click relative to the anchor
    final int x = event.getRelativeX(myAnchor.getElement());
    final int y = event.getRelativeY(myAnchor.getElement());

    // Check click was within bounds of anchor
    if(x >= 0 && y >= 0 && 
      x <= myAnchor.getOffsetWidth() && 
      y <= myAnchor.getOffsetHeight()) {
        // Raise event on anchor

// Show the dialog;