for(idx = 0; idx < oi ; idx++) { if ( num_oth_turns[idx] != 0 && num_oth_turns[idx] < min) min = num_oth_turns[idx];
for(index = 0; index < orderedItems ; index++) { if ( num_normal_turns[index] != 0 && num_normal_turns[index] < min) min = num_normal_turns[index];
    public static TurnVectors generateTurnOrder(Vector v, boolean infAndProtosLast)    {	int[] num_inf_and_proto_turns = new int[v.size()];	int[] num_oth_turns = new int[v.size()];       	int total_inf_and_proto_turns = 0;	int total_oth_turns = 0;	int idx;        TurnOrdered[] order = new TurnOrdered[v.size()];        int oi = 0;        com.sun.java.util.collections.ArrayList plist = 	    new com.sun.java.util.collections.ArrayList(v.size());        for (Enumeration i = v.elements(); i.hasMoreElements();) {            Object item = i.nextElement();            plist.add(item);        }        com.sun.java.util.collections.Collections.sort(plist, new com.sun.java.util.collections.Comparator() {            public int compare(Object o1, Object o2) {                return ((TurnOrdered)o1).getInitiative().compareTo(((TurnOrdered)o2).getInitiative());            }        });        for (com.sun.java.util.collections.Iterator i = plist.iterator(); i.hasNext();) {            final TurnOrdered item = (TurnOrdered)i.next();            order[oi] = item;	    	    // If infantry/protos are last, separate them.            // Otherwise, place all 'turns' in one pile 	    if (infAndProtosLast) {		num_inf_and_proto_turns[oi] = item.getInfantryAndProtomechCount();		num_oth_turns[oi] = item.getTankCount() + item.getMechCount();	    } else {		num_inf_and_proto_turns[oi] = 0;		num_oth_turns[oi] = item.getTankCount() + 		    item.getMechCount() + item.getInfantryAndProtomechCount();	    }	    total_inf_and_proto_turns += num_inf_and_proto_turns[oi];	    total_oth_turns += num_oth_turns[oi];	    oi++;        }		int min;	int turns_left;	TurnVectors turns = new TurnVectors(total_oth_turns, total_inf_and_proto_turns);	// We will do the 'other' units first (mechs and vehicles, and        // if infAndProtosLast is false, infantry and protomechs)	min = Integer.MAX_VALUE;	for(idx = 0; idx < oi ; idx++) {	    if ( num_oth_turns[idx] != 0 && num_oth_turns[idx] < min)		min = num_oth_turns[idx];	}	turns_left = total_oth_turns;	while(turns_left > 0) {	    for(idx = 0; idx < oi; idx++) {		// If you have no turns here, skip		if (num_oth_turns[idx] == 0)		    continue;		/* If you have less than twice the lowest, move 1.  Otherwise, move more. */		int ntm = (int)Math.floor( ((double)num_oth_turns[idx]) / ((double)min) );		for (int j = 0; j < ntm; j++) {		    turns.non_infantry_non_protomechs.addElement(order[idx]);		    num_oth_turns[idx]--;		    turns_left--;		}		    	    }	    // Since the smallest unit count had to place 1, reduce min)	    min--;	}	// Now, we do the 'infantry/protomech' turns.	if (infAndProtosLast) {	    	    min = Integer.MAX_VALUE;	    for(idx = 0; idx < oi ; idx++) {		if ( num_inf_and_proto_turns[idx] != 0 && num_inf_and_proto_turns[idx] < min)		    min = num_inf_and_proto_turns[idx];	    }	    	    turns_left = total_inf_and_proto_turns;	    	    while(turns_left > 0) {		for(idx = 0; idx < oi; idx++) {		    // If you have no turns here, skip		    if (num_inf_and_proto_turns[idx] == 0)			continue;		    		    /* If you have less than twice the lowest, move 1.  Otherwise, move more. */		    int ntm = (int)Math.floor( ((double)num_inf_and_proto_turns[idx]) / ((double)min) );		    for (int j = 0; j < ntm; j++) {			turns.infantry_and_protomechs.addElement(order[idx]);			num_inf_and_proto_turns[idx]--;			turns_left--;		    }		    		}		// Since the smallest unit count had to place 1, reduce min)		min--;	    }	}	return turns;    }