You are on page 1of 9

AI and Game Mechanics Research on

“Candy Crush Saga” Android Game


For subject: Artificial Intelligence (3161608)
By: Smil Raj Thakur | 201310132064 | ICT A4 |

Overview of the game

Candy Crush Saga is a free to play game developed by King released in 2012. It is
available on iOS, Android, and Facebook.

The game wants player to swap two adjacent candies on a game board to make a line
of three or more of the same type of candy. When three or more candies are matched,
they disappear from the game board and new candies fall into place from the top of
the board to fill the gaps.

Game has several levels; player can clear these levels by completing required
objective or clearing certain number of candies. The game constantly increases its
difficulty as level increases.

The main reason behind its growth was its colorful UI/UX combined with good
background music and addictive gameplay.

The main catch of the game is that you have 3 lives initially and on losing a level the
life decreases by one, restoration of one life takes about 30 minutes. So basically
players need to play each move carefully and if they loose all their lives they have to
wait for a considerable amount of time, this creates excitement to play the game next
time.

SMIL RAJ THAKUR 1 Dr. Kinjal Chaudhari


Basic Game Mechanics:

1) Levels

a. Time-limited levels: player need to clear the level before the time
limit provided.

b. Objective-based levels: Player need to clear specific number of


candies or score to complete the level with some constraints like
limited no of moves.

2) Matching: player need to match three or more candies of the same color
to clear them from the board.

3) Obstacle: levels have obstacles like jelly, chocolate, or blockers that


prevent players from making matches.

4) Lives system: players have a limited number of lives (3), and they lose a
life each time they fail a level.

AI implementation on basic game mechanics:

1) Level balancing: To maintain the difficulty of the level based on the


progress AI implements certain level of difficulty in the level.

2) Personalization: The AI tracks your gameplay and suggest boosters


or special ability accordingly

3) Predictive analysis: The game uses predictive analytics to analyze


player data and identify trends that can inform game updates and
improvements.

4) Level mapping: AI maps the level accordingly so that there is at least


one possible move, and the player can win if he/she plays optimally.

SMIL RAJ THAKUR 2 Dr. Kinjal Chaudhari


Constraints and pseudo-codes
For three most fundamental mechanics

Valid Match:

Condition: We need to check whether the element after the swap with
adjacent element forms a row or column of three or more elements that have
similar identity.

For example:

Here we can see that the purple candy when swapped we the blue candy forms a
row of purple candy that has length more than 3, which is a valid move.

Pseudo-code for this:

We need to maintain four variables.

Int right, left, up, down.

These variables will store the length of matching elements/candies.

From the swapped element travel:

Left and increase left count variable until the traversed element is
not same as swapped element.

SMIL RAJ THAKUR 3 Dr. Kinjal Chaudhari


Right and increase right count variable until the traversed element
is not same as swapped element.

Up and increase up count variable until the traversed element is not


same as swapped element.

Down and increase down count variable until the traversed element
is not same as swapped element.

Sum of right and left will give total length of row with same candies.
Sum of up and down will give length of column with same candies.

Row_count = right + left


Col_count = up + down

If(row_count > = 3 ) the match is valid

If(col_count >= 3 ) the match is valid

This is very basic algo to determine the valid match as game proceeds it allows
different combinations of match like match combining both row and column
etc. but these all combinations can be validate using the row_count and
col_count variable.

Lives System:

Condition: We need to check if the player lost the game or not. If yes
than fetch the current life and decrease by one

For example:

SMIL RAJ THAKUR 4 Dr. Kinjal Chaudhari


Here the player finished all his/her lives and counter for next life is initiated that
is 30 mins.

Pseudo-code for this:

We need two variable to store the current life, and current timer

Int curr_life = fetch_current_life();


Int curr_timer = fetch_current_timer();

If(game_lost() == true){
//we check that if the game is lost
If(curr_life > 0){
//we need to check whether current life if greater than zero or
//not

Curr_life = curr_life – 1;

Curr_timer = curr_timer + 30 mins;

Set_life(curr_life);
Set_timer(curr_timer);

SMIL RAJ THAKUR 5 Dr. Kinjal Chaudhari


//inbuild game methods will be used to update the new life
and timer
}
Else{
//this condition should not exist as player can not play with z
//zero life

Return ERROR;
}
}

This is very basic algo to update the life system and life regeneration timer.
Player can also purchase additional lives and decrease timer time, this requires
additional code implementation.

Level Up System:

Condition: We need to check whether the player won the current level
and unlock new level

For example:

SMIL RAJ THAKUR 6 Dr. Kinjal Chaudhari


Here levels till 22 is unlocked by the player and levels succeeding it is locked.

Level 1 is unlocked by default

Pseudo-code for this:

We can have a custom class from each level having a Boolean value for
unlocked.

If unlocked = false than the level is locked and vice-versa

These levels can be chained in array or a linked list

If(game_win()==true){

Curr_level->next_level.unlocked = true;

//move the pointer to next level and set its unlocked value to true;

SMIL RAJ THAKUR 7 Dr. Kinjal Chaudhari


}

This is very basic algo to unlock next level, as game also needs to fetch and
sync level already played from the same account. And account for any
purchased unlocked also scoring system needs to be bind with the level.

Classifying in game AI into categories

Overview of classes of AI:

1) Monotonic: Addition of a extra rule does not affect the growth of


the system in negative way that is adding extra rule will increase the
stability of the AI, make the system more powerful.

2) Non-monotonic: If the addition of a new rule to the system can


either increase or decrease the number of inferences that can be
made. Make the system more or less powerful.

3) Partially commutative: If the order in which the rules are applied


can affect the outcome. The order in which the rules are applied
matters in some cases but not in others.

4) Commutative: If the order in which the rules are applied does not
affect the outcome. The order in which the rules are applied does not
matter.

Classifying Game AI into these classes:

1) level balancing AI: This can be classified as goal-oriented cause it


is designed to solve a specific problem that is balancing the game
difficulty. Also this AI is incremental and operates by making small

SMIL RAJ THAKUR 8 Dr. Kinjal Chaudhari


changes to game over time. It can be classified into monotonic as
each increment make the AI more complex by adding more rules.

2) Personalization AI: This can also be classified as goal-oriented, it


could be monotonic or non-monotonic depending on how the AI
adapts to user preferences and behavior.

3) Predictive analysis AI: This type of AI is declarative as it uses


data and rules to predict the future outcomes and achieve the a
specific goal. It could also be classified as either monotonic or non-
monotonic depending on whether the addition of new data or rules
can only increase or may decrease the accuracy of the predictions.

4) Level mapping AI: It comes under partially commutative, as the


order in which the rules are applied to place the candies in the map
affects the outcome of the gameplay, this AI needs to communicate
with level balancing AI and apply rules to formulate the board
accordingly and it also incremental, as new level maps can be added
over time to enhance the experience.

Conclusion: Candy Crush Saga is a game that has very deep implemented
data structures and algorithm that pairs with AI to deliver a very addicted
game. It truly understands the users responses and make the level and
special abilities accordingly. AI are implemented in small chunks rather
than modeling a big general purpose AI, this reduces the chances of error
and decrease the logic processing time for the game.

SMIL RAJ THAKUR 9 Dr. Kinjal Chaudhari

You might also like