private synchronized int getBestType(CellPoint cell) {
		ArrayList<Piece> possiblePieces = new ArrayList<Piece>();
		for (Piece a : pieces) {
			if (piecesUsed.indexOf(a) == -1) {
				possiblePieces.add(a);
			}
		}
		// Check for each Piece in pieces if they are in piecesUsed, if not will
		// add to possiblePieces
		// invariant: possiblePieces.size() = pieces.size()-piecesUsed.size()

		int type = -1;

		boolean typeFound = false;
		while (!typeFound && possiblePieces.size() > 0) {
			if (board.getCell(cell.x, cell.y).isEmpty()
					&& cell.getBW() > cell.getWW()
					&& getPieceOfType(possiblePieces, 4) != null) {
				type = 4;
			} else {
				type = getMostCommonType(possiblePieces);
			}// Determine the best type

			possiblePieces.remove(getPieceOfType(possiblePieces, type));
			// removes a piece with the just found type from the possiblePieces.
			typeFound = board.canMove(cell.x, cell.y, new Piece(type,
					playerColor));
			// Checks if the found type is a valid move, if not will retry to
			// found a best type
		}

		return type;
	}