Followers

Monday 28 May 2012

World of Warcraft probability C# script

This is a simple WOW drop probability calculator. Its written in C# as i couldn't find it in a different language.

The algorithm seems solid and functional, hope its helpful to those looking for some awesome drops
using System;
using System.IO;
using System.Linq;



public class Probability
{
    static void Main()
    {
        Hello();
        Input();
    }

    static void Hello()
    {
        Console.Clear();
        Console.WriteLine("This is a very simple probability calculator.");
        Console.WriteLine("I wrote it to calculate the probability of the Baron dropping his Deathcharger.");
        Console.WriteLine("\nInstructions:");
        Console.WriteLine("\n1. Consult Wowhead for the percentage chance of X item dropping.");
        Console.WriteLine("2. Determine how many times you are willing to run an event or kill a boss for this drop.");
        Console.WriteLine("3. Input them when requested.");
        Console.Write("\nPress [RETURN] to continue.");
        Console.ReadLine();
        Console.Clear();
    }

    static void Input()
    {
        int drop = 0;
        int runs = 0;

        drop = ParseInteger("Enter percentage drop rate: \t");
        runs = ParseInteger("Enter number of runs: \t\t");

        Console.WriteLine();
        Console.Write("\nThe probability of a drop after {0} runs is {1:P}.\n", runs, Calcutron(drop, runs));
        Console.ReadLine();
    }

    static double Calcutron(int drop, int runs)
    {
        // Convert the drop rate percentage into a usable decimal.

        double cuml = 1;
        double prob = 0;

        prob = 1 - (Convert.ToDouble(drop) / 100);

        for (int i = 1; i <= runs; i++)
            cuml *= prob;

        cuml = 1 - cuml;

        return cuml;
    }

    // Parse input.
    static int ParseInteger(string query)
    {
        bool parse         = false;
        int parsedInt     = 0;

        do
        {
            Console.Write(query);
            parse = Int32.TryParse(Console.ReadLine(), out parsedInt);

            if (!parse)
                ParseErr();

        } while(!parse);

        return parsedInt;
    }

    // +++++ERRORS++++
    static void ParseErr()
    {
        Console.WriteLine("\nPlease input a valid number!");
    }
}

No comments:

Post a Comment