All pastes #179213 Raw Edit

Anonymous

public text v1 · immutable
#179213 ·published 2006-09-22 01:18 UTC
rendered paste body
package rockPaperScissors;
import java.util.ArrayList;
import java.util.Random;

public class JackBauerBot implements RPSStrategy {
	float round = 0;
	int rocks = 0;
	int paps = 0;
	int ss = 0;
	int op = 9;
	int thor;
	String move = "";
	int mine = 9;
	int r = 0;
	private Random generator;
	boolean isdummy = false;
	ArrayList hismoves;
	ArrayList mymoves;
	
	public JackBauerBot() 
	{
		reset();
	}
	
	public void reset() 
	{
		rocks = 0;
		paps = 0;
		ss = 0;
		round = 0;
		generator = new Random();
		isdummy = false;
		hismoves = new ArrayList();
		mymoves = new ArrayList();
		mymoves.add(r, new Integer(op));
	}

	public String getName() 
	{
		return "JackBauerBot";
	}

	public int nextThrow() 
	{
		round++;
		
		if (round < 50 || op == -1)
			mine = generator.nextInt(3);  //randomize for the first 15 turns or when i hit an invalid
		else if (round >= 50)
			if ((rocks/round) > .91 || (paps/round) > .91 || (ss/round) > .91)
				mine = (op + 1) % 3;
		
			if (isdummy)
			{
			if (op == 0)
			{
				op = 1;
				mymoves.add(r++, new Integer(op));
				return 1;
			}
			if (op == 1)
			{
				op = 2;
				mymoves.add(r++, new Integer(op));
				return 2;
			}
			if (op == 2)
			{
				op = 0;
				mymoves.add(r++, new Integer(op));
				return 0;
			}
			return -1;
			}
		
		mine = (op + 2) % 3;
		
		return mine;
	}

	public void opponentsLastThrow(int th)
	{
		r++;	
			if (th == -1)
				move = "invalid";
			if (th == 0)
			{
				rocks++;
				op = th;
			}
			if (th == 1)
			{
				paps++;
				op = th;
			}
			else
			{
				op = th;
				ss++;
			}
			hismoves.add(r, new Integer(th));
			if (hismoves.equals(mymoves))
			{
				isdummy = true;
			}
			else
			{
				isdummy = false;
			}
			
	}

}