class Focus extends Shark5
{
	public int initial_turn() { return 8; }

	final int brain = 250;
	hist hh[];
	int temp[];

	void priv_init()
	{
		int i;

		hh = new hist[brain];
		for (i = 0; i < brain; i++)
		{
			hh[i] = new hist(opponents);
		}
		temp = new int[opponents];
	}

	int sqr(int x) { return x * x; }

	public int turn(int last_turns[], int scores[],
					int carryOver, int turn_no)
	{
		int i, i0, w, w0, j, k, k2;
		int di, di1, di2, a1, a2;
		int lead1, lead2, lead3;

		// Determine the top players
		lead1 = lead2 = lead3 = 0;
		for (i = 1; i < opponents; i++)
		{
			if ( scores[i] > scores[lead1] )
			{
				lead3 = lead2;
				lead2 = lead1;
				lead1 = i;
			}
			else if ( scores[i] > scores[lead2] )
			{
				lead3 = lead2;
				lead2 = i;
			}
			else if ( scores[i] > scores[lead3] )
			{
				lead3 = i;
			}
		}

		// Remember the history
		k = ( turn_no - 1 ) % brain;
		for (i = 0; i < opponents; i++) hh[k].lt[i] = last_turns[i];
		hh[k].carry = carryOver;

		// Simple reply as base-strategy
      i0 = 0;
		w0 = -2147483647;
		for (i = 0; i <= maxPlayableNumber; i++)
		{
		   last_turns[0] = i;
		   w = eval(last_turns, carryOver, scores);
		   if ( w > w0 )
		   {
			   w0 = w;
			   i0 = i;
		   }
		}

		// Try s.th. better later
		// (this is for tactical and indexing reasons!)
		if ( turn_no > 12 )
		{
			//
			// Find the closest matching old situations!
			//
			j = 2;
			k = turn_no - j;
			// Fill the hit-list with default strategies
			di1 = di2 = -2147483647; // dummy scores
			a1 = a2 = k;                // turns
			while ( k > 0 && j < brain )
			{
				k = turn_no - j;
				k2 = k % brain;
				//
				// Calculate distance to previous situation
				//
				di = sqr(carryOver - hh[k2].carry) / 2
					+ sqr(hh[k2].lt[lead1] - last_turns[lead1])*3/2
					+ sqr(hh[k2].lt[lead2] - last_turns[lead2])
					+ sqr(hh[k2].lt[lead3] - last_turns[lead3])
					+ sqr(hh[k2].lt[lead1] - last_turns[lead1]
					    + hh[k2].lt[lead2] - last_turns[lead2]
					    + hh[k2].lt[lead3] - last_turns[lead3])/3
					;
				di = - di;
				if ( di > di2 )
				{
					if ( di > di1 )
					{
						a2 = a1;
						di2 = di1;
						a1 = k2;
						di1 = di;
					}
					else
					{
						di2 = di;
						a2  = k2;
					}
				}
				j++;
			}
			//
			// Look if any of the favourites past strategies
			// can beet the default one.
			//
			k2 = ( a1 + 1 ) % brain;
			for (i = 1; i < opponents; i++ ) temp[i] = hh[k2].lt[i];
			temp[0] = hh[k2].lt[lead3];
			w  = eval(temp, carryOver, scores);
			if ( w >= w0 )
			{
				w0 = w;
				i0 = temp[0];
			}
			temp[0] = hh[k2].lt[lead2];
			w  = eval(temp, carryOver, scores);
			if ( w >= w0 )
			{
				w0 = w;
				i0 = temp[0];
			}
			temp[0] = hh[k2].lt[lead1];
			w  = eval(temp, carryOver, scores);
			if ( w >= w0 )
			{
				w0 = w;
				i0 = temp[0];
			}
		}

		// done
		return i0;
	}
}

// Eine Variante von Focus
class Focus2 extends Focus
{
	public int initial_turn() { return 8; }

	final int brain = 500;
	hist hh[];
	int temp[], temp2[];

