class Storm extends Strategy
{
    public int count, thisTake, bestTake, bestBid, nudge;

    // Bid 4 to start.
    public int initial_turn()
    {
        return 4;
    }


    // 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)
    {
	// Store the actions of every bidder away for future reference,
	// and set the expected next bids
	for (count = 1; count < opponents; count++)
	{
	    if (scores[count] < 1) last_turns[count] = 0;
	    else if (last_turns[count] > 0) last_turns[count]++;
	}
	
	// Now find the best bid given the assumed bids
	bestTake = 0;
	bestBid = 0;
	for (count = 1; count < maxPlayableNumber; count++)
	{
            last_turns[0] = count;
            thisTake = eval(last_turns, carryOver, scores);
            if (thisTake > bestTake)
            {
                bestBid = count;
		bestTake = thisTake;
            }
        }

	// 1/4 of the time add 1 to the bid for confusion's sake
	nudge = (int) ((Math.random() * 7.0) / 3);

	// Make sure we return a valid bid
	if ((bestBid + nudge) > maxPlayableNumber) nudge =0;

	// Now bid...
	return (bestBid + nudge);
    }
}
