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;
}
}