class PRandom12 extends Strategy
{
    public int count, thisTake;

    // Bid 5 to start.
    public int initial_turn()
    {
        return 5;
    }

    // A tiny little turn-evaluator:
    int eval(int turns[], int carry, int scores[])
    {
        int i, j, sum, t, parts, t0;

        sum = carry;
        parts = 0;
        t0 = 0;
        for (i = 0; i < opponents; i++) if ( scores[i] > 0 )
        {
            if ( turns[i] > 0 )
            {
                sum  += turns[i];
                t = 0;
                for (j = 0; j < opponents; j++)
                {
                    if ( turns[j] > 0 && turns[i] >= turns[j] ) t++;
                }
                if (i == 0) t0 = t;
                parts   += t;
            }
        }
        sum += stepBonus;
        if ( parts == 0 ) return 0;
        return (int) ( sum * t0 ) / parts - turns[0];
    }


    public int turn(int last_turns[], int scores[], int carryOver, int turn_no)
    {
	// Assume everyone will bid 1 more
	for (count = 1; count < opponents; count++)
	{
	    if ((scores[count] < 1) && (last_turns[count] > 0)) last_turns[count]++;
	}

	// Try 25 times to find a big money making bid
	for (count = 1; count < 25; count++)
	{
            last_turns[0] = (int) ((Math.random() * 12) + 1);
            thisTake = eval(last_turns, carryOver, scores);
            if (thisTake > 1)
            {
                return(last_turns[0]);
            }
        }

	// Now try 25 times to find any money making bid
	for (count = 1; count < 25; count++)
	{
            last_turns[0] = (int) ((Math.random() * 12) + 1);
            thisTake = eval(last_turns, carryOver, scores);
            if (thisTake > 0)
            {
                return(last_turns[0]);
            }
        }

	// Give up.  Bid 1.
	return(1);
    }
}
