Wednesday, October 30, 2013

Match 3 Game algorithm Part 2 - How to detect there is a match?

With the game element terminology, we are ready to jump into the core of the game - Matches detection. It is the most fundamental yet critical puzzle.

So, the question: Provided a matrix of 8x8 consisting of random items, how to detect if there is a match?

And here comes the 1st statement (from androidgamify blogspot :) )
Statement 1:
- Every match (vertical or horizontal) is detected at the node located at the smallest nth of tile.

What does that mean?

For example, the picture below shows a matrix with a number of matches. (Assume that you design your match-3 game in such a way that there could be matches at the initial stage)

From the observation, there is a horizontal match of the green nodes located at the tile 8th, 9th and 10th, and a vertical match of the blue nodes located at the tile 35th, 43th, 51th. (Just focus on these two first).

Based on the statement, while scanning the matrix nodes 1 by 1, the green match has to be detected at the 8th, while the blue match is to be detected at the 35th. With this systematic checking, we can effectively avoid redundancy.

Hence, generally speaking we can deduce the matching algorithm as below:
To detect the vertical matching, we only need to scan the nodes which are from the row 0th to 5th.

And to detect the horizontal matching, the nodes to be scanned are from the column 0th to 5th.

These make sense, considering the fact that only at the green nodes we are able to detect the matching of the specified orientation.

Here's the pseudo-code:
a) Vertical matching
- foreach node nth
  if it is at more than 5th row, skip
  else check if nth equal to (n+8)th, (n+2*8)th, (n+3*8)th, (n+4*8)th to determine how many nodes in  the matching.

b) Horizontal matching
- foreach node nth
  if it is at more than 5th column, skip
  else check if nth equal to (n+1)th, (n+2)th, (n+3)th, (n+4)th to determine how many nodes in  the matching.

Coming up next: How to detect if there is no more match?

Sunday, October 27, 2013

Match 3 Game algorithm Part 1 - Game elements terminology and analogy

Generally, a Match 3 Game consists of a matrix of nodes with the dimension M x N. Here i prefer a square one (M x M), specifically 8 x 8.

a) Tile: The location at which the 'node' resides. In a matrix of M x M, each tile is representable by a number from 0 to (M x M - 1), at ith row and jth column.
b) Node: The item of the matching. In the Candy Crush Saga, it is analogous to the candy.
c) Matches: The matching of 3 to 5 nodes, could be horizontal or vertical, but not diagonal.

* To conveniently setup the Match 3 Game, I use colors as the type to differentiate the nodes. Similar to the tile number, i will start counting my row and column from 0 to (M-1).

For example, the picture shows a matrix of 8 x 8 - consisting of 64 tiles.
 The crossed tile:
a) resides at 1st row, 1st column. OR
b) belongs to the 9th tile.

Apart from that, there are a number of matches observed. For example, a matches of 5 blue squares at 33th, 34th, 35th, 36th, 37th tiles.

Coming up next: How to detect a match?

Friday, October 25, 2013

How to create a match 3 Android Game like Candy Crush Saga?

As mentioned before, the Candy Crush Saga, with the basic concept of the Match 3 game, stands out to be an extraordinarily successful game.

Then, instinctively, you will ask yourselves, "Can I become similarly successful if i make another Match 3 game?" And the most importantly, what is the basic algorithm behind the Match 3 game that powers the Candy Crush Saga? By understanding and constructing those skeletons, you may design your own attractive graphics, sound effects, and animations to package your game.

To your delight, for the next couple of blog posts, the contents will touch about the algorithm of the Match 3 game. Curiosity makes me learn to create this kind of game as well :) . After some research from the search engines, I came out with my own solution (ok, + reference) which I wish you can find it useful for your basic understanding.

No fuzzy codes. It is mainly about the algorithm, with intuitive picture description and lines of pseudo-code.

To summarize, I break down the Match 3 Game algorithm into several parts:

a) Match 3 Game algorithm Part 1 - Game elements terminology and analogy

- A quick understanding of how I define the game elements. It will help a lot before you read the others.

b) Match 3 Game algorithm Part 2 - How to detect if there is a match?

- Basically it is the core part of the game. No third-party framework or library. Everything is from scratch.

c) Match 3 Game algorithm Part 3 - How to determine whether there is no more match?

