class BlueStreak extends Strategy
{
    public int count, othercount, leader, leadScore, leadBid;
    public int lastLeadBid, onetwothree, min, lastCarry;
    public int history[][];

    void priv_init()
    {
        history = new int[maxPlayableNumber][opponents];
        lastCarry = 0;
        leadBid = 0;

        for (count = 0; count < maxPlayableNumber; count++)
        {
            for (othercount = 0; othercount < opponents; othercount++)
            {
                history[count][othercount] = 0;
            }
        }
    }

    // Bid 3 to start.
    public int initial_turn()
    {
        return 3;
    }

    public int turn(int last_turns[], int scores[], int carryOver, int turn_no)
    {
        // BlueStreak assumes that the leader (excluding itself) will make the
        // same bid it did last time, given a particular most recent bid and
        // a particular carryover.  If BlueStreak is the leader, it will
        // match the expected bid of the second place player.  If BlueStreak
        // is _not_ leading, it will bid one more than the anticipated bid.

        // What did the leader bid two turns ago?
        lastLeadBid = leadBid;

        // Find the leader, plus some additional information with which to
        // choose a bid should there be no previous bid stored for this case.
        leadScore = 0;
        leader = 0;
        onetwothree = 0;
        min = 100;
        for (count = 1; count < opponents; count++)
        {
            // Find the leader, and their score
            if (scores[count] > leadScore)
            {
                leadScore = scores[count];
                leader = count;
            }

            // If this player bid something...
            if (last_turns[count] > 0)
            {
                // ...count it if it was in the range of 1-3
                if (last_turns[count] < 4) onetwothree++;

                // ...and check to see if it was the low bid
                if (last_turns[count] < min) min = last_turns[count];
            }
        }

        // What did the leader bid last turn?
        leadBid = last_turns[leader];

        // OK, now store the bid so that we know what to do next time

        history[lastLeadBid][lastCarry] = leadBid;

        // Set lastCarry for the next turn

        lastCarry = carryOver;

        // Now choose my bid...

        if (history[leadBid][carryOver] > 0)
        {
            // OK, there's a bid stored.  If I'm in first, bid it.
            if (scores[0] > leadScore) return (history[leadBid][carryOver]);

            // Otherwise, bid one more...
            else return (history[leadBid][carryOver] + 1);
        }

        // Darn.  Nothing stored.  OK, revert to SomeOne (not expected to
        // happen frequently)
        else if (onetwothree > 2) return (leadBid+1);

        // If there are _no_ low bids about, follow the Const1 strategy
        else if (onetwothree == 0) return 1;

        // If just _one_ other bidder has bid in the 1-3 range, we want
        // to top _that_ bid
        else return (min+1);
    }
}

