private bool grow()//zlicza ile jest poszczególnych id i wybiera tego którego jest najwięcej { //to pusta komórka sprawdza sąsiądów bool stopGrow = true; int id = 0; MyCell newCell; MyCell[,] lastUniverse = (MyCell[, ])currentUniverse.Clone(); for (int i = 1; i < meshSizeX + 1; i++) { for (int j = 1; j < meshSizeY + 1; j++) { if (lastUniverse[i, j] == null) { stopGrow = false; id = getNeighborhood(lastUniverse, i, j); if (id == 0) { continue; } currentUniverse[i, j] = new MyCell(id); } } } currentTime++; if (stopGrow == true) { return(true); } else { return(false); } }
int computeEnergy(MyCell cell, List <MyCell> neighborsList) { int energy = 0; foreach (var item in neighborsList) { if (item.get_id() == 0 || item.get_id() == cell.get_id()) { continue; } energy = energy + 1; } return(energy); }
private double calcuteDistance(int x1, int y1, int x2, int y2, MyCell cell1, MyCell cell2) { double distance; //Przekonwertować x1, y1 na współrzędne kartezjańskie i wtedy liczyć double tmpX1 = x1 + cell1.get_gravityX(); double tmpX2 = x2 + cell2.get_gravityX(); double tmpY1 = y1 + cell1.get_gravityY(); double tmpY2 = y2 + cell2.get_gravityY(); distance = Math.Pow(x2 - x1, 2) + Math.Pow(y2 - y1, 2); distance = Math.Sqrt(distance); return(distance); }
private void setBoundaryCondition() { MyCell myCell = new MyCell(0); switch (switchBoundaryCondition) { case 0: //Periodyczne //corners currentUniverse[0, 0] = currentUniverse[meshSizeX, meshSizeY]; //left up currentUniverse[0, meshSizeY + 1] = currentUniverse[meshSizeX, 1]; //right up currentUniverse[meshSizeX + 1, 0] = currentUniverse[1, meshSizeY]; //left down currentUniverse[meshSizeX + 1, meshSizeY + 1] = currentUniverse[1, 1]; //right down //walls for (int i = 1; i < meshSizeX + 1; i++) { currentUniverse[i, 0] = currentUniverse[i, meshSizeY]; //left wall currentUniverse[i, meshSizeY + 1] = currentUniverse[i, 1]; //right wall //Było 0 zamiast 1 } for (int i = 1; i < meshSizeY + 1; i++) { currentUniverse[0, i] = currentUniverse[meshSizeX, i]; //up wall currentUniverse[meshSizeX + 1, i] = currentUniverse[1, i]; //down wall } break; case 1: //Absorbujące for (int i = 0; i < meshSizeX + 2; i++) //TODO: sprawdzic to { currentUniverse[i, 0] = myCell.myclone(); //lewa currentUniverse[i, meshSizeY + 1] = myCell.myclone(); //prawa } for (int i = 0; i < meshSizeY + 2; i++) //TO też { currentUniverse[0, i] = myCell.myclone(); //gorna currentUniverse[meshSizeX + 1, i] = myCell.myclone(); //dolna } break; default: break; } }
private void seed() { Random random = new Random(); int count = 1; int tmpX = 0; int tmpY = 0; MyCell newCell; int missCount = 0; switch (switchGrainGrowthType) { case 0: //Jednorodne ok int jumpX = meshSizeX / amountX; int jumpY = meshSizeY / amountY; for (int i = 0; i < amountX; i++) { for (int j = 0; j < amountY; j++) { newCell = new MyCell(count); //obczaić bo ostatnie tworzy na krawędzi currentUniverse[jumpX / 2 + i * jumpX, jumpY / 2 + j * jumpY] = newCell; //1 na warunki brzegowe count++; } } amountSeed = amountX * amountY; break; case 1: //Losowe ok for (int i = 0; i < amountX; i++) //sprawdzić czy miejsce jest zajęte { tmpX = random.Next(1, meshSizeX + 1); //TODO: spr w jakim zakresie czy od 1 czy od 2 dd ilu tmpY = random.Next(1, meshSizeY + 1); if (currentUniverse[tmpX, tmpY] == null) //nie dziala { newCell = new MyCell(count); currentUniverse[tmpX, tmpY] = newCell; count++; } else { i--; continue; } amountSeed = amountX; } break; case 2: //Z promieniem //ok for (int i = 0; i < amountX; i++) //zrobić okrąg wpisany w kwadra { tmpX = random.Next(1, meshSizeX + 1); tmpY = random.Next(1, meshSizeY + 1); if (checkRayNeighborhood(tmpX, tmpY) == true) { newCell = new MyCell(count); currentUniverse[tmpX, tmpY] = newCell; count++; } else { missCount++; i--; continue; } amountSeed = count - 1; //sprawdzić if (missCount >= 100) { break; } } break; case 3: //Wybór Uzytkownika nie działa drawUniverse(); break; default: break; } myProperties.amountSeed = amountSeed; colorArray = new Color[amountSeed]; createColorArray(); }
public Neighbor(MyCell myCell, int x, int y) { this.myCell = myCell; this.x = x; this.y = y; }