	void priv_init()
	{
		int i;

		hh = new hist[brain];
		for (i = 0; i < brain; i++)
		{
			hh[i] = new hist(opponents);
		}
		temp  = new int[opponents];
		temp2 = new int[opponents];
	}

	int sqr(int x) { return x * x; }

	public int turn(int last_turns[], int scores[],
					int carryOver, int turn_no)
	{
		int i, i0, w, w0, j, k, k2;
		int di, di1, di2, a1, a2;
		int lead1, lead2, lead3;

		// Determine the top players (including self!)
		lead1 = lead2 = lead3 = -1;
		for (i = 0; i < opponents; i++)
		{
			if ( lead1 == -1 || scores[i] > scores[lead1] )
			{
				lead3 = lead2;
				lead2 = lead1;
				lead1 = i;
			}
			else if (  lead2 == -1 ||scores[i] > scores[lead2] )
			{
				lead3 = lead2;
				lead2 = i;
			}
			else if ( lead3 == -1 || scores[i] > scores[lead3] )
			{
				lead3 = i;
			}
		}
		// Focus on yourself when there is noone else
		if ( lead3 == - 1 ) lead3 = 0;
		if ( lead2 == - 1 ) lead2 = 0;
		if ( lead1 == - 1 ) lead1 = 0;


		// Remember the history
		k = ( turn_no - 1 ) % brain;
		for (i = 0; i < opponents; i++) hh[k].lt[i] = last_turns[i];
		hh[k].carry = carryOver;

		// Try s.th. better later
		// (this is for tactical and indexing reasons!)
		if ( turn_no < 2 )
		{
			i0 = 8;
		}
		else
		{
			//
			// Find the closest matching old situations!
			//
			j = 2;
			k = turn_no - j;
			//
			// Fill the hit-list with dummy hits!
			a1 = k;
			di1= -340;
			a2 = k == 0 ? ( turn_no > 2 ? brain-1 : 0 ) : k - 1;
			di2 = -500;
			while ( k > 0 && j < brain )
			{
				k = turn_no - j;
				k2 = k % brain;
				//
				// Calculate distance to previous situation
				//
				di = sqr(carryOver - hh[k2].carry) / 3
					+ sqr(hh[k2].lt[lead1] - last_turns[lead1])*3/2
					+ sqr(hh[k2].lt[lead2] - last_turns[lead2])
					+ sqr(hh[k2].lt[lead3] - last_turns[lead3])
					+ sqr(hh[k2].lt[lead1] - last_turns[lead1]
					    + hh[k2].lt[lead2] - last_turns[lead2]
					    + hh[k2].lt[lead3] - last_turns[lead3])/3
					;
				di = - di;
				if ( di > di2 )
				{
					if ( di > di1 )
					{
						a2 = a1;
						di2 = di1;
						a1 = k2;
						di1 = di;
					}
					else
					{
						di2 = di;
						a2  = k2;
					}
				}
				j++;
			}
			// The matching positions leed to two
			// predicted positions:
		   k  = ( a1 + 1 ) % brain;
		   k2 = ( a2 + 1 ) % brain;
			for (i = 1; i < opponents; i++)
			{
				temp [i] = hh[k ].lt[i];
				temp2[i] = hh[k2].lt[i];
			}
			// Find the most competitive turn in the
			// predicted situations:
			w0 = - 4*maxPlayableNumber;
			i0 = 0;
			j = 1;
			for (i = 0; i <= maxPlayableNumber; i++)
			{
				temp[0] = temp2[0] = i;
				w = 2*eval(temp, carryOver, scores)
				   +  eval(temp2,carryOver, scores);
				j = ( w == w0 ) ? j+1 : 1;
				if ( w > w0
					|| ( w == w0 && Math.random()*j >= 1.0 )
						)
				{
					w0 = w;
					i0 = i;
				}
			}
		}

		// done
		return i0;
	}
}

// Eine Variante von Focus
class Focus3 extends Focus2
{
	public int initial_turn() { return 0; }

