Zuma Game Algorithm

Problem:

Play Zuma games online for free: Zuma Deluxe, Zuma's Revenge, Zuma Blitz! Zuma Deluxe 2. Rating: -control: by mouse. Japanese Zuma. It is the most famous and popular version of the online game. Classical Zuma will always remain a favorite one for many players. It has beautiful graphics, lots of exciting levels,.

Think about Zuma Game. You have a row of balls on the table, colored red(R), yellow(Y), blue(B), green(G), and white(W). You also have several balls in your hand.

Each time, you may choose a ball in your hand, and insert it into the row (including the leftmost place and rightmost place). Then, if there is a group of 3 or more balls in the same color touching, remove these balls. Keep doing this until no more balls can be removed.

Zuma

Zuma Revenge

Find the minimal balls you have to insert to remove all the balls on the table. If you cannot remove all the balls, output -1.

Examples:
Input: “WRRBBW”, “RB”
Output: -1
Explanation: WRRBBW -> WRR[R]BBW -> WBBW -> WBB[B]W -> WW

Input: “WWRRBBWW”, “WRBRW”
Output: 2
Explanation: WWRRBBWW -> WWRR[R]BBWW -> WWBBWW -> WWBB[B]WW -> WWWW -> empty

Input:“G”, “GGGGG”
Output: 2
Explanation: G -> G[G] -> GG[G] -> empty

Input: “RBYYBBRRB”, “YRBGB”
Output: 3
Explanation: RBYYBBRRB -> RBYY[Y]BBRRB -> RBBBRRB -> RRRB -> B -> B[B] -> BB[B] -> empty

Note:

  1. You may assume that the initial row of balls on the table won’t have any 3 or more consecutive balls with the same color.
  2. The number of balls on the table won’t exceed 20, and the string represents these balls is called “board” in the input.
  3. The number of balls in your hand won’t exceed 5, and the string represents these balls is called “hand” in the input.
  4. Both input strings will be non-empty and only contain characters ‘R’,’Y’,’B’,’G’,’W’.

Idea: Search

Solution1: C++ / Search

2
4
6
8
10
12
14
16
18
20
22
24
26
28
30
32
34
36
38
40
42
44
46
48
50
52
54
56
// Runtime: 3 ms
public:
vector<int>h(128,0);
returndfs(board,h);
private:
// Return the min # of balls needed in hand to clear the board.
intdfs(conststring&board,vector<int>&hand){
inti=0;
while(i<board.size()){
// board[i] ~ board[j - 1] have the same color
// Number of balls needed to clear board[i] ~ board[j - 1]
// Have sufficient balls in hand
// Remove board[i] ~ board[j - 1] and update the board
stringnb=update(board.substr(0,i)+board.substr(j));
// Find the solution on new board with updated hand
intr=dfs(nb,hand);
// Recover the balls in hand
}
}
}
// Update the board by removing all consecutive 3+ balls.
stringupdate(stringboard){
while(i<board.size()){
while(j<board.size()&&board[i]board[j])++j;
board=board.substr(0,i)+board.substr(j);
}else{
}
returnboard;
};

请尊重作者的劳动成果,转载请注明出处!花花保留对文章/视频的所有权利。
如果您喜欢这篇文章/视频,欢迎您捐赠花花。
If you like my articles / videos, donations are welcome.

Buy anything from Amazon to support our website
您可以通过在亚马逊上购物(任意商品)来支持我们
Venmo
huahualeetcode

Zuma Game Algorithm Download

Zuma

Zuma Game Algorithm Game

Rating:

Zuma Game Algorithms

Would you like to take a break from everyday hustle and relax? Play a game 'Zuma' on-line!
You see a stone slab from Egypt pyramid. There are special gutters on it with a hole at the end. A line of balls runs along the gutter. Their colors are chosen randomly. There is an all-seeing eye in the center with a ball inside. The ball is just like its 'brothers' in the chain.
You aim is not to let the chain get to the end of the gutter and fall into the hole. Move a mouse for changing direction and click the left button of it to shoot. If you hit the right group of balls (minimum two) - they will disappear and you will get your points. If you shoot in the wrong place - your ball will just join a moving chain.
After good shots the chin slows down and you have a good opportunity to keep shooting. Levels change automatically, but you can make a break and continue your game after this pause. Each level differs from the previous one with the shape of the gutter and number of balls. Higher levels can challenge you with fast speed and new colors.
It is free to play on-line and the one who makes a new record high becomes a champion!