Code:
using System;
namespace PokeCatchSim
{
class Program
{
static Random r = new Random();
static void Main(string[] args)
{
Console.Write("Enter the Pokemon's Max HP (an estimate based on it's level): ");
int MaxHP = GetIntInput();
Console.Write("Enter the Pokemon's Current HP based on the estimated MaxHP\r\nand the current HPbar: ");
int CurHP = GetIntInput();
Console.Write("Enter the status ailment multiplier\r\n(1.5 for poison, paralysis and burn, 2 for sleep and freeze)\r\n(and 1 for no ailment): ");
float Ailment = GetSingleInput();
Console.Write("Enter the Pokemon's Catch Rate: ");
int CatchRate = GetIntInput();
Console.Write("Enter the used Poke Ball's multiplier: ");
int Ball = GetIntInput();
double StepA = ((3 * MaxHP) - (2 * CurHP)) * CatchRate * Ball;
double StepB = StepA/(3*MaxHP);
double a = StepB*Ailment;
if(a >= 255)
{
Console.WriteLine("Catch rate: 100%");
Console.WriteLine("The Pokemon was caught non-randomly.\r\n(You have successfully withered the Pokemon's HP down\r\nto where it will be caught no matter what).");
Console.WriteLine("Press Enter to exit.");
Console.ReadLine();
return;
}
double b = 1048560/Math.Sqrt(Math.Sqrt(16711680/a));
double c = (b/65535) * 100;
Console.WriteLine("Catch rate: " + c + "%. Try your luck?\r\nEnter the number of tries to catch the Pokemon.\r\n(0 for NO): ");
int tries = GetIntInput();
if(tries < 1)
{
Console.WriteLine("Press Enter to exit...");
Console.ReadLine();
return;
}
int ZeroShakes = 0;
int OneShake = 0;
int TwoShakes = 0;
int ThreeShakes = 0;
int Catches = 0;
int Wierd = 0;
for(int count = 0; count < tries; count++)
{
int res = SimulateCatch(b);
switch(res)
{
case 0:
ZeroShakes++;
continue;
case 1:
OneShake++;
continue;
case 2:
TwoShakes++;
continue;
case 3:
ThreeShakes++;
continue;
case 4:
Catches++;
continue;
default:
Wierd++;
continue;
}
}
Console.WriteLine("0 shakes: " + ZeroShakes);
Console.WriteLine("1 shake : " + OneShake);
Console.WriteLine("2 shakes: " + TwoShakes);
Console.WriteLine("3 shakes: " + ThreeShakes);
Console.WriteLine("Catches : " + Catches);
if(Wierd > 0)
Console.WriteLine("Errors : " + Wierd);
Console.WriteLine("Press Enter to exit...");
Console.ReadLine();
}
private static int GetIntInput()
{
while (true)
{
string input = Console.ReadLine();
int ret;
if (int.TryParse(input, out ret))
{
return ret;
}
Console.Write("Invalid integer. Re-enter: ");
}
}
private static Single GetSingleInput()
{
while (true)
{
string input = Console.ReadLine();
Single ret;
if (Single.TryParse(input, out ret))
{
return ret;
}
Console.Write("Invalid decimal. Re-enter: ");
}
}
private static int SimulateCatch(double b)
{
int Shakes = 0;
int[] Random = { r.Next(65536), r.Next(65536), r.Next(65536), r.Next(65536) };
foreach (int rand in Random)
{
if (rand <= b) Shakes++;
}
return Shakes;
}
}
}