summaryrefslogtreecommitdiff
path: root/Pathfinding Visualizer/Assets/Scripts/Main.cs
diff options
context:
space:
mode:
authorSimon O'Shea <osheas1@wit.edu>2023-08-08 16:29:52 -0400
committerSimon O'Shea <osheas1@wit.edu>2023-08-08 16:29:52 -0400
commit2dcb6ea96d73b29ddd5d6fd302330a004348c47d (patch)
tree1f70f088252202ccafae09ea425d518dc989d21a /Pathfinding Visualizer/Assets/Scripts/Main.cs
parent239f7ed4c592fc90ad8d6afc9e342a0e8f1694cf (diff)
things are broken
Diffstat (limited to 'Pathfinding Visualizer/Assets/Scripts/Main.cs')
-rw-r--r--Pathfinding Visualizer/Assets/Scripts/Main.cs69
1 files changed, 57 insertions, 12 deletions
diff --git a/Pathfinding Visualizer/Assets/Scripts/Main.cs b/Pathfinding Visualizer/Assets/Scripts/Main.cs
index 6ebb37f..53bbec2 100644
--- a/Pathfinding Visualizer/Assets/Scripts/Main.cs
+++ b/Pathfinding Visualizer/Assets/Scripts/Main.cs
@@ -8,27 +8,29 @@ public class Main : MonoBehaviour
[SerializeField] private CellMesh cellMesh;
private LogicGrid world;
- char placementMode;
int placementValue;
-
bool astarSelected;
+ // Coordinates for pathfinding
+ public Vector2 agent = new Vector2();
+ public List<Vector2> obstacles = new List<Vector2>();
+ public List<Vector2> samples = new List<Vector2>();
+
// Start is called before the first frame update
void Start()
{
// Create world
- int width = 100;
- int height = 100;
- float cellSize = 5f;
- Vector3 origin = new Vector3(-110, -110);
+ int width = 5;
+ int height = 5;
+ float cellSize = 10f;
+ Vector3 origin = new Vector3(-10, -10);
world = new LogicGrid(width, height, cellSize, origin);
// Set default placement to Obstacle
placementValue = 1;
- placementMode = 'o';
cellMesh.SetGrid(world);
@@ -45,21 +47,18 @@ public class Main : MonoBehaviour
if (Input.GetKeyDown("o"))
{
Debug.Log("Placing Mode: Obstacle");
- placementMode = 'o';
placementValue = 1;
}
// Place Sample in cell
if(Input.GetKeyDown("s"))
{
Debug.Log("Placing Mode: Sample");
- placementMode = 's';
placementValue = 2;
}
// Place agent in cell
if (Input.GetKeyDown("a"))
{
Debug.Log("Placing Mode: Agent");
- placementMode = 'a';
placementValue = 3;
}
// Reset Canvas
@@ -67,6 +66,11 @@ public class Main : MonoBehaviour
{
ResetGrid();
}
+
+ if (Input.GetKeyDown("g"))
+ {
+ StartAlgorithm();
+ }
//////////////////////////
@@ -107,9 +111,50 @@ public class Main : MonoBehaviour
public void StartAlgorithm()
{
- if(astarSelected)
+ Vector2 coord = new Vector2();
+
+ // Collect information about world
+ for (int x = 0; x < world.GetWidth(); x++)
+ for(int y = 0; y < world.GetHeight(); y++)
+ {
+ int index = x * world.GetHeight() + y;
+ int value = world.GetValue(x, y);
+
+ Debug.Log("x: " + x + " y: " + y + " | value: " + value);
+
+ // Add coordinate to obstacle array
+ if (value == 1)
+ {
+ //coord = new int[2][];
+
+ coord.x = x;
+ coord.y = y;
+
+ if (!obstacles.Contains(coord))
+ obstacles.Add(coord);
+ }
+ // Add coordinate to sample array
+ if (value == 2)
+ {
+ //coord = new int[2][];
+
+ coord.x = x;
+ coord.y = y;
+
+ samples.Add(coord);
+ }
+ // Add coordinate to obstacle array
+ if (value == 3)
+ {
+ agent[0] = x;
+ agent[1] = y;
+ }
+ }
+
+
+ if ( true )
{
- AStar astar = new AStar(world, 0);
+ Pathfinder astar = new Pathfinder(world, agent, obstacles, samples, 0, 0);
astar.go();
}
}