	final int score_dummy1 = -340;
	final int score_dummy2 = -500;

	public int turn(int last_turns[], int scores[],
					int carryOver, int turn_no)
	{
		int i, i0, w, w0, j, k, k2;
		int di, di1, di2, a1, a2;
		int lead1, lead2, lead3;
		int p1, p2;

		// Determine the top players (including self!)
		lead1 = lead2 = lead3 = -1;
		for (i = 0; i < opponents; i++)
		{
			if ( lead1 == -1 || scores[i] > scores[lead1] )
			{
				lead3 = lead2;
				lead2 = lead1;
				lead1 = i;
			}
			else if (  lead2 == -1 ||scores[i] > scores[lead2] )
			{
				lead3 = lead2;
				lead2 = i;
			}
			else if ( lead3 == -1 || scores[i] > scores[lead3] )
			{
				lead3 = i;
			}
		}
		// Focus on yourself when there is noone else
		if ( lead3 == - 1 ) lead3 = 0;
		if ( lead2 == - 1 ) lead2 = 0;
		if ( lead1 == - 1 ) lead1 = 0;

		// Remember the history
		k = ( turn_no - 1 ) % brain;
		for (i = 0; i < opponents; i++) hh[k].lt[i] = last_turns[i];
		hh[k].carry = carryOver;

		// Try s.th. better later
		// (this is for tactical and indexing reasons!)
		if ( turn_no < 2 )
		{
			i0 = 1;
		}
		else
		{
			//
			// Find the closest matching old situations!
			//
			j = 2;
			k = turn_no - j;
			//
			// Fill the hit-list with dummy hits!
			a1 =  k >= 0 ? k : 0;
			di1= score_dummy1;
			a2 = k >= 0
				  ? k == 0 ? ( turn_no > 2 ? brain-1 : 0 ) : k - 1
				  : 0;
			di2 = score_dummy2;
			while ( k > 0 && j < brain )
			{
				k = turn_no - j;
				k2 = k % brain;
				//
				// Calculate distance to previous situation
				//
				di = sqr(carryOver - hh[k2].carry) / 3
					+ sqr(hh[k2].lt[lead1] - last_turns[lead1])*3/2
					+ sqr(hh[k2].lt[lead2] - last_turns[lead2])
					+ sqr(hh[k2].lt[lead3] - last_turns[lead3])
					+ sqr(hh[k2].lt[lead1] - last_turns[lead1]
					    + hh[k2].lt[lead2] - last_turns[lead2]
					    + hh[k2].lt[lead3] - last_turns[lead3])/3
					;
				di = - di;
				if ( di > di2 )
				{
					if ( di > di1 )
					{
						a2 = a1;
						di2 = di1;
						a1 = k2;
						di1 = di;
					}
					else
					{
						di2 = di;
						a2  = k2;
					}
				}
				j++;
			}
			// The matching positions leed to two
			// predicted positions:
		   k  = ( a1 + 1 ) % brain;
		   k2 = ( a2 + 1 ) % brain;
			for (i = 1; i < opponents; i++)
			{
				temp [i] = hh[k ].lt[i];
				temp2[i] = hh[k2].lt[i];
			}
			// Find the most competitive turn in the
			// predicted situations:
			w0 = - 4*maxPlayableNumber;
			i0 = 0;
			j = 1;
			if ( 3*di1 < di2 && di2 > score_dummy1 )
			{
				p1 = 2;
				p2 = 1;
			}
			else
			{
				p1 = 5;
				p2 = 1;
			}
			for (i = 0; i <= maxPlayableNumber; i++)
			{
				temp[0] = temp2[0] = i;
				w = ( p1*eval(temp, carryOver, scores)
				     +p2*eval(temp2,carryOver, scores))
					 /(p1+p2)/2;
				j = ( w == w0 )? j+1 : 1;
				if ( w > w0
					|| ( w == w0 && Math.random()*j >= 1.0 )
						)
				{
					w0 = w;
					i0 = i;
				}
			}
		}
		return i0;
	}
}


