public class Tournament
{
	private int cap;
	private int size;
	private Competitor[] competitors;
	private java.util.Random gen;
	private int numFights;

	public Tournament(int cap, int numFights)
	{	this.cap = cap;
		this.numFights = numFights;
		competitors = new Competitor[cap];
		size = 0;
		gen = new java.util.Random();
	}

	public void add(Competitor c)
	{	if (size < cap)
		{	competitors[size++] = c;
	}	}
	

	public Competitor get(int i) 
	{	if (i < 0 || size <= i)
		{	return null; // note: in Jasmin null is aconst_null
		}
		return competitors[i];
	}

	public void run() 
	{	for(int i = 0; i < numFights; i++)
		{	if (size <= 1)
			{	System.out.println("Too few competitors!");
				break;
			}
			int k = gen.nextInt(size);
			int j = gen.nextInt(size);
			if (k == j)
			{	j = (j + 1) % size;
			}
			Competitor c1 = get(k);
			Competitor c2 = get(j);
			c1.fight(c2);
			c2.fight(c1);
	}	}	

	public void display() 
	{	for(int i = 0; i < size; i++)
		{	System.out.println(get(i));
	}	}
	

	public static void main(String[] args)
	{	Tournament unreal = new Tournament(50, 100);
		for(int i = 0; i < unreal.size; i++) 
		{	if (i % 3 == 0)
			{	unreal.add(new Warrior("Warrior " + i));
			} else if (i % 3 == 1)
			{	unreal.add(new Dragon("Dragon " + i));
			} else
			{	unreal.add(new Robot("Robot " + i));
			}
		}
		unreal.run();
		unreal.display();
}	}