- An important checking to see whether the game can proceed or not.

d) Match 3 Game algorithm Part 4 - How to enable the user interaction?

- There are a number of approaches. Here I simply use the index difference, with an exception handling.

e) Match 3 Game algorithm Part 5 - Miscellaneous (Special Combinations)

- Include some interesting parts which make the game more impressive and fun.

f) Match 3 Game algorithm Part 6 - A real Android Match 3 Game demo

- The whole tutorial is not convincing without a real game demo. However, the graphics are not emphasized. Yay! It is now in the Google Play Store - Match 3 Pop Saga

Kindly drop a feedback if you find any typo.

Tuesday, October 22, 2013

Gentle reminder: This is truly an original and a useful blog

"To err is human, to forgive divine".
Wait, what if the culprit is a robot? or precisely, the blog crawlers?

Last Sunday night, on a routine surfing of my "Android Gamify" blogspot to plan which topic should come next, all of a sudden, i was returned with a horrifying message:

"Blog has been removed"

Flabbergasted, my mind turned blank for seconds before gaining consciousness.

"What?" "Why?"

These are the questions flashing through my mind. Immediately, i logged into my email, realizing that my blogspot has been marked as "SPAM" by the automation system.

This is hilarious. The blog is my personal diary of my Android Games development. Every single article is originally written and proofread. How does the system define it as "SPAM"?

Without a second thought, I made an appeal, while praying everything will be restored. Unlike other services, blogger doesn't offer a Live chat. I really wished to have an immediate face to face session arguing, discussing, clarifying, convincing, or whatever action to recover my posts. That night, was a completely sleepless night...

On the next day, i kept checking emails and entering the blog again. Only in the afternoon I found that the entire blog site has been restored. And the blogger staff admitted that it was a MISTAKE.

Heaving a sigh of relief, I told myself that, to prevent such a disaster in the future, it is so crucial for us to consistently "backup" our posts (which is actually a feature available  in the blogger). I almost lost the motivation to continue blogging, until i found that it came alive again.

And i hope you can learn from this lesson as well.

Sunday, October 20, 2013

How to save data/records of the Android Games in Adobe AIR AS3?

Throughout the game play (either Android Game or others), the player's record is important to be always updated in order to let him/her continue the previous checkpoint. From the complicated RPG Games (levels, equipments, cash left, etc) to the simple mini games (high score, number of attempts, number of stages unlocked), records are necessary so that the players need not start all over again every time they engage the game.

In fact, the feature of saving data/records of the Android Games in Java is available here. The question is, how to implement the same thing in Actionscript 3?

1. import
The code which is similar to the SharedPreferences in Java is the "SharedObject". To use it, you need to import the flash library.


2. Define a SharedObject variable and a Record name
Define a variable named "shared" at which the records would be stored. You can provide any "RECORD_NAME" to create a shared object.

private var shared:SharedObject = SharedObject.getLocal("YOUR_RECORD_NAME");

 3. Define your data in Object datatype and store it inside the 'data'

The "data" member of the SharedObject is nothing different from the datatype "Object" - an associative array. You can easily define your records in "Object" datatype before storing it.

For example, to store the levels, hit points, mana point of a character, the codes would be as below: = {"level":5, "hit_point":100, "mana_point":100"};
In short, it isn't hard to have a data saving feature in your Android Game. So, next time when designing the game architecture, remember to have this feature included.

Saturday, October 19, 2013

How to solve "unsupported sampling/frequency" of audio files in AS3 (Starling Framework)?

As mentioned in the previous post, it is pretty straightforward to load audio/sound files in Starling Framework. But the thing is, it is annoying to learn that the adobe Flash Builder only allows to import the audio files that are recorded in the multiple of 11kHz (11kHz, 22kHz, 44kHz). And if it is not, you will get the error similar to the message below:

- Internal error in outgoing dependency subsystem, when generating code for ... : java.lang.NullPointerException
- The frequency 0 is not supported in file....

So, how to solve this "unsupported sampling/frequency" issue? (we are not sound engineers right?)

Solution: Manually down-sample/up-sample the audio/sound files

At the moment, I suggest using a third-party audio editor software, such as GoldWave to manually edit the sampling rate of your audio/sound files. (I personally hope that someone would make a browser-based version of that functionality)

To use the GoldWave, you could simply open your audio/sound files with it, and "Save as" a file in the "mp3" format, choosing any option which is in the multiple of the 11kHz frequency. (Here, i pick Layer-3 (LAME), 44100 Hz, 128kpbs, stereo.)

Once you have saved it, you can re-embed your audio/sound files again. :)

