26
\$\begingroup\$

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:

a = (((3 * HP_max - 2 * HP_current) * rate * bonus_ball) / 3 * HP_max) * bonus_status

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.

After finding 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 , so your score is your program's source code's byte count. Lowest score wins.

Bonuses!

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:

*shake*
Click!

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.

Example Input/Output

Just to ensure we're all on the same page.

$ ./balls <<< "19,Ultra,255"
*shake*
*shake*
*shake*
Click!

Good luck, and happy golfing!

\$\endgroup\$
  • \$\begingroup\$ I currently can't judge how big the probability you give as 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\$ – TheConstructor Mar 8 '14 at 13:09
  • \$\begingroup\$ If 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\$ – undergroundmonorail Mar 8 '14 at 18:11
  • \$\begingroup\$ So rnd < p means the check is successfull with rnd in range of 0 and 1. \$\endgroup\$ – TheConstructor Mar 8 '14 at 18:14
  • 1
    \$\begingroup\$ @IsmaelMiguel see my comments: you generate a random number in the range of 0 to 1 and compare it against 65536 / (255 / a)^(1/4), then if the random number is less the shake test succeeded \$\endgroup\$ – TheConstructor Mar 8 '14 at 22:39
  • 1
    \$\begingroup\$ As state in the text the textual type of pokeball, max hp and catch rate are past as input to your program. Optionally you can ask for current hp (default 1) or status bonus (default 2.5) \$\endgroup\$ – TheConstructor Mar 8 '14 at 22:48
3
\$\begingroup\$

J 301-150 = 151

For sports, all bonuses implemented, though I'd probably be better off not to :). I shortly explained things below, but this one is far too long to explain in detail, unless someone explicitly requests. It implements all balls, critical captures, and optional inputs.

