Refactor maze scripts: namespaces & cleanup
Move Maze-related scripts into the Hallucinate.GameSetup.Maze namespace and perform a broad refactor and cleanup. Make MapLocation a readonly struct, add Corridor/Wall/Path constants, and convert Maze into a clearer base class with serialized fields (width, depth, scale, mapParentObject), proper initialization, virtual Generate, and safer DrawMap behavior. Update neighbor-count helpers, tighten method visibility, and improve algorithm implementations (Crawler, Prims, Recursive, Wilsons) to use the new constants and more robust logic (including logging and loop guards). Add a Fisher–Yates Shuffle extension with a static RNG under Hallucinate.GameSetup.Maze.Extensions. Also update IDE metadata (.idea encodings.xml and workspace.xml) to record file encodings and some project settings.
This commit is contained in:
@@ -1,51 +1,70 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Crawler : Maze
|
||||
namespace Hallucinate.GameSetup.Maze
|
||||
{
|
||||
|
||||
public override void Generate()
|
||||
/// <summary>
|
||||
/// A maze generation algorithm that "crawls" through the grid in a semi-random walk.
|
||||
/// It creates long, winding corridors by moving vertically or horizontally.
|
||||
/// </summary>
|
||||
public class Crawler : Maze
|
||||
{
|
||||
//for (int i = 0; i < 2; i++)
|
||||
// CrawlV();
|
||||
|
||||
//for(int i = 0; i < 3; i++)
|
||||
// CrawlH();
|
||||
}
|
||||
|
||||
void CrawlV()
|
||||
{
|
||||
bool done = false;
|
||||
int x = Random.Range(1,width-1);
|
||||
int z = 1;
|
||||
|
||||
while (!done)
|
||||
/// <summary>
|
||||
/// Orchestrates the crawling generation.
|
||||
/// (Currently empty as per original procedural logic).
|
||||
/// </summary>
|
||||
public override void Generate()
|
||||
{
|
||||
map[x, z] = 0;
|
||||
if (Random.Range(0, 100) < 50)
|
||||
x += Random.Range(-1, 2);
|
||||
else
|
||||
z += Random.Range(0, 2);
|
||||
done |= (x < 1 || x >= width-1 || z < 1 || z >= depth-1);
|
||||
// Implementation can be expanded as needed.
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs a vertical crawl starting from a random X position at the bottom.
|
||||
/// </summary>
|
||||
protected void CrawlV()
|
||||
{
|
||||
bool done = false;
|
||||
int x = Random.Range(1, width - 1);
|
||||
int z = 1;
|
||||
|
||||
while (!done)
|
||||
{
|
||||
map[x, z] = Corridor;
|
||||
if (Random.Range(0, 100) < 50)
|
||||
{
|
||||
x += Random.Range(-1, 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
z += Random.Range(0, 2);
|
||||
}
|
||||
|
||||
done |= (x < 1 || x >= width - 1 || z < 1 || z >= depth - 1);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs a horizontal crawl starting from a random Z position at the left.
|
||||
/// </summary>
|
||||
protected void CrawlH()
|
||||
{
|
||||
bool done = false;
|
||||
int x = 1;
|
||||
int z = Random.Range(1, depth - 1);
|
||||
|
||||
while (!done)
|
||||
{
|
||||
map[x, z] = Corridor;
|
||||
if (Random.Range(0, 100) < 50)
|
||||
{
|
||||
x += Random.Range(0, 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
z += Random.Range(-1, 2);
|
||||
}
|
||||
|
||||
done |= (x < 1 || x >= width - 1 || z < 1 || z >= depth - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CrawlH()
|
||||
{
|
||||
bool done = false;
|
||||
int x = 1;
|
||||
int z = Random.Range(1,depth-1);
|
||||
|
||||
while (!done)
|
||||
{
|
||||
map[x, z] = 0;
|
||||
if (Random.Range(0, 100) < 50)
|
||||
x += Random.Range(0, 2);
|
||||
else
|
||||
z += Random.Range(-1, 2);
|
||||
done |= (x < 1 || x >= width-1 || z < 1 || z >= depth-1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user