// Eine Variante von Focus
class Focus4 extends Focus2
{
	public int initial_turn() { return 2; }

	final int score_dummy1 = -340;
	final int score_dummy2 = -500;

	int lt[];

	void priv_init()
	{
		int i;

		hh = new hist[brain];
		for (i = 0; i < brain; i++)
		{
			hh[i] = new hist(opponents);
		}
		temp  = new int[opponents];
		temp2 = new int[opponents];
		lt    = new int[opponents];
	}

	public int turn(int last_turns[], int scores[],
					int carryOver, int turn_no)
	{
		int i, i0, w, w0, j, k, k2;
		int di, di1, di2, a1, a2;
		int lead1, lead2, lead3;
		int p1, p2, p3, p4;
		double pw;

		// Determine the top players (including self!)
		lead1 = lead2 = lead3 = -1;
		for (i = 0; i < opponents; i++)
		{
			if ( lead1 == -1 || scores[i] > scores[lead1] )
			{
				lead3 = lead2;
				lead2 = lead1;
				lead1 = i;
			}
			else if (  lead2 == -1 ||scores[i] > scores[lead2] )
			{
				lead3 = lead2;
				lead2 = i;
			}
			else if ( lead3 == -1 || scores[i] > scores[lead3] )
			{
				lead3 = i;
			}
		}
		// Focus on yourself when there is noone else
		if ( lead1 == - 1 ) lead1 = 0;
		if ( lead2 == - 1 ) lead2 = lead1;
		if ( lead3 == - 1 ) lead3 = lead2;


		// Remember the history
		k = ( turn_no - 1 ) % brain;
		for (i = 0; i < opponents; i++) hh[k].lt[i] = last_turns[i];
		hh[k].carry = carryOver;

		// Try s.th. better later
		// (this is for tactical and indexing reasons!)
		if ( turn_no < 2 )
		{
			i0 = 4;
		}
		else
		{
			//
			// Find the closest matching old situations!
			//
			j = 2;
			k = turn_no - j;
			//
			// Fill the hit-list with dummy hits!
			a1 =  k >= 0 ? k : 0;
			di1= score_dummy1;
			a2 = k >= 0
				  ? k == 0 ? ( turn_no > 2 ? brain-1 : 0 ) : k - 1
				  : 0;
			di2 = score_dummy2;
			while ( k > 0 && j < brain )
			{
				k = turn_no - j;
				k2 = k % brain;
				//
				// Calculate distance to previous situation
				//
				di = sqr(carryOver - hh[k2].carry) 
					+ sqr(hh[k2].lt[lead1] - last_turns[lead1])*4
					+ sqr(hh[k2].lt[lead2] - last_turns[lead2])*3
					+ sqr(hh[k2].lt[lead3] - last_turns[lead3])*2
					+ sqr(hh[k2].lt[lead1] - last_turns[lead1]
					    + hh[k2].lt[lead2] - last_turns[lead2]
					    + hh[k2].lt[lead3] - last_turns[lead3])/2
					;
				di = - di;
				if ( di > di2 )
				{
					if ( di > di1 )
					{
						a2 = a1;
						di2 = di1;
						a1 = k2;
						di1 = di;
					}
					else
					{
						di2 = di;
						a2  = k2;
					}
				}
				j++;
			}
			// The matching positions leed to two
			// predicted positions:
		        k  = ( a1 + 1 ) % brain;
		        k2 = ( a2 + 1 ) % brain;
			for (i = 1; i < opponents; i++)
			{
				temp [i] = hh[k ].lt[i];
				temp2[i] = hh[k2].lt[i];
			}
			// Find the most competitive turn in the
			// predicted situations:
			w0 = - 4*maxPlayableNumber;
			i0 = 0;
			j = 1;
			// Komisches Kriterium?!
			pw = 0.75;
			//
			if ( turn_no > 100 && turn_no < 350 )
			{
				p1 = 0;
				p2 = 0;
				p3 = 2;
				p4 = 1;
				pw = 0.1;
			}
			else if ( 3*di1 < di2 && di2 > score_dummy1 )
			{
				p1 = 20;
				p2 = 10;
				p3 =  0;
				p4 =  0;
			}
			else
			{
				p1 = 40;
				p2 =  9;
				p3 =  1;
				p4 =  0;
			}
			for (i = 0; i <= maxPlayableNumber; i++)
			{
				temp[0] = temp2[0] = last_turns[0] = lt[0] = i;
				w = ( p1*eval(temp      , carryOver, scores)
				     +p2*eval(temp2     , carryOver, scores)
				     +p3*eval(last_turns, carryOver, scores)
				     +p4*eval(   lt     , carryOver, scores)
				    )
				    ;
				j = ( w == w0 )? j+1 : 1;
				if ( w > w0
					// Auswahl bei Gleichstand mit Bias?!
					// Die Konstante scheint kritisch und
					// ist ein wenig ausoptimiert :-)
					// pur 0.75 besser aber mit Shark7 ?
					|| ( w == w0 && Math.random()*j >= pw )
						)
				{
					w0 = w;
					i0 = i;
				}
			}
		}
		for (i = 1; i < opponents; i++) lt[i] = last_turns[i];
		return i0;
	}
}

