public void evaluate(int times)
	{

		if (times < 0)
		{
			whitePass = true;
			current = true;
			return;
		}
		Piece[][] backup = new Piece[9][9];
		for (int i = 0; i < 9; i++)
			for (int j = 0; j < 9; j++)
				backup[i][j] = squares[i][j].piece;
		double oldBS = this.blackScore;
		double oldWS = this.whiteScore;
		double blackScore = this.blackScore;
		double whiteScore = this.whiteScore;
		processTerritories();
		for (TerritoryAi t : territories)
		{
			switch (t.team())
			{
				case 0:
					continue;
				case 1:
					blackScore += t.squares.size();
					break;
				case 2:
					whiteScore += t.squares.size();

			}
		}
		int[][] scores = new int[9][9];
		for (int i = 0; i < 9; i++)
		{
			for (int j = 0; j < 9; j++)
			{

				if (squares[i][j].piece != null)
				{
					scores[i][j] = -12345;
				}
				else
				{
					squares[i][j].piece = new Piece(false, squares[i][j]);
					processGroups();
					capture();
					processTerritories();
					for (TerritoryAi t : territories)
					{
						switch (t.team())
						{
							case 0:
								continue;
							case 1:
								this.blackScore += t.squares.size();
								break;
							case 2:
								this.whiteScore += t.squares.size();

						}
					}
					int wliberties = 0;
					int bliberties = 0;
					int whiteGroups = 0;
					int blackGroups = 0;
					for (GroupAi g : groups)
					{
						if (g.pieces.toArray(new Piece[0])[0].team)
						{
							bliberties += g.pieces.size();
							blackGroups++;
						}
						else
						{
							wliberties += g.pieces.size();
							whiteGroups++;
						}
					}
					scores[i][j] = (int) (5 * (blackScore - this.blackScore + this.whiteScore - whiteScore) + 1.5 * (wliberties) + 8 * (-bliberties) + 12 * (-3 * (blackGroups) - .5 * (whiteGroups)));
					for (int x = 0; x < 9; x++)
					{
						for (int y = 0; y < 9; y++)
						{
							squares[x][y].piece = backup[x][y];
						}

					}
					this.blackScore = oldBS;
					this.whiteScore = oldWS;
				}

			}

		}
		int[] score2 = new int[81];
		for (int i = 0; i < 9; i++)
		{
			for (int j = 0; j < 9; j++)
			{
				score2[j + i * 9] = scores[i][j];
			}
		}
		int topScore = -2147483647;
		ArrayList<Integer> finalx = new ArrayList<Integer>();
		ArrayList<Integer> finaly = new ArrayList<Integer>();
		for (int i = 0; i < 81; i++)
		{
			if (topScore < score2[i] && score2[i] != -12345)
			{
				topScore = score2[i];
			}
		}
		for (int i = 0; i < 81; i++)
		{
			if (score2[i] == topScore)
			{
				finalx.add(i / 9);
				finaly.add(i % 9);
			}
		}

		if (finalx.size() == 0)
		{
			whitePass = true;
			current = true;
			int[][] copy = new int[9][9];
			for (int i = 0; i < squares.length; i++)
				for (int j = 0; j < squares[0].length; j++)
				{
					if (squares[i][j].piece == null)
					{
						copy[i][j] = -1;

					}
					else if (squares[i][j].piece.team)
					{
						copy[i][j] = 1;

					}
					else
						copy[i][j] = 0;
				}
			ko.add(copy);

			return;
		}
		int finalX = finalx.get((int) (Math.random() * finalx.size()));
		int finalY = finaly.get((int) (Math.random() * finaly.size()));

		if (squares[finalX][finalY].piece == null)
		{
			squares[finalX][finalY].piece = new Piece(false, squares[finalX][finalY]);
			processGroups();
			capture();
			int[][] copy = new int[9][9];
			for (int i = 0; i < squares.length; i++)
				for (int j = 0; j < squares[0].length; j++)
				{
					if (squares[i][j].piece == null)
					{
						copy[i][j] = -1;

					}
					else if (squares[i][j].piece.team)
					{
						copy[i][j] = 1;

					}
					else
						copy[i][j] = 0;
				}
			outside: for (int[][] c : ko)
			{
				for (int i = 0; i < 9; i++)
				{
					for (int j = 0; j < 9; j++)
					{
						if (copy[i][j] != c[i][j])
							continue outside;
					}
				}
				squares[finalX][finalY].piece = null;
				evaluate(times - 1);
			}

			int numBlack = 0;
			for (int i = 0; i < 9; i++)
			{
				for (int j = 0; j < 9; j++)
				{
					if (squares[i][j].piece != null && squares[i][j].piece.team)
						numBlack++;
				}
			}
			if (numBlack == 0)
			{
				whitePass = true;
				current = true;
				copy = new int[9][9];
				for (int i = 0; i < squares.length; i++)
					for (int j = 0; j < squares[0].length; j++)
					{
						if (squares[i][j].piece == null)
						{
							copy[i][j] = -1;

						}
						else if (squares[i][j].piece.team)
						{
							copy[i][j] = 1;

						}
						else
							copy[i][j] = 0;
					}
				ko.add(copy);

				return;
			}

			for (int i = 0; i < 9; i++)
			{
				for (int j = 0; j < 9; j++)
				{
					if (squares[i][j].piece != backup[i][j])
						return;
				}
			}
			blackScore -= .5;
			whitePass = true;
			current = true;
			copy = new int[9][9];
			for (int i = 0; i < squares.length; i++)
				for (int j = 0; j < squares[0].length; j++)
				{
					if (squares[i][j].piece == null)
					{
						copy[i][j] = -1;

					}
					else if (squares[i][j].piece.team)
					{
						copy[i][j] = 1;

					}
					else
						copy[i][j] = 0;
				}
			ko.add(copy);

		}
		else
		{
			evaluate(times - 1);
		}
	}