public static List <Grain> HexagonalGrains(Grain[,] grains, int x, int y) { List <Grain> _Neighbours = new List <Grain>(); HexagonalNeighbourhood hexagonalNeighbourhood = HEXAGONAL_NEIGHBOURHOOD; if (hexagonalNeighbourhood == HexagonalNeighbourhood.Random) { hexagonalNeighbourhood = (HexagonalNeighbourhood)hexagonalNeighbourhoods.GetValue(SIMULATION_RANDOM.Next(hexagonalNeighbourhoods.Length)); } if (BOUNDARY_CONDITION == BoundaryCondition.Periodic) { int x_l = x - 1 < 0 ? SIZE_X - 1 : x - 1; int x_p = x + 1 >= SIZE_X ? 0 : x + 1; int y_d = y + 1 >= SIZE_Y ? 0 : y + 1; int y_g = y - 1 < 0 ? SIZE_Y - 1 : y - 1; switch (hexagonalNeighbourhood) { case HexagonalNeighbourhood.Left: _Neighbours.Add(grains[y, x_l]); // s_l _Neighbours.Add(grains[y, x_p]); // s_p _Neighbours.Add(grains[y_d, x]); // s_d _Neighbours.Add(grains[y_g, x]); // s_g _Neighbours.Add(grains[y_d, x_p]); // s_d_p _Neighbours.Add(grains[y_g, x_l]); // s_g_l break; case HexagonalNeighbourhood.Right: _Neighbours.Add(grains[y, x_l]); // s_l _Neighbours.Add(grains[y, x_p]); // s_p _Neighbours.Add(grains[y_d, x]); // s_d _Neighbours.Add(grains[y_g, x]); // s_g _Neighbours.Add(grains[y_d, x_l]); // s_d_l _Neighbours.Add(grains[y_g, x_p]); // s_g_p break; } } else { int x_l = x - 1 < 0 ? x : x - 1; int x_p = x + 1 >= SIZE_X ? x : x + 1; int y_d = y + 1 >= SIZE_Y ? y : y + 1; int y_g = y - 1 < 0 ? y : y - 1; switch (hexagonalNeighbourhood) { case HexagonalNeighbourhood.Left: _Neighbours.Add(grains[y, x_l]); // s_l _Neighbours.Add(grains[y, x_p]); // s_p _Neighbours.Add(grains[y_d, x]); // s_d _Neighbours.Add(grains[y_g, x]); // s_g _Neighbours.Add(grains[y_d, x_p]); // s_d_p _Neighbours.Add(grains[y_g, x_l]); // s_g_l break; case HexagonalNeighbourhood.Right: _Neighbours.Add(grains[y, x_l]); // s_l _Neighbours.Add(grains[y, x_p]); // s_p _Neighbours.Add(grains[y_d, x]); // s_d _Neighbours.Add(grains[y_g, x]); // s_g _Neighbours.Add(grains[y_d, x_l]); // s_d_l _Neighbours.Add(grains[y_g, x_p]); // s_g_p break; } } return(_Neighbours); }
public static List <Grain> PentagonalGrains(Grain[,] grains, int x, int y) { List <Grain> _Neighbours = new List <Grain>(); PentagonalNeighbourhood pentagonalNeighbourhood = (PentagonalNeighbourhood)pentagonalNeighbourhoods.GetValue(SIMULATION_RANDOM.Next(pentagonalNeighbourhoods.Length)); if (BOUNDARY_CONDITION == BoundaryCondition.Periodic) { int x_l = x - 1 < 0 ? SIZE_X - 1 : x - 1; int x_p = x + 1 >= SIZE_X ? 0 : x + 1; int y_d = y + 1 >= SIZE_Y ? 0 : y + 1; int y_g = y - 1 < 0 ? SIZE_Y - 1 : y - 1; switch (pentagonalNeighbourhood) { case PentagonalNeighbourhood.Top: _Neighbours.Add(grains[y, x_l]); // s_l _Neighbours.Add(grains[y, x_p]); // s_p _Neighbours.Add(grains[y_d, x]); // s_d _Neighbours.Add(grains[y_d, x_l]); // s_d_l _Neighbours.Add(grains[y_d, x_p]); // s_d_p break; case PentagonalNeighbourhood.Right: _Neighbours.Add(grains[y, x_l]); // s_l _Neighbours.Add(grains[y_d, x]); // s_d _Neighbours.Add(grains[y_g, x]); // s_g _Neighbours.Add(grains[y_d, x_l]); // s_d_l _Neighbours.Add(grains[y_g, x_l]); // s_g_l break; case PentagonalNeighbourhood.Bottom: _Neighbours.Add(grains[y, x_l]); // s_l _Neighbours.Add(grains[y, x_p]); // s_p _Neighbours.Add(grains[y_g, x]); // s_g _Neighbours.Add(grains[y_g, x_l]); // s_g_l _Neighbours.Add(grains[y_g, x_p]); // s_g_p break; case PentagonalNeighbourhood.Left: _Neighbours.Add(grains[y, x_p]); // s_p _Neighbours.Add(grains[y_d, x]); // s_d _Neighbours.Add(grains[y_g, x]); // s_g _Neighbours.Add(grains[y_d, x_p]); // s_d_p _Neighbours.Add(grains[y_g, x_p]); // s_g_p break; } } else { int x_l = x - 1 < 0 ? x : x - 1; int x_p = x + 1 >= SIZE_X ? x : x + 1; int y_d = y + 1 >= SIZE_Y ? y : y + 1; int y_g = y - 1 < 0 ? y : y - 1; switch (pentagonalNeighbourhood) { case PentagonalNeighbourhood.Top: _Neighbours.Add(grains[y, x_l]); // s_l _Neighbours.Add(grains[y, x_p]); // s_p _Neighbours.Add(grains[y_d, x]); // s_d _Neighbours.Add(grains[y_d, x_l]); // s_d_l _Neighbours.Add(grains[y_d, x_p]); // s_d_p break; case PentagonalNeighbourhood.Right: _Neighbours.Add(grains[y, x_l]); // s_l _Neighbours.Add(grains[y_d, x]); // s_d _Neighbours.Add(grains[y_g, x]); // s_g _Neighbours.Add(grains[y_d, x_l]); // s_d_l _Neighbours.Add(grains[y_g, x_l]); // s_g_l break; case PentagonalNeighbourhood.Bottom: _Neighbours.Add(grains[y, x_l]); // s_l _Neighbours.Add(grains[y, x_p]); // s_p _Neighbours.Add(grains[y_g, x]); // s_g _Neighbours.Add(grains[y_g, x_l]); // s_g_l _Neighbours.Add(grains[y_g, x_p]); // s_g_p break; case PentagonalNeighbourhood.Left: _Neighbours.Add(grains[y, x_p]); // s_p _Neighbours.Add(grains[y_d, x]); // s_d _Neighbours.Add(grains[y_g, x]); // s_g _Neighbours.Add(grains[y_d, x_p]); // s_d_p _Neighbours.Add(grains[y_g, x_p]); // s_g_p break; } } return(_Neighbours); }