tm =: =*./@:+.' '=] NB. Template match, match non-blanks in right with left
balls  =: 'MMLLPGSUNDFQ',.12{.'oauo' NB. space = wildcard.
NB. lookup function: name -> bonus_ball
lookup =: 4 255 3 8 1 1.5 1.5 2 3 3.5 4 5 #~ (tm"1&balls)@(2&{.) 

NB. convert given option
options =: ;".`lookup@.(_=_&".);._2 ,&',' i3 NB. parse options to numeric values
NB. add defaults if necessary
complete =: (, 1 2.5{.~(5-$)) options         
NB. formula
r=: <.&.(*&4096)                              NB. round to 1/4096
NB. a=: ((3*zeroth - 2*thirth)*first*second*fourth)/(3*zeroth)
a=:r(1-3%~2*%/3 0{complete)**/1 2 4{complete  NB. A prime, already divided by 255

NB. Critical captures
crit =: >2r5*[:?11^~2: NB. check for critical, k a
mess =: 2 7$'*shake*Click! '"_ NB. Message template
check =: >"0 [:?(4$2^16)"_     NB. Perform 4 checks
mes2 =: mess#~3(<.,<)]          NB. Construct message from number of passed checks
NB. If critical, just output the message array, else do the 4 tests, and execute mes2 on their running and (meaning count the number of uninterrupted trues)
echo mes2@(+/)@(*./\)@(check"0)@(65536%4%:[:r 255%])`mess@.crit a

Here the golfed version

NB. Golfed verion
echo(m#~3(<.,<)])@(+/)@(*./\)@(>"0[:?(4$2^16)"_)@(65536%4%:[:r 255%])`(m=:2 7$'*shake*Click! '"_)@.(>2r5*[:?11^~2:)(r=:<.&.(*&4096))(1-3%~2*%/3 0{co)**/1 2 4{co=:(,1 2.5{.~(5-$));(".`(4 255 3 8 1 1.5 1.5 2 3 3.5 4 5 #~((=*./@:+.' '=])"1)&('MMLLPGSUNDFQ',.12{.'oauo')@(2&{.)))@.(_=_&".);._2,&','stdin''
| improve this answer | |
\$\endgroup\$
6
\$\begingroup\$

PYTHON 249 bytes - 75 for bonuses = 174

My first try ever golfing.

import sys,random
y=sys.argv
d,b,f={10:1,1:1.5,15:2,7:1.5,13:255,-2:3.5,6:3,8:3,0:4,11:5},3*int(y[1]),"*shake*\n"
s=lambda:random.random()*(255*b)**.25<65536*((b-2)*int(y[3])*d[ord(y[2][0])-70]*2.5)**.25
if s():print f*3+"Click!" if s()and s()else f

Bonus for including selected balls: Safari, Sport, Lure, Net, Dusk, Dive, Fast, Quick

Giving me 8*5+6+5+4+3+4+4+4+5=75 bonus points

[edit] Round down to 12 fractional bits every time division is used by not using it

[edit2] optimize pokeball dictionary

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ I think you are using a precission higher than 1/4096 (question states Note: Whenever any division is performed, the result is rounded down to a multiple of 1/4096.) \$\endgroup\$ – TheConstructor Mar 10 '14 at 11:12
  • \$\begingroup\$ You are probably right, I didn't quite understand that part and the other answers seemed to do it same way I did. I guess I need to do something like this: r < 65536/(255/a)^(0.25) <=> r*255^(0.25)/a^(0.25) < 65536 <=> r*255^(0.25) < 65536*a^(0.25) to exclude all divisions? \$\endgroup\$ – Þorsteinn Mar 10 '14 at 14:51
  • \$\begingroup\$ 1/4096 mean 12 fractional bits. Have a look at my solution; a more direct approach would be floor(x*4096)*4096 just as you would round down to e.g. decimal places. \$\endgroup\$ – TheConstructor Mar 11 '14 at 0:49
  • \$\begingroup\$ Ohh I see, thank you. This should likely also apply to multiplication like you seem to have done it, but since that is not stated in the rules I´m not going to worry about that. :) \$\endgroup\$ – Þorsteinn Mar 11 '14 at 3:31
  • \$\begingroup\$ Yes, probably they use fixed-point arithmetics. But OP only asked to round division. \$\endgroup\$ – TheConstructor Mar 11 '14 at 6:10
6
\$\begingroup\$

Perl 1 (374 - 150 = 224 + MissingNo. bytes)

sub h{print "*shake*
";}($x,$h,$_,$c,$s)=split(/,/,<>);$G=$$%(/P/?256:/U/?151:201);$S=$G-($s==1?0:$s==1.5?12:25);
$F=255&int(int($h*255/(/G|S/?8:12))/(int($x/4)||1));sub c{for($i=0;$i<3;$i++){do h();}print "Click!
";exit;}
/M/||$S<0||$S<$c&&$F>$$*$$%255&&do c();$W=int(int($c*100/(/P/?255:/U/?150:200))*$F/255)+($s==1?0:$s==1.5?5:10);$W>9&&do h();$W>29&&do h();$W>69&&do h();

Argument list:

current hp, max hp, pokéball, catch rate, status, critical capture

Yes, I'm aware this completely breaks the rules, but I don't care. In case you haven't noticed, this is first Pokémon generation capture algorithm, with all its quirks (Great Balls are better than Ultra Balls, in certain conditions). This implements all features, including ones that aren't included (and I decided to include points for them anyway). Critical captures are ignored (but they are implemented - just that they don't affect the capture rate), newer Poké Balls load data of other Poké Balls.

Please note that while this answer is short, it breaks all the rules, so consider it just to be a fun answer, don't accept it. I was initially going to implement Gen5 algorithm in Perl 5, but I decided - why not have some fun. And yes, I actually compiled Perl 1, and this code works. If you run it in newer version of Perl, you may get warnings about deprecated use of do, but let's be honest - it's the only way to run functions in Perl 1. Perl 1 also has some quirks on its own (for example, I cannot move the line starting with /M/ to previous line - why? - I don't know).

Also, there are no random numbers in Perl 1, so hope you won't kill me for modulo of $$. It's the closest thing to the random number I could have found.

Edit: It appears that the old do call() syntax was removed in Perl 5.19.8. Make sure you use an older version of Perl to run this script, as it appears that Perl 5.20 won't be compatible with Perl 1 scripts.

| improve this answer | |
\$\endgroup\$
5
\$\begingroup\$

PHP (746 763 bytes - all bonuses):

<?if(!$i=fgets(STDIN))die('');parse_str($i,$i);$b=array('poke'=>1,'great'=>1.5,'ultra'=>2,'master'=>255,'safari'=>1.5,'sport'=>1.5,'lure'=>3,'net'=>3,'dusk'=>3.5,'dive'=>3.5,'moon'=>4,'fast'=>4,'quick'=>5,'love'=>8);$s=array('sleep'=>2.5,'frozen'=>2.5,'paralyzed'=>1.5,'poisoned'=>1.5,'burnt'=>1.5,''=>1);$i=array_merge(array('ball'=>'poke','hp'=>array('max'=>25,'current'=>1),'status'=>2.5,'rate'=>255),$i);$l='strtolower';$r='mt_rand';$x='*shake*'.PHP_EOL;$c='Click!'.PHP_EOL;$a=(((3*$i[hp][max])-(2*$i[hp][current]))*$i[rate]*$b[$l($i[ball])])/(3*$i[hp][max])*(is_numeric($i[status])?$i[status]:$s[$l($i[status])]);$a=((pow(65536/(255/$a),0.25)*4096)<<0)/4096;if($r(0,1)>$a)die();echo$x;if($a>1)die($c);if($r(0,1)>$a)die();echo$x,$x;if($r(0,1)>$a)die();echo$c;

To use this, you have to provide the input as 'ball=poke&status=sleep' on STDIN.

The HP must be provided as 'hp[max]' or 'hp[current]'.

This code works, as tested here.

You can provide the status by it's name or the multiplier. (not required in the question).

Here is a readable version:

if(!$info=fgets(STDIN))die('');
parse_str($info,$info);
$balls=array(//list of pokeballs
    'poke'=>1,
    'great'=>1.5,
    'ultra'=>2,
    'master'=>255,
    'safari'=>1.5,
    'sport'=>1.5,
    'lure'=>3,
    'net'=>3,
    'dusk'=>3.5,
    'dive'=>3.5,
    'moon'=>4,
    'fast'=>4,
    'quick'=>5,
    'love'=>8
);
$status=array(//list of status
    'sleep'=>2.5,
    'frozen'=>2.5,
    'paralyzed'=>1.5,
    'poisoned'=>1.5,
    'burnt'=>1.5,
    ''=>1 //in case there is no status
);
$info=array_merge(//this will set the default values
    array(
        'ball'=>'poke',
        'hp'=>array('max'=>25,'current'=>1),
        'status'=>2.5,
        'rate'=>255
    ),
    $info
);
$a=(((3*$info['hp']['max'])-(2*$info['hp']['current']))*$info['rate']*$balls[strtolower($info['ball'])])/(3*$info['hp']['max'])*(is_numeric($info['status'])?$info['status']:$status[strtolower($info['status'])]);
$a=((pow(65536/(255/$a),0.25)*4096)<<0)/4096;//same as $a=floor(pow(65536/(255/$a),0.25)*4096)/4096;

if(mt_rand(0,1)>$a) die();//test 1
echo '*shake*',PHP_EOL;
if($a>1)die('Click!'.PHP_EOL);//if $a>1, catch it (critical catch)

if(mt_rand(0,1)>$a) die();//test 2
echo'*shake*',PHP_EOL,'*shake*',PHP_EOL;

if(mt_rand(0,1)>$a) die();//test 3
echo 'Click!',PHP_EOL;//passed all tests

I had to edit this because i was using a much higher precision than the required.

The fix was provided by TheConstructor.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ I think you are using a precission higher than 1/4096 (question states Note: Whenever any division is performed, the result is rounded down to a multiple of 1/4096.) \$\endgroup\$ – TheConstructor Mar 11 '14 at 9:54
  • \$\begingroup\$ And you are right. I noticed that I'm using whatever value comes from the division. If you want, you can give me some help 'cause i have no damn idea of how to 'round' to a smaller precision in PHP. \$\endgroup\$ – Ismael Miguel Mar 11 '14 at 10:33
  • \$\begingroup\$ You can do floor(x*4096)/4096 or implement fixed-point division like I did. \$\endgroup\$ – TheConstructor Mar 11 '14 at 10:37
  • \$\begingroup\$ Thank you for your help. I would never think of that. I have fixed my answer. \$\endgroup\$ – Ismael Miguel Mar 11 '14 at 14:00
3
\$\begingroup\$

Java, 611

import java.util.*;class P{enum B{DI(35),DU(35),FA(40),GR(15),LO(80),LU(30),MA(2550),MO(40),NE(30),PO(10),QU(50),SA(15),SP(15),UL(20);long v;B(int i){v=((long)i<<12)/(long)10;}}public static void main(String[]y){Scanner s=new Scanner(System.in);B b=B.valueOf(s.next().toUpperCase().substring(0,2));long c=(long)(s.nextDouble()*4096);long m=s.nextLong()<<12;long h=(s.hasNextInt()?s.nextLong():1)<<12;long S=(long)((s.hasNextDouble()?s.nextDouble():2.5)*4096);long p=(65536L<<12)/(long)(Math.sqrt(Math.sqrt((255L<<24)/((((3L*m-2L*h)*c>>12)*b.v>>12<<12)/(3L*m)*S>>12)))*512);Random r=new Random();System.out.print(r.nextInt(65536)<p?"*shake*\n"+(r.nextInt(65536)<p?"*shake*\n*shake*\n"+(r.nextInt(65536)<p?"Click!\n":""):""):"");}}

Score:

  • 729 Bytes
  • -93 all Balls
  • -25 optional current_hp and bonus_state

=> 611

The program uses fixed-point-arithmetics with 12 fraction-bits (1/4096 is the value of the right most bit). As Java does not usually use fixed-point there are quite some shifts inside the code to achieve the expected results. See long version for the used arithmetic functions, which have been inlined for golfing purposes.

While most calculations could have been done on int values, divisions work better with longs as you need to shift the dividend by another 12 bit to the left to keep the desired precision (otherwise you loose all fraction-bits).

Sample input ( ; is only required if run interactively i.e. STDIN has not received EOF): Ball, catch_rate, max_hp

Poke 15 255 ;

Sample output:

*shake*

Sample input: Ball, catch_rate, max_hp, current_hp, bonus_state

Moon 42 255 50 1.5

Sample output:

*shake*
*shake*
*shake*
Click!
import java.math.BigDecimal;
import java.util.Random;
import java.util.Scanner;

class Pokeball {
    static long shift(long i) {
        return i << 12;
    }
    enum B {
        DI(35),DU(35),FA(40),GR(15),LO(80),LU(30),MA(2550),MO(40),NE(30),PO(10),QU(50),SA(15),SP(15),UL(20);
        long v;
        B(int i) {
            v = semiFixedDivision(shift(i),10);
        }
    }

    public static void main(String[] args) {
        final Scanner s = new Scanner(System.in);
        B b = B.valueOf(s.next().toUpperCase().substring(0, 2));
        long catchRate = (long) (s.nextDouble() * 4096);
        long maxHp = shift(s.nextLong());
        long currentHp = shift(s.hasNextInt()?s.nextInt():1);
        long statusBonus = (long) ((s.hasNextDouble()?s.nextDouble():2.5) * 4096);
        long a = fixedMultiplication(fixedDivision(fixedMultiplication(fixedMultiplication(
                semiFixedMultiplication(3, maxHp) - semiFixedMultiplication(2, currentHp), catchRate), b.v),
                                                   semiFixedMultiplication(3, maxHp)), statusBonus);
        println("a=",a);
        long x = fixedFourthRoot(fixedDivision(shift(255), a));
        println("x=",x);
        println("x^4=",fixedMultiplication(fixedMultiplication(x,x), fixedMultiplication(x,x)));
        long p = semiFixedDivision(shift(65536), fixedFourthRoot(fixedDivision(shift(255), a)));
        Random r = new Random();
        System.out.print(r.nextInt(65536) < p ?
                         "*shake*\n" + (r.nextInt(65536) < p ?
                                        "*shake*\n*shake*\n" + (r.nextInt(65536) < p ?
                                                                "Click!\n" :
                                                                "") :
                                        "") :
                         "");
    }

    private static long unshift(long p) {
        return p >> 12;
    }

    private static void println(String s, long v) {
        System.out.print(s);
        println(v);
    }

    private static void println(long v) {
        System.out.printf("%s%n", BigDecimal.valueOf(v).divide(BigDecimal.valueOf(4096)));
    }

    /**
     * Calculates division of {@code a/b} with both number last 12 bits treated as being "right of the dot"
     */
    static long fixedDivision(long a, long b) {
        return (a<<12)/b;
    }

    /**
     * Calculates division of {@code a/b} with {@code a}'s last 12 bits treated as being "right of the dot"
     */
    static long semiFixedDivision(long a, long b) {
        return a/b;
    }
    static long fixedMultiplication(long a, long b) {
        return (a*b) >> 12;
    }
    static long semiFixedMultiplication(long a, long b) {
        return a*b;
    }
    static long fixedFourthRoot(long a) {
        return (long)(Math.sqrt(Math.sqrt(a)) * 512);
    }
}
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

CoffeeScript - 317 313 310 307 306 294 270 250 242 bytes

342 - 25 (parameters) - 75 (12 balls) = 242

_=process.stdin
l=console.log
m=Math
s=m.sqrt
t=['*shake*','Click!']
n=65536
_.resume()
_.setEncoding 'utf8'
_.on 'data',(d)=>
 [A,B,C,E,F]=d.match /\w+/g;E||=1;F||=2.5;i=0;while i++<3
  if n*(s s (3*A-2*E)*B*{P:1,G:1.5,U:2,M:255,S:1.5,L:3,N:3,D:3.5,F:4,Q:5}[C.charAt 0]*F)<m.floor(m.random()*n)*s s 765*A
   break
  l t[0]
 if i>2
  l t[i-3]

Expects input HP_max,Rate,Ball[,HP_current[,status]]. Does not support Moon or Love balls.

This is the first thing I ever golfed that's not a regex, so there is probably room for improvement. I've shamelessly copied the idea to store only partial ball names. ;) Supporting the other two balls is simply not worth it, not even with the additional +7 for getting all bonuses.

Ungolfed version

This version omits all the short aliases I define at the beginning, but does define the ball-lookup separately.

balls =
  P: 1
  G: 1.5
  U: 2
  M: 255
  S: 1.5
  L: 3
  N: 3
  D: 3.5
  F: 4
  Q: 5

messages = ['*shake*', 'Click!']

process.stdin.resume()
process.stdin.setEncoding 'utf8'
process.stdin.on 'data', (data) =>
  [HP_max, rate, ball, HP_current, status] = data.match /\w+/g
  HP_current ||= 1
  HP_status ||= 2.5
  i = 0
  while i++ < 3
    if 65536 * (Math.sqrt Math.sqrt (3*HP_max - 2*HP_current)*rate*status*balls[ball.charAt 0]) < Math.floor(Math.random()*65536) * Math.sqrt Math.sqrt 765*HP_max
      break
    console.log messages[0]
  if i > 2
    console.log messages[i-3]

A note on the probability formula: I've rearranged the full formula (with written out a) so that there are no divisions, and I'm computing (...)^(1/4) by taking the square root twice.

| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ Looks like precendence is on your side O.o p-=p%1/4096 really seems to work. (Would have guessed you would at least need to write p-=p%(1/4096) and then still I would not be sure modulus is implemented for fractions on both side. Nice! \$\endgroup\$ – TheConstructor Mar 11 '14 at 10:57
  • \$\begingroup\$ @TheConstructor Haha, yeah I actually had to check that... it looked really weird to me too, but % can be used for some funny things in JS. After re-reading the question, I think this answer doesn't quite fulfil the rounding requirement though. I think rounding should be applied after each division. I might have to restructure my calculation a bit. ^^ \$\endgroup\$ – Martin Ender Mar 11 '14 at 11:01
  • \$\begingroup\$ Yes probably still good idea \$\endgroup\$ – TheConstructor Mar 11 '14 at 11:02
  • \$\begingroup\$ @TheConstructor Actually, I do need to write p%(1/4096). I even checked this before posting, but somehow remembered the result of my test wrong. \$\endgroup\$ – Martin Ender Mar 11 '14 at 12:31
  • \$\begingroup\$ Tried in Chrome; worked without () but maybe not always or not on all browsers... \$\endgroup\$ – TheConstructor Mar 11 '14 at 12:35
0
\$\begingroup\$

Update: (C#)

Byte count: 3,600

Critcal: -25

All poke-balls: -91


Total = 3,484

[golfed]

using System;using System.Text;using System.Security.Cryptography;using System.Linq;namespace Pokemon{public class MainClass{private string[] c(string[] i){if(i.Length <= 3){var v1 =i[0][0];var v2 =i[1][0];var v3 =i[2][0];if(v1>='0'&&v1<='9'&&v2>='a'&&v2<='z'&&v3>='0'&&v3<='9')return new string[]{i[0],i[2],i[1]};else if(v1>='0'&&v1<='9'&&v2>='0'&&v2<='9'&&v3>='a'&&v3<='z')return new string[]{i[0],i[1],i[2]};else if(v1>='a'&&v1<='z'&&v2>='0'&&v2<='9'&&v3>='0'&&v3<='9')return new string[]{i[1],i[2],i[0]};else return null;}else return null;}private static void Main(string[] args){while(true){Console.Clear();MainClass _c = new MainClass();Console.Write("Inputs'please:");var i = Console.ReadLine().ToLower();string[] r = _c.c((string[])(i.Split(new Char[]{' ','.',',','\n','\t','!','@','#','$','%','^','&','&','*','(',')','-','_','+','=','?','/','\\'},StringSplitOptions.RemoveEmptyEntries).Select(p=>p.Trim()).ToList()).ToArray());new w("Processing...\n");if(r== null)new w("Too many errors");else new m(r);}}}public class w{public w(string l){Console.WriteLine(l);}}public class m{public m(string[] v){switch (v[2].Substring(0,2)){case "po":c(v[0],v[1],"1");break;case "ul":c(v[0],v[1],"2");break;case "ma":c(v[0],v[1],"255");break;case "gr":case "sa":case "sp":c(v[0],v[1],"1.5");break;case "lu":case "ne":c(v[0],v[1],"3");break;case "du":case "di":c(v[0],v[1],"3.5");break;case "mo":case "fa":c(v[0],v[1],"4");break;case "qu":c(v[0],v[1],"5");break;case "lo":c(v[0],v[1],"8");break;default:new w("Not supported");break;}}private double y(double v){return Convert.ToDouble(((double)1/(double)4096)*(v/Convert.ToDouble(1/4096)-(v%Convert.ToDouble(1/4096))));}private bool i(double v,double r,double b){if(((double)new Random().Next(0,(int)r))>b*v)return true;else return false;}private double f(double r, double h, double b){return 2.5*y((((3.0*h)-2.0)*r*b)/(3.0*h));}private void c(params string[] v){var s =0.0;var x =0;if(int.Parse(v[1])>100&&int.Parse(v[1])<= 255){s =f(double.Parse(v[0]),double.Parse(v[1]),double.Parse(v[2]));x=0;}else if(int.Parse(v[0])>100&&int.Parse(v[0])<= 255){s =f(double.Parse(v[1]),double.Parse(v[0]),double.Parse(v[2]));x=1;}else{new w(String.Format("Which number is the Max HP? :{0} or {1}:",v[0],v[1]));var c_ = int.Parse(Console.ReadLine());s =f((double.Parse(v[0])+double.Parse(v[1]))-double.Parse(v[c_]),double.Parse(v[c_]),double.Parse(v[2]));x=2;}if(((double)new Random().Next(0, 2047))<s*2.5)new w("*shake*\nClick!");else{for(int c_= 0;c_<3;c_++){new w("*shake*");var r =Math.Pow(65536.0/y(255.0/s),0.25);if(i(r,double.Parse(v[x]),2.5)==true){new w("Click!");break;}else;}}Console.ReadKey();}}}

[regular]

using System;
using System.Text;
using System.Security.Cryptography;
using System.Linq;

namespace Pokemon
{
    public class MainClass
    {
        private string[] c(string[] i)
        {
            if (i.Length <= 3)
            {
                var v1 =i[0][0];
                var v2 =i[1][0];
                var v3 =i[2][0];
                if(v1>='0'&&v1<='9'&&v2>='a'&&v2<='z'&&v3>='0'&&v3<='9')return new string[]{i[0],i[2],i[1]};
                else if(v1>='0'&&v1<='9'&&v2>='0'&&v2<='9'&&v3>='a'&&v3<='z')return new string[]{i[0],i[1],i[2]};
                else if(v1>='a'&&v1<='z'&&v2>='0'&&v2<='9'&&v3>='0'&&v3<='9')return new string[]{i[1],i[2],i[0]};
                else return null;
            }
            else return null;
        }

        private static void Main(string[] args)
        {
            while(true)
            {
                Console.Clear();
                MainClass _c = new MainClass();
                Console.Write("Inputs'please:");
                var i = Console.ReadLine().ToLower();
                string[] r = _c.c((string[])(i.Split(new Char[]{' ','.',',','\n','\t','!','@','#','$','%','^','&','&','*','(',')','-','_','+','=','?','/','\\'},StringSplitOptions.RemoveEmptyEntries).Select(p=>p.Trim()).ToList()).ToArray());
                new w("Processing...\n");
                if(r== null)new w("Too many errors");
                else new m(r);
            }
        }
    }

    public class w
    {
        public w(string l)
        {
            Console.WriteLine(l);
        }
    }

    public class m
    {
        public m(string[] v)
        {
            switch (v[2].Substring(0,2))
            {
                case "po":
                    c(v[0],v[1],"1");
                    break;
                case "ul":
                    c(v[0],v[1],"2");
                    break;
                case "ma":
                    c(v[0],v[1],"255");
                    break;
                case "gr":
                case "sa":
                case "sp":
                    c(v[0],v[1],"1.5");
                    break;
                case "lu":
                case "ne":
                    c(v[0],v[1],"3");
                    break;
                case "du":
                case "di":
                    c(v[0],v[1],"3.5");
                    break;
                case "mo":
                case "fa":
                    c(v[0],v[1],"4");
                    break;
                case "qu":
                    c(v[0],v[1],"5");
                    break;
                case "lo":
                    c(v[0],v[1],"8");
                    break;
                default:
                    new w("Not supported");
                    break;
            }
        }

        private double y(double v){return Convert.ToDouble(((double)1/(double)4096)*(v/Convert.ToDouble(1/4096)-(v%Convert.ToDouble(1/4096))));}

        private bool i(double v,double r,double b){if(((double)new Random().Next(0,(int)r))>b*v)return true;else return false;}

        private double f(double r, double h, double b){return 2.5*y((((3.0*h)-2.0)*r*b)/(3.0*h));}

        private void c(params string[] v)
        {
            var s =0.0;
            var x =0;
            if(int.Parse(v[1])>100&&int.Parse(v[1])<= 255){s =f(double.Parse(v[0]),double.Parse(v[1]),double.Parse(v[2]));x=0;}
            else if(int.Parse(v[0])>100&&int.Parse(v[0])<= 255){s =f(double.Parse(v[1]),double.Parse(v[0]),double.Parse(v[2]));x=1;}
            else
            {
                new w(String.Format("Which number is the Max HP? :{0} or {1}:",v[0],v[1]));
                var c_ = int.Parse(Console.ReadLine());
                s =f((double.Parse(v[0])+double.Parse(v[1]))-double.Parse(v[c_]),double.Parse(v[c_]),double.Parse(v[2]));
                x=2;
            }
            if (((double)new Random().Next(0, 2047))<s*2.5)new w("*shake*\nClick!");
            else
            {
                for(int c_= 0;c_<3;c_++)
                {
                    new w("*shake*");
                    var r =Math.Pow(65536.0/y(255.0/s),0.25);
                    if (i(r,double.Parse(v[x]),2.5)==true){new w("Click!");break;}else;
                }
            }
            Console.ReadKey();
        }    
      }
  }
| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ This is code golfing. You should reduce your answer (eg: stripping whitespaces). You still can provide the current answer as a readable version. \$\endgroup\$ – Ismael Miguel Mar 9 '14 at 0:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.