Wednesday, October 16, 2013

How to load audio/sound (.mp3) files with Starling Framework?

Sound effect plays an important role in any game. It stimulates the players to immerse themselves into the games. It manipulate the game paces, and the players' heart beat.

Similarly, an Android game without any background music or sound effect won't keep the players long. Hence, it is important to know how to load audio/sound files into your game, playing them at a correct timing. Here, the codes for doing it with Starling Framework will be displayed.

1. Import Flash's Sound library

It is alright to just use the Sound library from the Flash. In fact, there isn't any specific library for the sound in Starling Framework.


2.  Embed the audio/sound file

Like embedding the image files, embedding an audio/sound is similarly straightforward.

public const MOVE_SOUND:Class;

 3. Define the sound variable     

Here, note that it is necessary to use "as Sound" when defining the variable.

public var sndMove:Sound = new MOVE_SOUND() as Sound;

4. Play the audio/sound file

 With the play function, you can directly play the audio file, with customizable parameters. (specify start time, loop times, sound transform)

Wednesday, October 9, 2013

Monkey - a programming language for Games Development on multiple platform

Cool. As the title suggests, "Android Gamify", now even the name of "monkey" has been taken for the language of Games development. And it claims to target at Android, iOS, Desktop, HTML5 and XNA.

The download page of the "Monkey" presents a Demo Version (free) and a Full Version ($99 USD). Here, i would only be able to show the Demo Version. In short, the interface is pretty clean and intuitive.

The IDE of Monkey is quite fast to load. For beginners, there are a number of monkey samples available to start with. I am not that familiar with the language, but it looks like Actionscript (from the way it declares the data type).

The red rocket button is the one to build and run your project. Fast and clean.

However, the important question to ask here is that: How to build an Android apk file from this Monkey demo version? To our dismay, the demo version doesn't have the feature. I would personally be better impressed if it is included, so that I could write a little more about the Android Games Development using Monkey, precisely, Monkey programming language.

Beware of how vulnerable your Android Games (.apk files) are!

Ok. This is not a threat, nor a nonsense.

Here, I would like to emphasize on the vulnerability of the Android Games (.apk files), in order to raise the awareness of all the games developers.

Plagiarism takes place everywhere, from websites contents to the games elements, across any industry and brand. But when it comes to the Android Games, it is really sad to reveal that recently there has been cases such as the hard work pieces "Chase Burger" from Elventales Studio had been copied and published on iOS and Android Play Store under the name of Hungry Chase. When i said "copied", i mean it isn't just about the game logo or the genre, but about the duplication of the ENTIRE GAME, from images, buttons location to the character appearance. By changing only "Game Title" and editing a little bit on the color, those jerks simply claim the games as theirs.

What is even more discouraging is that, it happens not only on the famous games (which are from the well known studios). Even the indie games are not spared of. And that definitely poses a question: How on earth are those scumbags be able to reverse engineer the Android games, such that the entire games could be manipulated and re-published so easily? Why the apk files are so vulnerable?

You may argue that this scenario is inevitable, and it actually pesters the iOS game developers as well. But the thing is, as the developers who hope to earn some income for a living through the Android Games development, we are really disturbed by the hacking and stealing prone games ecosystem. And in fact, with the Google search engine (alright, is stackoverflow, etc), you can 'conveniently' get the ideas of how to intelligently reverse engineer de-compiling any Android apk file. I know that they are not to blame. But I wish the play store (such as Google Play Store) would be more vigilant and efficient when handling the apk theft.

Wish to know some demo on how an Android apk file is stolen? I won't show the whole ugly picture, but here's an example:
a) Randomly grab and download an apk file from here.
b) Rename the apk file with a ".zip" at the back
c) Extract / unzip the file

Here you go, i only partially demo how to steal the assets (pictures) of an Android apk file. It could be performed so so easily.

So what to do to enhance the security? No idea. But as observant games developers, the only thing that we can do, is to always keep an eye on the play store, filing reports whenever necessary and pray that those games thieves would be busted without affecting the reputation of your games brand.