MakeWebGames

# Algorithm Challenge!

## Recommended Posts

Hello Everyone,

As my game is getting closer to finish. I started to focus on the minor elements that pull it all together. One very important element was the algorithm to how much one can gain when playing a level. I guess it will be best to start off with the basics of the game and then give an example. The game is set to give out 1 Star, 2 Stars or 3 Stars based on the total number of moves one makes during the level. I have set up that one 3 Stars will give out full reward, 2 Stars will give out half of the reward and 1 Star will give out a 1/4 of the reward. I was looking to find an algorithm that would exponentially increase the value from the 1 Star value to the 2 Star value, the same for 2-3 Stars. So, here is an example:

Level 1 will give you 100\$ for 3 Stars, 50\$ for 2 Stars and 25\$ for 1 Star.

- 1 Star you do the level in 15 moves

- 2 Stars you do the level in 10 moves

- 3 stars you do the level in 5 moves.

With the difference of 5 moves between the stars, you would use a multiplier of 1.14-1.15. You can see below how it will work out:

10 moves = 50\$

9 moves = 57.50\$ (rounded out to 58 for display purposes on game)

8 moves = 66.13\$ (rounded to 66 for display purposes)

7 moves = 76.04\$

6 moves = 87.45\$

5 moves = ~100\$

Now this example was for easy example usage, however, all levels will be different with some being 10 moves away or 3 or 7, etc. So, I went from 2-6 move differences to get an idea. Those are as follow:

2 move difference = x1.41

3 move difference = x1.26

4 move difference = x1.19

5 move difference = x1.15

6 move difference = x1.123

The issue is that I know I got the multiplier manually, I would prefer coming up with an algorithm that would make it all work no matter the difference of moves between the Star markers.

Been at it or a couple of days now, anyone want to give it a try?

Regards,

Pete

##### Share on other sites

Will the levels increase with difficulty? Are the levels all custom?

But try the 1.11-1.15 + 0.2 for each new level.

##### Share on other sites

I'm not sure exactly what you're looking for as your post is a little unclear. But give this a go...

```\$maximum_move_difference = \$maximum_moves_for_current_level - \$minimum_moves_for_current_level;

\$your_move_difference = \$maximum_moves_for_current_level - \$your_moves;

\$maximum_to_multiply_by = 4;
\$minimum_to_multiply_by = 1;

\$each_move_difference_increment = (\$maximum_to_multiply_by - \$minimum_to_multiply_by) / \$maximum_move_difference;

\$multiply_value = (\$your_move_difference*\$each_move_difference_increment) + \$minimum_to_multiply_by;

\$award = \$minimum_reward_for_current_level*\$multiply_value;```
Edited by DidNotCompute

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×

• #### Marketplace

• Discord Chat
• PBBG Directory
×
• Create New...