In the Pokemon video games, the player is sent out into the world to force wild animals into tiny balls and train them to fight. Of course, everyone knows that no one plays Pokemon for the battling. The real draw the series has is the pokemon catching itself! Your job is to simulate the pokeball during a capture attempt. This challenge will use the generation V capture formula, which is as follows:
HP_max is equal to the target pokemon's maximum HP.
HP_current is equal to the target pokemon's current HP.
rate is the catch rate of the pokemon,
bonus_ball is the thrown pokeball's multiplier, and
bonus_status is 2.5 if the target pokemon is asleep or frozen, 1.5 if the target pokemon is paralyzed, poisoned, or burned, and 1 otherwise.
a, you are to perform up to three "shake checks". The probability of a shake check succeeding is
65536 / (255 / a)^(1/4). If any one of these checks fails, the pokemon escapes its ball. If all three checks are successful, the pokemon is caught!
Note: Whenever any division is performed, the result is rounded down to a multiple of 1/4096. This is generally an insignificant detail, but it must be accounted for in your program.
Your challenge is to write a program that executes the shake checks and prints to stdout the status of the checks. On stdin, your program will receive (at least, details below) the maximum HP of the pokemon, the catch rate of the target pokemon, and the name of the pokeball. The maximum HP and the catch rate are both guaranteed to be integers, while the name of the pokeball is always a string. This input may come in any order and with any delimiting character(s) is convenient for you, so long as it's consistent. Assume that the input is correct, no error handling is required.
The names of the pokeballs you are required to support and their catch multipliers are listed here:
Poke | 1 Great | 1.5 Ultra | 2 Master | 255
You may assume that the target is asleep and at 1 HP. The expected format for output is this:
(First check failed) (no output) (Second check failed) *shake* (Third check failed) *shake* *shake* *shake* (All checks pass) *shake* *shake* *shake* Click!
(That isn't a typo, your program should never output just two shakes.)
This is code-golf, so your score is your program's source code's byte count. Lowest score wins.
I said that you may assume the pokemon is at 1 HP and asleep. Alternatively, you may allow the user to input the pokemon's current HP and
bonus_status. The pokemon's current HP will always be an integer equal to or less than its maximum HP, and
bonus_status will always be either 2.5, 1.5 or 1. If you do, you must have these values at the end of your input, and default to 1 and 2.5 if they're not supplied. You may subtract 15 points from your score for implementing one of these, or 25 for both.
Additionally, you may implement critical captures. If a critical capture occurs, only one shake test is performed. If failed, the program exits silently. If passed, it outputs:
Critical captures become more common as the player collects more pokemon, but for simplicity's sake we can assume that they have already "caught 'em all". If a randomly generated number between 0 and 2047 is less than
a (the result of the first calculation) multiplied by 2.5, that's a critical capture. Support for critical captures allows you to remove 25 points from your score.
There are a number of other pokeballs you may choose to support. Their names and catch multipliers are listed here:
Safari | 1.5 Sport | 1.5 Lure | 3 Net | 3 Dusk | 3.5 Dive | 3.5 Moon | 4 Fast | 4 Quick | 5 Love | 8
For each of these balls you add support for, you may subtract (5 + the length of the ball's name) from your score.
Finally, for kicks, achieving all of these bonuses (current HP and bonus_status from stdin, critical captures, and all 10 optional balls) will net you an additional reward of 7 points removed from your score, for an even 150 total bonus.
Just to ensure we're all on the same page.
$ ./balls <<< "19,Ultra,255" *shake* *shake* *shake* Click!
Good luck, and happy golfing!
65536 / (255 / a)^(1/4)can get but my guts says it is greater than 1. Do you check against a random number in the range of 0 to 65536? Does the check succeed if the random number is bigger or if it is lower? \$\endgroup\$
65536 / (255 / a)^(1/4)is greater than 1, the check automatically succeed. I'm not sure what you mean by the second question. \$\endgroup\$
rnd < pmeans the check is successfull with
rndin range of 0 and 1. \$\endgroup\$
65536 / (255 / a)^(1/4), then if the random number is less the shake test succeeded \$\endgroup\$