package com.github.andone.launcher;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * Created by denis on 2/22/17.
 */
public class Pattern {
    private final int x;
    private final int y;

    public static List<Pattern> getPatterns() {
        return Arrays.asList(
                new Pattern(5 ,0),
                new Pattern(0 ,5),
                new Pattern(0 ,4),
                new Pattern(4 ,0),
                new Pattern(2 ,2),
                new Pattern(0 ,3),
                new Pattern(3 ,0),
                new Pattern(2 ,0),
                new Pattern(0 ,2)
        );
    }

    public static List<List<Cell>> getValidRegions(int x, int y) {

        return Collections.emptyList();
    }

    public Pattern(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }
}

@@ -52,17 +52,20 @@
 il.Array
-s
+List
 ;%0Aimport
@@ -75,26 +75,21 @@
 va.util.
-Collection
+Array
 s;%0Aimpor
@@ -331,11 +331,11 @@
 ern(
-5 ,
+4, 
 0),%0A
@@ -367,11 +367,11 @@
 rn(0
- ,5
+, 4
 ),%0A 
@@ -402,11 +402,11 @@
 rn(0
- ,4
+, 3
 ),%0A 
@@ -436,11 +436,11 @@
 ern(
-4 ,
+3, 
 0),%0A
@@ -471,12 +471,12 @@
 ern(
-2 ,2
+1, 1
 ),%0A 
@@ -507,11 +507,11 @@
 rn(0
- ,3
+, 2
 ),%0A 
@@ -541,11 +541,11 @@
 ern(
-3 ,
+2, 
 0),%0A
@@ -576,11 +576,11 @@
 ern(
-2 ,
+1, 
 0),%0A
@@ -612,11 +612,11 @@
 rn(0
- ,2
+, 1
 )%0A  
@@ -698,51 +698,1074 @@
 nt y
-) %7B%0A%0A        return Collections.emptyList()
+, Pizza pizza) %7B%0A        List%3CList%3CCell%3E%3E regions = new ArrayList%3C%3E();%0A        for (Pattern pattern : getPatterns()) %7B%0A            int dx = pattern.x;%0A            int dy = pattern.y;%0A%0A            for (int i = -1; i %3C= 1; i += 2) %7B%0A                for (int j = -1; j %3C= 1; j += 2) %7B%0A                    int x2 = x + dx * i;%0A                    int y2 = y + dy * j;%0A                    if (isValidRegion(x + x2, y + y2, pizza)) %7B%0A                        regions.add(cellsInRegion(x, y, x2, y2, pizza));%0A                    %7D%0A                %7D%0A            %7D%0A        %7D%0A        return regions;%0A    %7D%0A%0A    private static boolean isValidRegion(int x, int y, Pizza pizza) %7B%0A        return x %3C pizza.getRows() && y %3C pizza.getCols() && x %3E= 0 && y %3E= 0;%0A    %7D%0A%0A    private static List%3CCell%3E cellsInRegion(int x0, int y0, int dx, int dy, Pizza pizza) %7B%0A        List%3CCell%3E region = new ArrayList%3C%3E();%0A        for (int i = x0; i %3C= dx; i++) %7B%0A            for (int j = y0; j %3C= dy; j++) %7B%0A                region.add(pizza.get(i, j));%0A            %7D%0A        %7D%0A        return region
 ;%0A  

Return valid regions bu target cell after all possible patterns application