From 3608f4f4605c2191321e6420110add6635daf50c Mon Sep 17 00:00:00 2001 From: Xevion Date: Sun, 8 Nov 2020 18:02:01 -0600 Subject: [PATCH] fix NodeGrid width/height constructor, reformat --- Paths/Assets/Scripts/Algorithms/NodeGrid.cs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/Paths/Assets/Scripts/Algorithms/NodeGrid.cs b/Paths/Assets/Scripts/Algorithms/NodeGrid.cs index 05e38d6..f799960 100644 --- a/Paths/Assets/Scripts/Algorithms/NodeGrid.cs +++ b/Paths/Assets/Scripts/Algorithms/NodeGrid.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Numerics; using Algorithms; using NUnit.Framework.Constraints; using UnityEngine.SocialPlatforms; @@ -11,14 +12,23 @@ public class NodeGrid { private readonly int _height; public NodeGrid(int width, int height) { - if(width <= 0) - throw new ArgumentOutOfRangeException(nameof(width), $"The width of the grid must be a positive non-zero integer."); + if (width <= 0) + throw new ArgumentOutOfRangeException(nameof(width), + $"The width of the grid must be a positive non-zero integer."); if (height <= 0) - throw new ArgumentOutOfRangeException(nameof(height), $"The height of the grid must be a positive non-zero integer."); + throw new ArgumentOutOfRangeException(nameof(height), + $"The height of the grid must be a positive non-zero integer."); this.grid = new List>(width); - for(int _ in Enumerable.Range(0, height - 1)) {} - + // Fill grid with width*height nodes, zero-indexed + foreach (int x in Enumerable.Range(0, width - 1)) { + List list = new List(height); + foreach (int y in Enumerable.Range(0, height)) + list.Add(new Node(new Vector2(x, y), true)); + + this.grid.Add(list); + } + this._width = width; this._height = height; }