Rework triangular board to equidistant corner starts
This commit is contained in:
@@ -134,38 +134,48 @@ public static class BoardShapeGenerator
|
||||
|
||||
/// <summary>
|
||||
/// Triangular board for 3 players.
|
||||
/// Generates a true triangular footprint (not a full rectangle) within a bounding box.
|
||||
/// Starting zones:
|
||||
/// Seat 0 = bottom-left edge
|
||||
/// Seat 1 = bottom-right edge
|
||||
/// Seat 2 = top apex area
|
||||
/// Uses a symmetric sparse footprint with equal corner-to-corner path lengths:
|
||||
/// Seat 0 = bottom-left corner, Seat 1 = bottom-right corner, Seat 2 = top apex.
|
||||
///
|
||||
/// Geometry is chosen so:
|
||||
/// base distance (corner↔corner) == side distance (corner↔apex)
|
||||
/// under orthogonal movement.
|
||||
/// </summary>
|
||||
private static Board MakeTriangular(GameRules rules)
|
||||
{
|
||||
int w = Math.Max(rules.BoardWidth, 13);
|
||||
int h = Math.Max(rules.BoardHeight, 10);
|
||||
if (w % 2 == 0) w += 1; // keep a clear center column for the apex
|
||||
// Let "side" be the desired equal travel distance between any two starting corners.
|
||||
// For an isosceles triangle on an orthogonal grid:
|
||||
// base = w - 1
|
||||
// side = (w - 1)/2 + (h - 1)
|
||||
// Enforce equality by picking h = (w + 1)/2, i.e. side = base.
|
||||
int side = Math.Max(12, rules.BoardWidth - 1, 2 * (rules.BoardHeight - 1));
|
||||
if (side % 2 != 0) side++; // keep width odd so apex is centered exactly
|
||||
|
||||
int w = side + 1; // odd
|
||||
int h = side / 2 + 1; // ensures equidistant corners
|
||||
int cx = w / 2;
|
||||
|
||||
var tiles = new Dictionary<string, Tile>();
|
||||
int cx = w / 2;
|
||||
|
||||
for (int y = 0; y < h; y++)
|
||||
{
|
||||
// Half-span shrinks linearly from base (bottom, y=0) to apex (top, y=h-1).
|
||||
int halfSpan = (int)Math.Round((double)(h - 1 - y) * (w - 1) / (2 * Math.Max(1, h - 1)));
|
||||
int x0 = Math.Max(0, cx - halfSpan);
|
||||
int x1 = Math.Min(w - 1, cx + halfSpan);
|
||||
// Shrink by 1 tile per side each row moving upward.
|
||||
int halfSpan = (h - 1) - y;
|
||||
int x0 = cx - halfSpan;
|
||||
int x1 = cx + halfSpan;
|
||||
for (int x = x0; x <= x1; x++)
|
||||
AddTile(tiles, x, y, rules.StartingRandomTilePct);
|
||||
}
|
||||
|
||||
var seat0 = new Coord(0, 0);
|
||||
var seat1 = new Coord(w - 1, 0);
|
||||
var seat2 = new Coord(cx, h - 1);
|
||||
|
||||
var zones = new Dictionary<int, HashSet<Coord>>
|
||||
{
|
||||
// Bottom corners (small bands near each end of the base)
|
||||
[0] = CollectExistingRect(tiles, 0, 0, Math.Max(1, w / 6), Math.Min(1, h - 1)),
|
||||
[1] = CollectExistingRect(tiles, w - 1 - Math.Max(1, w / 6), 0, w - 1, Math.Min(1, h - 1)),
|
||||
// Top apex (2 rows centered)
|
||||
[2] = CollectExistingRect(tiles, cx - 1, Math.Max(0, h - 2), cx + 1, h - 1),
|
||||
[0] = new() { seat0 },
|
||||
[1] = new() { seat1 },
|
||||
[2] = new() { seat2 },
|
||||
};
|
||||
|
||||
return new Board { Width = w, Height = h, Tiles = tiles, StartingZones = zones };
|
||||
|
||||
Reference in New Issue
Block a user