public bool canChangeGrain(Grain grain) { return(grain.stan == Grain.TYPE_EMPTY); }
public bool canChangeGrain(Grain grain) { return(true); }
public int calcEnergy(Grain currentGrain, Grain[] neighborhood) { Dictionary <int, int> colors = getColorsDictionary(neighborhood); return(colors.Keys.Sum(x => (x != currentGrain.index) ? (colors[x]) : 0)); }
public bool canChangeGrain(Grain grain) { return(grain.stan == Grain.TYPE_OLD_GRAIN); }
public void solve(Displayer displayer, int param, int percent) { GrowthStrategy growthStrategy; bool doRandomGrainPick = false; if (param == 3) { growthStrategy = monteCarlo; } else if (param == 2) { growthStrategy = new Moore2GrowthStrategy(percent); } else if (param == 4) { growthStrategy = srxmcGrowth; doRandomGrainPick = true; } else { growthStrategy = new MooreGrowthStrategy(); } for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { if (grains[i, j] != null && grains[i, j].stan == Grain.TYPE_OLD_GRAIN) { //... } else if (ifGrainIsInColorList(grains[i, j])) { grains[i, j].stan = 9; //przypisuje ziarną stan 9 zey nie byly edytowane } } } Grain[,] tab2 = new Grain[width, height]; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { tab2[i, j] = new Grain(); } } bool hasEmptyGrain = true; do { growthStrategy.prepareLoop(grains, width, height); if (doRandomGrainPick) { Random rand = new Random(); IList <int[]> pozList = new List <int[]>(); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { pozList.Add(new int[2] { i, j }); } } while (pozList.Count > 0) { int randX = rand.Next(0, pozList.Count); int[] X = pozList[randX]; solveInternal(growthStrategy, tab2, X[0], X[1]); pozList.Remove(X); } } else { for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { solveInternal(growthStrategy, tab2, i, j); } } } hasEmptyGrain = rewriteGrains(tab2); displayer.display(display()); System.Threading.Thread.Sleep(10); } while (growthStrategy.canContinue(hasEmptyGrain)); }
public void createBoundaryFromColor(int x, int y) { x = x / 5; y = y / 5; Grain[,] tab2 = new Grain[width, height]; //dostaje x i y z klikniecia - dziele przez 5 bo piksele //dostaje x y tablicy Grain grain = grains[x, y]; if (grain.stan == Grain.TYPE_GRAIN) { for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { Grain g = grains[i, j]; int gora = j - 1; int dol = j + 1; int prawy = i + 1; int lewy = i - 1; //perdiodyczny warunek brzegowy if (i == 0) { lewy = width - 1; } if (i == width - 1) { prawy = 0; } if (j == 0) { gora = height - 1; } if (j == height - 1) { dol = 0; } //liczy sasiedztwo po to zeby policzyc tablice kolorow //jesli sa w sasiedztwie dwa rozne kolory to jest granica // ziarno ktore Dictionary <int, int> mapa = getColorsDictionary(grains, i, j, lewy, gora, dol, prawy); if (g.index == grain.index && mapa.Count >= 2) { tab2[i, j] = new Grain(); tab2[i, j].index = grain.index; tab2[i, j].stan = Grain.TYPE_INCLUSION; } else { tab2[i, j] = new Grain(); tab2[i, j].index = 0; tab2[i, j].stan = Grain.TYPE_EMPTY; } } } rewriteGrains(tab2); resetBoundaryColor(); } }