package jsettlers.ai.highlevel;

import jsettlers.logic.map.grid.MainGrid;
import jsettlers.network.client.interfaces.ITaskScheduler;

import java.util.ArrayList;
import java.util.List;


public class AiThread extends Thread {

	private final List<IWhatToDoAi> whatToDoAis;
	private boolean shutdownRequested;
	
	public AiThread(List<Byte> aiPlayers, MainGrid mainGrid, ITaskScheduler taskScheduler) {
		shutdownRequested = false;
		this.whatToDoAis = new ArrayList<IWhatToDoAi>();
		for (byte playerId : aiPlayers) {
			whatToDoAis.add(new WhatToDoAi(playerId, mainGrid, taskScheduler));
		}
	}
	
	@Override
	public void run() {
		System.out.println("AI Thread started");
		while (!shutdownRequested) {
			try {
				for (IWhatToDoAi whatToDoAi: whatToDoAis) {
					whatToDoAi.applyRules();
				}
				AiThread.sleep(3000l);
			} catch (InterruptedException e) {
				//continiue and then return run
			}
		}
		System.out.println("AI Thread finished");
	}
	
	public void shutdown() {
		shutdownRequested = true;
	}

}

@@ -207,22 +207,27 @@
 ead 
-extends Thread
+implements Runnable
  %7B%0A%0A
@@ -799,18 +799,16 @@
 %09%09%7D%0A%09%09%09%09
-Ai
 Thread.s
@@ -952,16 +952,74 @@
 );%0A%09%7D%0A%09%0A
+%09public void start() %7B%0A%09%09(new Thread(this)).start();%0A%09%7D%0A%09%0A
 %09public 

make AiThread Runnable instead of extending Thread