// Eine aggressivere Variante von Focus
class FocuTak extends Focus2
{
	public int initial_turn() { return 0; }

	final int score_dummy1 = -340;
	final int score_dummy2 = -500;

	public int turn(int last_turns[], int scores[],
					int carryOver, int turn_no)
	{
		int i, i0, i1, w, w0, j, k, k2, k3, k4;
		int di, di1, di2, a1, a2;
		int lead1, lead2, lead3;
		int p1, p2;

		// Determine the top players (including self!)
		lead1 = lead2 = lead3 = -1;
		for (i = 0; i < opponents; i++)
		{
			if ( lead1 == -1 || scores[i] > scores[lead1] )
			{
				lead3 = lead2;
				lead2 = lead1;
				lead1 = i;
			}
			else if (  lead2 == -1 ||scores[i] > scores[lead2] )
			{
				lead3 = lead2;
				lead2 = i;
			}
			else if ( lead3 == -1 || scores[i] > scores[lead3] )
			{
				lead3 = i;
			}
		}
		// Focus on yourself when there is noone else
		if ( lead3 == - 1 ) lead3 = 0;
		if ( lead2 == - 1 ) lead2 = 0;
		if ( lead1 == - 1 ) lead1 = 0;


		// Remember the history
		k = ( turn_no - 1 ) % brain;
		for (i = 0; i < opponents; i++) hh[k].lt[i] = last_turns[i];
		hh[k].carry = carryOver;

		// Try s.th. better later
		// (this is for tactical and indexing reasons!)
		if ( turn_no < 2 )
		{
			i0 = 1;
		}
		else
		{
			//
			// Find the closest matching old situations!
			//
			j = 2;
			k = turn_no - j;
			//
			// Fill the hit-list with dummy hits!
			a1 =  k >= 0 ? k : 0;
			di1= score_dummy1;
			a2 = k >= 0
				  ? k == 0 ? ( turn_no > 2 ? brain-1 : 0 ) : k - 1
				  : 0;
			di2 = score_dummy2;
			while ( k > 0 && j < brain )
			{
				k = turn_no - j;
				k2 = k % brain;
				//
				// Calculate distance to previous situation
				//
				di = Math.abs(carryOver - hh[k2].carry)
					+ sqr(hh[k2].lt[lead1] - last_turns[lead1]) * 2 // *3/2
					+ sqr(hh[k2].lt[lead2] - last_turns[lead2])
					+ sqr(hh[k2].lt[lead3] - last_turns[lead3])
					+ sqr(hh[k2].lt[lead1] - last_turns[lead1]
					    + hh[k2].lt[lead2] - last_turns[lead2]
					    + hh[k2].lt[lead3] - last_turns[lead3])/6 // /3
					;
				di = - di;
				if ( di > di2 )
				{
					if ( di > di1 )
					{
						a2 = a1;
						di2 = di1;
						a1 = k2;
						di1 = di;
					}
					else
					{
						di2 = di;
						a2  = k2;
					}
				}
				j++;
			}
			// The matching positions leed to two
			// predicted positions:
		   k  = ( a1 + 1 ) % brain;
		   k2 = ( a2 + 1 ) % brain;
			for (i = 1; i < opponents; i++)
			{
				temp [i] = hh[k ].lt[i];
				temp2[i] = hh[k2].lt[i];
			}
			// Find the most competitive turn in the
			// predicted situations:
			w0 = - 4*maxPlayableNumber;
			i0 = 0;
			j = 1;
			if ( 3*di1 < di2 && di2 > score_dummy1 )
			{
				p1 = 2;
				p2 = 1;
			}
			else
			{
				p1 = 5;
				p2 = 1;
			}
			// Since we realized we got stuck in a 99 stalemate,
			// we do not play 99 arbitrarily often!!
			k  = ( turn_no - 1 ) % brain;
			k2 = ( turn_no - 2 ) % brain;
			k3 = ( turn_no - 3 ) % brain;
			k4 = ( turn_no - 4 ) % brain;
			i1 = maxPlayableNumber;
			if (   turn_no > 3
				&& hh[k4].lt[0] == maxPlayableNumber
				&& hh[k3].lt[0] == maxPlayableNumber
				&& hh[k2].lt[0] == maxPlayableNumber
				&& hh[k ].lt[0] == maxPlayableNumber
				&& Math.random() < 0.5 ) i1--;
			for (i = 0; i <= i1; i++)
			{
				temp[0] = temp2[0] = i;
				w = ( p1*eval(temp, carryOver, scores)
				     +p2*eval(temp2,carryOver, scores))
					 /(p1+p2)/2;
				j = ( w == w0 )? j+1 : 1;
				if ( w > w0
					|| ( w == w0
					  && ( i != maxPlayableNumber || lead1 == 0 )
					  && Math.random()*j >= 1.0 )
						)
				{
					w0 = w;
					i0 = i;
				}
			}
			if ( false )
			{
				System.out.println("ft: "
						+last_turns[lead1]+" "
						+last_turns[lead2]+" "
						+last_turns[lead3]
						+" = "
						+hh[a1].lt[lead1]+","
						+hh[a1].lt[lead2]+","
						+hh[a1].lt[lead3]+" "
						+" -> "
						+hh[k ].lt[lead1]+" "
						+hh[k ].lt[lead2]+" "
						+hh[k ].lt[lead3]+" "
						+" ("+di1+","+di2+") "
						+" "+i0
						+" "+w0
						+" ("+j+")"
					);
			}
		}

		// done
		return i0;
	}
}


