# Detailed explanation of ICM?

Most ICM's explanation just say: ICM converts the value of bla...bla...bla. Now let's get to the calculator.

I need something detailed, because I want to try to program it.

The best explanation that I get is this thread and this Java code but I got confused. To be precise, I lost my brain when I entered how to calculate 3rd place..

Genera ICM

ICM Math

If you know how to program recursion it is pretty easy
If you don't know recursion then it would be hard
For the first level you get a chip weighed split
For other levels it gets more complex - you get a chip weighted split of what is left over out of prior cashes
This is .NET C#

``````public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
double[] payout = new double[] { 500.0, 300.0, 200.0 };  // payout structure
double[] stacks = new double[] { 500, 300, 200, 100 };   // player stacks
double mePayout = getEquity(payout, stacks, 0);
double total = mePayout;
Debug.WriteLine(mePayout.ToString("N2"));
mePayout = getEquity(payout, stacks, 1);
total += mePayout;
Debug.WriteLine(mePayout.ToString("N2"));
mePayout = getEquity(payout, stacks, 2);
total += mePayout;
Debug.WriteLine(mePayout.ToString("N2"));
mePayout = getEquity(payout, stacks, 3);
total += mePayout;
Debug.WriteLine(mePayout.ToString("N2"));
Debug.WriteLine(total.ToString("N2"));
}

public static double getEquity(double[] payouts, double[] stacksI, int player)
{   //returns ICM equity for selected player
double total = 0;
for (int i = 0; i < stacksI.Length; i++)
total += stacksI[i];
double[] stacks = new double[stacksI.Length];
stacksI.CopyTo(stacks, 0);
return getEquity(payouts, stacks, total, player, 0);
}

private static double getEquity(double[] payouts, double[] stacks, double total, int player, int depth)
{   //Recursive method doing the actual calculation.
double eq = stacks[player] / total * payouts[depth];

if (depth + 1 < payouts.Length)
for (int i = 0; i < stacks.Length; i++)
if (i != player && stacks[i] > 0.0)
{
double c = stacks[i];
stacks[i] = 0.0;
eq += getEquity(payouts, stacks, total - c, player, depth + 1) * c / total;
stacks[i] = c;
}

return eq;
}
}
``````

For an intuitive explanation:

If youve ever run an equity calculation to analyze a hand adding all weighted outcomes together for either side of particular choice you made, it's the same idea as that.

Only difference is the weighting for finishes is based on (chip stacks)/(Chips in play).

The catch is you need to run it for every possible outcome not only for you but for the entire field. (All Permutations)