NSPredicates – SUBQuery on a parent-child relationship

I am currently working on a game where there is a parent-child relationship in a quite small array where;

A `Group` (parent)
has many `Child` objects
where 1 `Child` object can be owned by only 1 `Player`
and a `Player` can only ever own 1 `Child` per group

In the game, a `Child` object is called `Locomotive` (the game is about selling Locomotives) and a given `Player` can own a single locomotive in a given group.

I needed a way to grab all the child objects in a given array that met a series of conditions; in short, I’m after a list of child objects that I can `legally` purchase.

By `legally` I mean from the following rules (in no particular order)

  • I want to remove all children where I do not own anything
  • I want to remove all children which I already own a locomotive
  • I want to remove all children where I don’t have enough money to buy it
  • I want to remove all children by inspecting the group to only show those children where the sum total of orders > 0
  • I want to remove all children where something has been bought already

Phew, quite a lot of conditions. At first I was not sure how to solve so many conditions.

My first solution was to use a NSPredicate… with a block statement and simply loop through everything.

Code:

    NSPredicate *predicate = [NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
        EngYard_LocomotiveGroup *group = evaluatedObject;
        for (EngYard_Locomotive *child in group.locomotives) {
            if ( ([child.purchased boolValue] == NO) && (child.owner != player) && (group.purchasePrice < player.cash) && (group.initialOrders>0 || [group.totalOrders integerValue]>0 || group.unlocked==YES) )
            {
                return YES;
                break;
            }
            return NO;
            break;
        }
        return NO;
    }];

This seemed quite a lot of code. Surely there is an easier way to do this?

SUBQUERY to the rescue!

Having played around with the SUBQUERY for a while, I finally got a single-line solution;

Code:

    
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SUBQUERY(locomotives, $rv, $rv.purchased = %@).@count > 0 AND (purchasePrice < %d) AND (initialOrders>0 OR orders.@sum.integerValue>0 OR unlocked==YES)", @NO, player.cash];

I double checked both instances in my logger; and they both return my expected results.

Now on to more complex matters — how to make the AI make a decision to buy.

Startup Britain – Pitching to Chillingo

logo

On Monday 14 October I was in London as finalist to pitch a game to the Chillingo team as part of the week long Tech4Startup Britain event being held in Canary Wharf.

The Chillingo Team were:

  • Matt Dixon, Sales & Business Development Director, Chillingo
  • Andy Needham, Head of Production, Chillingo
  • Daniel Tausney Public Relations, Chillingo.

IMG_0267

As a finalist, I was pitching my cocos2d game, “Bootleggers of America” to Chillingo; perhaps the UK’s biggest iOS games publihser; it was an incredibly once-in-a-lifetime occasion to be pitching to a fantastic games publisher amongst such a fantastic and diverse crowd.

IMG_0262

About the game

The game I was pitching was “Bootleggers of America“, a Prohibition-era pick-up and deliver economic game that is similar to the old space trading games of the 80s, or if Drug Wars of the early 1990s, except the twist in my game is that you are responsible for producing your own goods, picking your own goons and making much deeper decisions beyond buying low and selling high.

The game takes ideas from the PC-game, “Gangsters:Organized Crime”, and other mafia trading games to create a fictional world where you play as a Mafia don of your own crime family with the idea to make as much money from Speakeasies and Illegal bootlegging operations during the Prohibition-era.

Although the consensus from the mobile app experts was that mobile players want to “dip in and dip out”, and that long-haul strategy games do not work well on mobile; I have seen a few games that have proven that they will work for a specific niche of players.

My game plays is aimed to this niche and is a premium, solitaire, long-haul strategy game designed to play on the train, I felt that with games like “Transport Tycoon” recently being released on iPad that the idea that premium long-haul strategy games for iPhone, iPad can work.

With this in mind, I felt that Chillingo could help get it published and help prove that the market isn’t about 15-second games.

My pitch to Chillingo

My pitch was about getting their help to turn the game from what it is now, and turn it into an isometric city with Game Center integration and allow you to play against other players; of course this would require servers, and a large scale technology support that only Chillingo or other games publishers could provide.

This would mean, helping out with new art work and giving help on the technical level to provide the game servers similar to the other games they currently publish.

Post-Pitch advise

Rightly, Chillingo felt the game didn’t seem innovative or brough anything “new” to the table; plus they could not help with the technical challenge of delivering content via servers, websites, etc; and advised me to look at the game again and try to deliver such a product myself.

The future for Bootleggers

Right now, I feel the game needs to be refreshed with an Isometic city, and integration with Game Center and the ability to play against other players.

In order to do this, I’m going to need raise funds from something like Kickstarter or IndieGoGo.

When this will happen, I’m not sure; there are a few things in flux — but releasing a premium game that caters to the fans of long-haul strategy games, the mafia theme and “Gangsters:Organized Crime” into a strategy game that people will enjoy.