// Eine aggressivere Variante von Focus
class FocuN2 extends Focus2
{
	public int initial_turn() { return 0; }

	final int score_dummy1 = -340;
	final int score_dummy2 = -500;

	public int turn(int last_turns[], int scores[],
					int carryOver, int turn_no)
	{
		int i, i0, i1, w, w0, j, k, k2, k3, k4;
		int di, di1, di2, a1, a2;
		int lead1, lead2;
		int p1, p2;

		// Determine the top players (including self!)
		lead1 = lead2 = -1;
		for (i = 0; i < opponents; i++)
		{
			if ( lead1 == -1 || scores[i] > scores[lead1] )
			{
				lead2 = lead1;
				lead1 = i;
			}
			else if (  lead2 == -1 ||scores[i] > scores[lead2] )
			{
				lead2 = i;
			}
		}
		// Focus on yourself when there is noone else
		if ( lead2 == - 1 ) lead2 = 0;
		if ( lead1 == - 1 ) lead1 = 0;


		// Remember the history
		k = ( turn_no - 1 ) % brain;
		for (i = 0; i < opponents; i++) hh[k].lt[i] = last_turns[i];
		hh[k].carry = carryOver;

		// Try s.th. better later
		// (this is for tactical and indexing reasons!)
		if ( turn_no < 2 )
		{
			i0 = 1;
		}
		else
		{
			//
			// Find the closest matching old situations!
			//
			j = 2;
			k = turn_no - j;
			//
			// Fill the hit-list with dummy hits!
			a1 =  k >= 0 ? k : 0;
			di1= score_dummy1;
			a2 = k >= 0
				  ? k == 0 ? ( turn_no > 2 ? brain-1 : 0 ) : k - 1
				  : 0;
			di2 = score_dummy2;
			while ( k > 0 && j < brain )
			{
				k = turn_no - j;
				k2 = k % brain;
				//
				// Calculate distance to previous situation
				//
				di = sqr(carryOver - hh[k2].carry) / 3
					+ sqr(hh[k2].lt[lead1] - last_turns[lead1]) *3/2
					+ sqr(hh[k2].lt[lead2] - last_turns[lead2])
					+ sqr(hh[k2].lt[lead1] - last_turns[lead1]
					    + hh[k2].lt[lead2] - last_turns[lead2])/3 // /3
					;
				di = - di;
				if ( di > di2 )
				{
					if ( di > di1 )
					{
						a2 = a1;
						di2 = di1;
						a1 = k2;
						di1 = di;
					}
					else
					{
						di2 = di;
						a2  = k2;
					}
				}
				j++;
			}
			// The matching positions leed to two
			// predicted positions:
		   k  = ( a1 + 1 ) % brain;
		   k2 = ( a2 + 1 ) % brain;
			for (i = 1; i < opponents; i++)
			{
				temp [i] = hh[k ].lt[i];
				temp2[i] = hh[k2].lt[i];
			}
			// Find the most competitive turn in the
			// predicted situations:
			w0 = - 4*maxPlayableNumber;
			i0 = 0;
			j = 1;
			if ( 3*di1 < di2 && di2 > score_dummy1 )
			{
				p1 = 2;
				p2 = 1;
			}
			else
			{
				p1 = 5;
				p2 = 1;
			}
			// Since we realized we got stuck in a 99 stalemate,
			// we do not play 99 arbitrarily often!!
			k  = ( turn_no - 1 ) % brain;
			k2 = ( turn_no - 2 ) % brain;
			k3 = ( turn_no - 3 ) % brain;
			k4 = ( turn_no - 4 ) % brain;
			i1 = maxPlayableNumber;
			if (   turn_no > 3
				&& hh[k4].lt[0] == maxPlayableNumber
				&& hh[k3].lt[0] == maxPlayableNumber
				&& hh[k2].lt[0] == maxPlayableNumber
				&& hh[k ].lt[0] == maxPlayableNumber
				&& Math.random() < 0.5 ) i1--;
			for (i = 0; i <= i1; i++)
			{
				temp[0] = temp2[0] = i;
				w = ( p1*eval(temp, carryOver, scores)
				     +p2*eval(temp2,carryOver, scores))
					 /(p1+p2)/2;
				j = ( w == w0 )? j+1 : 1;
				if ( w > w0
					|| ( w == w0
					  && ( i != maxPlayableNumber || lead1 == 0 )
					  && Math.random()*j >= 1.0 )
						)
				{
					w0 = w;
					i0 = i;
				}
			}
			if ( false )
			{
				System.out.println("ft: "
						+last_turns[lead1]+" "
						+last_turns[lead2]+" "
						+" = "
						+hh[a1].lt[lead1]+","
						+hh[a1].lt[lead2]+","
						+" -> "
						+hh[k ].lt[lead1]+" "
						+hh[k ].lt[lead2]+" "
						+" ("+di1+","+di2+") "
						+" "+i0
						+" "+w0
						+" ("+j+")"
					);
			}
		}

		// done
		return i0;
	}
}

