public Algorithms(Grain[,] grains, Grain[,] temp, int ActualHeightOFLayers, NeighbourType type, BoundaryConditions bc, int LayerNumber) { this.grains = grains; this.temp = temp; this.ActualHeightOfLayers = ActualHeightOFLayers; this.type = type; ActualLayerNumber = LayerNumber; this.bc = bc; }
public List <Vector2> GetNeighbourPositions(Vector2 gridPosition, bool existing, NeighbourType neighbourType = NeighbourType.All, int maxNeighbourOffset = 1) { List <Vector2> neighbourPositions = new List <Vector2>(); switch (neighbourType) { case NeighbourType.All: neighbourPositions = GetAllNeighbourPositions(gridPosition, existing, maxNeighbourOffset); break; case NeighbourType.Direct: neighbourPositions = GetDirectNeighbourPositions(gridPosition, existing, maxNeighbourOffset); break; case NeighbourType.Indirect: neighbourPositions = GetIndirectNeighbourPositions(gridPosition, existing, maxNeighbourOffset); break; } return(neighbourPositions); }
private void Neghbour(int cellIndex, NeighbourType type, DiskType attacker) { int neghbourIndex = grid.GetCellNeghbourIndex(cellIndex, type); HashSet <int> flipPath = new HashSet <int>(); while (neghbourIndex >= 0 && tempBoard[neghbourIndex] != attacker && tempBoard[neghbourIndex] != DiskType.Default) { flipPath.Add(neghbourIndex); neghbourIndex = grid.GetCellNeghbourIndex(neghbourIndex, type); } if (neghbourIndex == -1 || tempBoard[neghbourIndex] == attacker || flipPath.Count < 1) { return; } if (ValidMoves.ContainsKey(neghbourIndex)) { ValidMoves[neghbourIndex].UnionWith(flipPath); } else { ValidMoves.Add(neghbourIndex, flipPath); } }
public int GetCellNeghbourIndex(int cellIndex, NeighbourType type) { if (cellIndex < 0) { return(-1); } switch (type) { case NeighbourType.U: return(cellIndex >= boardWidth ? cellIndex - boardWidth : -1); case NeighbourType.D: return(cellIndex + boardWidth < CellsCount ? cellIndex + boardWidth : -1); case NeighbourType.R: return(Mathf.FloorToInt(cellIndex / boardWidth) == Mathf.FloorToInt((cellIndex + 1) / boardWidth) ? cellIndex + 1 : -1); case NeighbourType.L: return(Mathf.FloorToInt(cellIndex / boardWidth) == Mathf.FloorToInt((cellIndex - 1) / boardWidth) ? cellIndex - 1 : -1); case NeighbourType.UR: return(GetCellNeghbourIndex(GetCellNeghbourIndex(cellIndex, NeighbourType.R), NeighbourType.U)); case NeighbourType.UL: return(GetCellNeghbourIndex(GetCellNeghbourIndex(cellIndex, NeighbourType.L), NeighbourType.U)); case NeighbourType.DR: return(GetCellNeghbourIndex(GetCellNeghbourIndex(cellIndex, NeighbourType.R), NeighbourType.D)); case NeighbourType.DL: return(GetCellNeghbourIndex(GetCellNeghbourIndex(cellIndex, NeighbourType.L), NeighbourType.D)); } return(-1); }
public Neighbour(NeighbourType type, Tile tile) { _Type = type; _Tile = tile; }
public static List <Grain> GetNeighbours(Grain coord, Grain[,] grains, int i, int j, NeighbourType neighbourType, BoundaryConditions bc, int width, int height) { List <Grain> GrainNeighbour = new List <Grain>(); int iprev = 0; int inext = 0; int jprev = 0; int jnext = 0; switch (bc) { case BoundaryConditions.Absorbing: nonPeriodic(ref iprev, ref jprev, ref inext, ref jnext, i, j, width, height); break; case BoundaryConditions.Periodic: CheckIfEdge(ref iprev, ref jprev, ref inext, ref jnext, i, j, width, height); break; default: break; } if (neighbourType == NeighbourType.HeksagonalneLosowe) { ThreadSafeRandom tsr = new ThreadSafeRandom(); int pom = tsr.Next(); if (pom > 50) { neighbourType = NeighbourType.HeksagonalneLewe; } else { neighbourType = NeighbourType.HeksagonalnePrawe; } } else if (neighbourType == NeighbourType.PentagonalneLosowe) { ThreadSafeRandom tsr = new ThreadSafeRandom(); int pom = tsr.Next(); if (pom > 50) { neighbourType = NeighbourType.PentagonalnePrawe; } else { neighbourType = NeighbourType.PentagonalneLewe; } } switch (neighbourType) { #region Moore case NeighbourType.Moore: if (grains[iprev, jprev].isEmpty == false) { GrainNeighbour.Add(grains[iprev, jprev]); } if (grains[iprev, j].isEmpty == false) { GrainNeighbour.Add(grains[iprev, j]); } if (grains[iprev, jnext].isEmpty == false) { GrainNeighbour.Add(grains[iprev, jnext]); } if (grains[i, jprev].isEmpty == false) { GrainNeighbour.Add(grains[i, jprev]); } if (grains[i, jnext].isEmpty == false) { GrainNeighbour.Add(grains[i, jnext]); } if (grains[inext, jprev].isEmpty == false) { GrainNeighbour.Add(grains[inext, jprev]); } if (grains[inext, j].isEmpty == false) { GrainNeighbour.Add(grains[inext, j]); } if (grains[inext, jnext].isEmpty == false) { GrainNeighbour.Add(grains[inext, jnext]); } break; #endregion #region MyRegion case NeighbourType.VonNeumann: if (grains[iprev, j].isEmpty == false) { GrainNeighbour.Add(grains[iprev, j]); } if (grains[i, jprev].isEmpty == false) { GrainNeighbour.Add(grains[i, jprev]); } if (grains[i, jnext].isEmpty == false) { GrainNeighbour.Add(grains[i, jnext]); } if (grains[inext, j].isEmpty == false) { GrainNeighbour.Add(grains[inext, j]); } break; #endregion case NeighbourType.HeksagonalneLewe: if (grains[iprev, jprev].isEmpty == false) { GrainNeighbour.Add(grains[iprev, jprev]); } if (grains[iprev, j].isEmpty == false) { GrainNeighbour.Add(grains[iprev, j]); } if (grains[i, jprev].isEmpty == false) { GrainNeighbour.Add(grains[i, jprev]); } if (grains[i, jnext].isEmpty == false) { GrainNeighbour.Add(grains[i, jnext]); } if (grains[inext, j].isEmpty == false) { GrainNeighbour.Add(grains[inext, j]); } if (grains[inext, jnext].isEmpty == false) { GrainNeighbour.Add(grains[inext, jnext]); } break; case NeighbourType.HeksagonalnePrawe: if (grains[iprev, j].isEmpty == false) { GrainNeighbour.Add(grains[iprev, j]); } if (grains[iprev, jnext].isEmpty == false) { GrainNeighbour.Add(grains[iprev, jnext]); } if (grains[i, jprev].isEmpty == false) { GrainNeighbour.Add(grains[i, jprev]); } if (grains[i, jnext].isEmpty == false) { GrainNeighbour.Add(grains[i, jnext]); } if (grains[inext, jprev].isEmpty == false) { GrainNeighbour.Add(grains[inext, jprev]); } if (grains[inext, j].isEmpty == false) { GrainNeighbour.Add(grains[inext, j]); } break; case NeighbourType.PentagonalneLewe: if (grains[inext, jnext].isEmpty == false) { GrainNeighbour.Add(grains[inext, jnext]); } if (grains[iprev, jnext].isEmpty == false) { GrainNeighbour.Add(grains[iprev, jnext]); } if (grains[i, jnext].isEmpty == false) { GrainNeighbour.Add(grains[i, jnext]); } if (grains[iprev, j].isEmpty == false) { GrainNeighbour.Add(grains[iprev, j]); } if (grains[inext, j].isEmpty == false) { GrainNeighbour.Add(grains[i, jprev]); } break; case NeighbourType.PentagonalnePrawe: if (grains[inext, jprev].isEmpty == false) { GrainNeighbour.Add(grains[inext, jprev]); } if (grains[iprev, jprev].isEmpty == false) { GrainNeighbour.Add(grains[iprev, jprev]); } if (grains[i, jprev].isEmpty == false) { GrainNeighbour.Add(grains[i, jprev]); } if (grains[iprev, j].isEmpty == false) { GrainNeighbour.Add(grains[iprev, j]); } if (grains[inext, j].isEmpty == false) { GrainNeighbour.Add(grains[i, jprev]); } break; // break; default: break; } return(GrainNeighbour); }
private static IEnumerable <Location> GetNeighbours(Location location, NeighbourType neighbourType) { switch (neighbourType) { case NeighbourType.Four: return(new[] { (1, 0), (-1, 0), (0, 1), (0, -1) }.Select(tuple =>