@Override
	public Move getMove() {
		int thinkingTime = 0;
		if (playerColour == Definitions.WHITE) {
			thinkingTime = 750;
		} else {
			thinkingTime = 750;
		}
		System.out.println("AI Thinking (" + thinkingTime / 1000.0 + " seconds)");
		long startTime = System.currentTimeMillis();
		long finishTime = System.currentTimeMillis();

		int depth = 1;
		Move move = null;
		Move[][] moves = new Move[depth][depth];
		Move[] previousMoves = null;
		currentBoard.generateMoves(playerColour);

		//Create the first thread and start it running.
		System.out.println("Running depth 1 search");
		Runnable search;
		if (playerColour == Definitions.WHITE) {
			search = new MiniMaxSearch2(currentBoard, playerColour, otherPlayerColour, depth, previousMoves, moves);
		} else {
			search = new MiniMaxSearch(currentBoard, playerColour, otherPlayerColour, depth, previousMoves, moves);
		}
		Thread t = new Thread(search);
		t.start();
		//Ensure the first thread completes
		try {
			t.join();
		} catch (InterruptedException ex) {
			Logger.getLogger(AIPlayer.class.getName()).log(Level.SEVERE, null, ex);
		}

		while (System.currentTimeMillis() - startTime < thinkingTime) {
			try {
				//if the thread has finished start another one
				if (t.getState() == State.TERMINATED) {
					move = moves[0][0];
					finishTime = System.currentTimeMillis();
					//System.out.println("Current best move is " + move.oldX + move.oldY + move.newX + move.newY);
					depth++;
					System.out.println("Trying depth " + depth);
					previousMoves = moves[0];
					moves = new Move[depth][depth];
					currentBoard.generateMoves(playerColour);
					if (playerColour == Definitions.WHITE) {
						search = new MiniMaxSearch2(currentBoard, playerColour, otherPlayerColour, depth, previousMoves, moves);
					} else {
						search = new MiniMaxSearch(currentBoard, playerColour, otherPlayerColour, depth, previousMoves, moves);
					}
					t = new Thread(search);
					t.start();
				}
				Thread.sleep(100);
			} catch (InterruptedException ex) {
				Logger.getLogger(AIPlayer.class.getName()).log(Level.SEVERE, null, ex);
			}
		}

		t.interrupt();
		try {
			t.join();
		} catch (InterruptedException ex) {
			Logger.getLogger(AIPlayer.class.getName()).log(Level.SEVERE, null, ex);
		}

		System.out.println("Terminating depth " + depth + " search");
		System.out.println("The move to be used is " + move.oldX + move.oldY + move.newX + move.newY);
		System.out.println("The " + (depth - 1) + " level search took " + (finishTime - startTime) / 1000.0 + " seconds");


		currentBoard.makeMove(move);

		return move;

	}