// Path: app/src/main/java/org/bobstuff/bobball/Utilities.java
// public class Utilities extends Activity {
// 
// 	public static void arrayCopy(int[][] source,int[][] destination) {
// 		for (int a=0; a < source.length; ++a) {
// 			System.arraycopy(source[a], 0, destination[a], 0, source[a].length);
// 		}
// 	}
// 
// 	public static ArrayAdapter createDropdown (Context context, int count) {
// 		List<String> dropdownItems = new ArrayList<>();
// 
// 		for (int i = 1; i <= count; i++) { dropdownItems.add("" + i); }
// 
// 		ArrayAdapter adapter = new ArrayAdapter(context,android.R.layout.simple_spinner_item, dropdownItems);
// 
// 		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// 
// 		return adapter;
// 	}
// 
// 	public static ArrayAdapter createDropdownFromStrings (Context context, int stringsId){
// 		ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(context, stringsId, android.R.layout.simple_spinner_item);
// 		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// 		return adapter;
// 	}
// }


import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import android.graphics.PointF;
import android.graphics.RectF;
import android.os.Parcel;
import android.os.Parcelable;
import org.bobstuff.bobball.Utilities;
    public void addBox(RectF rect, int playerId) {
        int x1 = getGridX(rect.left);
        int y1 = getGridY(rect.top);
        int x2 = getGridX(rect.right);
        int y2 = getGridY(rect.bottom);
        for (int x = x1; x < x2; ++x) {
            for (int y = y1; y < y2; ++y) {
                if (x >= 0 && x < maxX && y >= 0 && y < maxY && gridSquares[x][y] == GRID_SQUARE_CLEAR) {
                    gridSquares[x][y] = GRID_SQUARE_FILLED + playerId;
                }
            }
        }
        perPlayer.get(playerId).collisionRects.add(rect);
    }

    public RectF collide(RectF rect) {
        for (GridPerPlayer gp : perPlayer) {
            for (RectF collisionRect : gp.collisionRects) {
                if (RectF.intersects(rect, collisionRect)) {
                    return collisionRect;
                }
            }
        }
        return null;
    }

    // collapse clear areas if they do not contain a ball
    // the newly filled squares are accounted to player playerid
    public void checkEmptyAreas(List<Ball> balls, int playerid) {

// Path: app/src/main/java/org/bobstuff/bobball/Utilities.java
// public class Utilities extends Activity {
// 
// 	public static void arrayCopy(int[][] source,int[][] destination) {
// 		for (int a=0; a < source.length; ++a) {
// 			System.arraycopy(source[a], 0, destination[a], 0, source[a].length);
// 		}
// 	}
// 
// 	public static ArrayAdapter createDropdown (Context context, int count) {
// 		List<String> dropdownItems = new ArrayList<>();
// 
// 		for (int i = 1; i <= count; i++) { dropdownItems.add("" + i); }
// 
// 		ArrayAdapter adapter = new ArrayAdapter(context,android.R.layout.simple_spinner_item, dropdownItems);
// 
// 		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// 
// 		return adapter;
// 	}
// 
// 	public static ArrayAdapter createDropdownFromStrings (Context context, int stringsId){
// 		ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(context, stringsId, android.R.layout.simple_spinner_item);
// 		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// 		return adapter;
// 	}
// }


// Path: app/src/main/java/org/bobstuff/bobball/GameLogic/Grid.java
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import android.graphics.PointF;
import android.graphics.RectF;
import android.os.Parcel;
import android.os.Parcelable;
import org.bobstuff.bobball.Utilities;

    public void addBox(RectF rect, int playerId) {
        int x1 = getGridX(rect.left);
        int y1 = getGridY(rect.top);
        int x2 = getGridX(rect.right);
        int y2 = getGridY(rect.bottom);
        for (int x = x1; x < x2; ++x) {
            for (int y = y1; y < y2; ++y) {
                if (x >= 0 && x < maxX && y >= 0 && y < maxY && gridSquares[x][y] == GRID_SQUARE_CLEAR) {
                    gridSquares[x][y] = GRID_SQUARE_FILLED + playerId;
                }
            }
        }
        perPlayer.get(playerId).collisionRects.add(rect);
    }

    public RectF collide(RectF rect) {
        for (GridPerPlayer gp : perPlayer) {
            for (RectF collisionRect : gp.collisionRects) {
                if (RectF.intersects(rect, collisionRect)) {
                    return collisionRect;
                }
            }
        }
        return null;
    }

    // collapse clear areas if they do not contain a ball
    // the newly filled squares are accounted to player playerid
    public void checkEmptyAreas(List<Ball> balls, int playerid) {

        Utilities.arrayCopy(gridSquares, tempGridSquares);