Other pictures I took;

IMG_0264

10 reasons your business needs to go mobile, today

There can be little doubt that mobile is crushing it for small businesses’ in local search. Increasingly, customers are using mobile smartphones to browse, surf, search and buy products and find services.

And yet, many business still aren’t using mobile marketing effectively for their business; or understand the reasons why.

So let’s go through 10 of the most popular reasons why your businesses needs to consider going mobile.

1. The growth of mobile-internet searches is increasing, and un-deniable

Searches via smart phones and tablets for local businesses like yours is one of the fastest-growing mobile activities.

Mobile Internet searches have grown by 500% over the past two years and companies like Google, Yahoo! and Mozilla and taking this trend very seriously and are leading the charge as they’ve seen the growth of searches mean that they must offer services to these smart, savvy customers.

The problem for your business is that if your website was designed for the “Internet” then mobile users are being cut out, they cannot find the information they want, they find the websites take too long to load; and most likely they’ll stop using your website and go to your competitor.

That’s money on the table!

The solution is simple, a mobile website that caters to these leads and grow the number of potential customers you have.

2. 50% of all mobile searches are local

When people look for services or businesses, they invariably search for local businesses, products and services; this number increases if they are on a mobile device.

Indeed, local mobile searches are projected to exceed desktop searches for the first time in 2015 more and currently more than 1/3 of all Internet searches performed on mobile devices are for “local” products and services. In a nutshell, this means that these consumers are searching for YOUR businesses.

local-search-graph

The above graph shows the increased usage of mobile devices like smartphones are used in local searches in the US, and the numbers are the UK are not only following this trajectory, they are growing.

3. 61% of users call a business after finding them on their smart phone

Customers who use a mobile smartphone to searching for a local business are hungry, and ready to take immediate action; they are hot, ready-to-spend customers. Just many customers are you losing because your website is not mobile friendly?

4. 59% of users visit a business after finding them on their smartphone

In the world of the Internet, conversions matter; and its been proven through research by Google, and others that consumers that search for a local business via mobile are more likely to visit a business having found them on a smartphone.

This is real, serious money.

5. 71% Smartphone users that see adverts for a local business will do a mobile search

When consumers see TV, printed or other adverts; the numbers show a high percentage of people will search for the business via their smartphone.

6. 45% of mobile users are between 18 and 29 and use mobile search daily

The numbers of young, hip urbanites using mobile smartphones to search for your business is increasing, that means you need to cater to them or risk losing them to the competition.

7. 53% of shoppers compare in-store prices to online prices while shopping.

It’s true. Even Google admits this. A high percentage of shoppers shop around both in physical shops and virtual e-commerce shops on their smartphone devices for the best price and the best deal.

They want to make snap buying decisions and find the information they want quickly and easily. If they can’t, it’s likely they’ll not use your services.


The numbers don’t lie. Mobile is here and your business needs to go mobile. Today.

Sources:

Sources:
* Google – Understanding Mobile Marketing
* Emarketeer
* Mobithinking
* MobileMarketing MAgazine

New theme launched and a new direction

A new theme has been launched for this website. We’re looking on-wards and upwards.

For the past few months I have been working on a few iPhone (iOS) apps and am looking forward to working on some more going forward.

In addition, the importance of mobile marketing and mobile ready websites is something that is increasingly becoming prevalent and important not just for small businesses but for startups and even well established ones.

This mark a new direction for this website.

Website changes

I am in the process of changing my website. There is a bit of confusion as the website has a logo and has a confusion about what it actually is meant to be; is it a personal website, blog — or, alternatively is it a brand name, a company, or a holding name for something else?

For the past four or five years the website has been both a personal website, and a “brand” or “company” and both expressing ideas and concepts I thought were interesting; and selling professional services.

I’ve always been torn about whether the website could do both at the same time, it is my expectation to turn it into a personal site; however I have thought seriously about selling up and moving on to something else — but this is not something I can decide without a lot of fore-thought.

It is my intention to focus back on exploring ideas for the time being.

The Trump Doctrine: Donald Trump and the United States of Talking Points

Donald Trump’s current “will he, or won’t he” campaign for the upcoming 2010 United States Presidential election has many people wondering whether this time he will actually run for office.

Assuming he does run, you can bet money that he will use the “Obama, You’re fired!” line at the debates. There’s no doubt the placards will cover that line, and he’ll use that as his strap-line for his election campaign.

However, many political commentators and astute Reddit readers have pointed out that Trump has a habit of running “will he, or won’t he” campaigns in the recent past. Indeed, this will be his third such run.

For many though, this is just another Trump PR exercise, a rating’s push for his TV show, “The Apprentice” (United States version).

There is no doubt that Trump is an astute businessman with keen show-man like qualities that help promote the Trump brand. However, watching the various interviews of Trump on the Internet, I cannot help thinking that Trump is not politically astute enough to be President of the United States.

Continue reading