private static void InitPanels () { int playable_count = 0; for (int x = 0; x < COUNT_X; ++x) { for (int y = 0; y < COUNT_Y; ++y) { Position position = new Position( START_X + DELTA_X * x, START_Y + DELTA_Y * y ); PanelDirectionX direction_x = (PanelDirectionX)(x % 3); PanelDirectionY direction_y = (PanelDirectionY)y; bool playable = ( (direction_x == PanelDirectionX.Center) == (direction_y == PanelDirectionY.Center) ); int player_index = (x < COUNT_X / 2) ? 0 : 1; int index = x + (y * COUNT_X); int index_playable = playable ? (playable_count++) : -1; #region Hard Coded Hack if (index_playable == 3) { index_playable = 4; } else if (index_playable == 4) { index_playable = 3; } else if (index_playable == 8) { index_playable = 9; } else if (index_playable == 9) { index_playable = 8; } #endregion Panel panel = new Panel( position, direction_x, direction_y, playable, player_index, x, y, index, index_playable ); Panels[x, y] = panel; Panels_1D[index] = panel; if (playable) { Panels_1D_Playable[index_playable] = panel; } } } }
public static Panel CalculateBestSubBracketable (Panel anchor, Panel other) { List<Panel> neighbours = SubNeighbours_1D[anchor.index]; Panel nearest = null; float distance = float.PositiveInfinity; foreach (Panel n in neighbours) { float d = Panel.DistanceTo(other.index, n.index); if (d < distance) { nearest = n; distance = d; } } if (nearest == null) { throw new ArgumentException(); } return nearest; }