How to put this algorithm in my app?

Hello again…

I think this is the most difficult question i have, because i don´t know how to do this…
But i have a lot of information and maybe anyone can help me… alone will be impossible to me =(

I tryng to create a poker app… and in this game you can make deals, we usually do when there are 9 players left

The algorithm here:

Link from this images:
Session 2.1

This is possible too:

Here is the algorithm:

Given n players
Given stack sizes S = S1, S2, … Sn
Given prizes Z = Z1, Z2, … Zn
Get normalized stack sizes Q = Q1, Q2, …Qn by dividing S by average stack

Simulate 1 tournament:
For each player i, generate a “place” for each player (Pi) by generating a random number between 0 and 1 and raising it to the power of 1/Qi. Pi = rand ^ (1.0 / Qi)
Sort players by their place P – higher is better
Award prizes Z according to P

This last information many people create this algorithm in 2 different language… maybe help…

import java.util.Arrays;
import java.util.Comparator;
import java.util.Random;

public class SimulatedIcm {

private Random rnd = new Random();

public double[] getEquities(double[] payouts, double[] stacks,
		int maxIterations) {
	if (payouts.length > stacks.length)
		payouts = Arrays.copyOf(payouts, stacks.length);

	double[] equities = new double[stacks.length];
	double[] exp = getExponents(stacks);
	final double[] r = new double[stacks.length];

	Integer[] ids = new Integer[stacks.length];
	for (int i = 0; i < ids.length; i++)
		ids[i] = i;

	Comparator<Integer> comp = new Comparator<Integer>() {
		public int compare(Integer i1, Integer i2) {
			if (r[i1] < r[i2])
				return 1;
			if (r[i1] > r[i2])
				return -1;
			return 0;

	for (int iteration = 0; iteration < maxIterations; iteration++) {
		for (int i = 0; i < r.length; i++)
			r[i] = Math.pow(rnd.nextDouble(), exp[i]);
		Arrays.sort(ids, comp);
		for (int i = 0; i < payouts.length; i++)
			equities[ids[i]] += payouts[i];

	for (int i = 0; i < equities.length; i++)
		equities[i] /= (double) maxIterations;

	return equities;

private static double[] getExponents(double[] stacks) {
	double t = 0;
	for (double s : stacks)
		t += s;
	t /= (double) stacks.length;
	double[] exp = new double[stacks.length];
	for (int i = 0; i < stacks.length; i++)
		exp[i] = t / stacks[i];
	return exp;

public static void main(String[] args) {
	SimulatedIcm sicm = new SimulatedIcm();

	double[] payouts = new double[] { 50, 30, 20 };
	double[] stacks = new double[] { 1000, 2000, 3000, 4000, 5000, 6000,
			7000, 8000, 9000 };
	double[] eqs = sicm.getEquities(payouts, stacks, 1000000);


from random import random

def trial(weights, payouts):
scores = sorted((random() ** weight, i) for i, weight in enumerate(weights))
results = [0] * len(payouts)
for payout, score in zip(payouts, scores): results[score[1]] = payout
return results

def sicm(stacks, payouts, trials):
avg = sum(stacks) / float(len(stacks))
payouts += [0] * (len(stacks) - len(payouts))
weights = [avg / s for s in stacks]
return [sum(player) / float(trials) for player in zip(*(
trial(weights, payouts) for i in xrange(trials)

I guess I should add an equivalent test to be fair to the Java implementation…

if name == ‘main’:
print sicm([1000 * n for n in range(1, 10)], [50, 30, 20], 1000000)

Link about this scripts:

My app is here:

So the calculation will shows under ICM (Column 4)
Anyone know how to do this?

You can take real proof of the calculation here:


I just need finish him… =/

If i do anything wrong, sorry… i just dont know i can’t do this
And so much thanks for anyone help me =) i have no ideia how do this.

Hey @Yukold!

I think I’d agree!! :joy:

A couple of quick questions:

  1. Do you have much/any experience with conditional probability or linear algebra?
  2. Is there a particular reason you need to build your own chip model simulator? Perhaps there is an API that can do the heavy lifting for you?
  3. Looking that the python script your have attached is should be possible to do this by yourself, but I’d break it down into smaller steps or functions to get started.
1 Like

Hi Domhnall!!

Haha so much hard for for someone without so much knowledge
So, answering your questions

I have a little experiencie with algebra in my school… a long time ago
No problem if have anything else can do it for me… i just need something working well =)
I put this python code for anyone understand and maybe can help me see this code, but i dont have any experience with this language or other, i never studied script/code or something else about it unfurtunately

Hey Domhnall, its possible do this algorithm in thunkable x? i tried many times but i maybe are thinking are impossible to do this…