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,21 +1,31 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public static class Extensions
|
||||
namespace Hallucinate.GameSetup.Maze.Extensions
|
||||
{
|
||||
private static System.Random rng = new System.Random();
|
||||
public static void Shuffle<T>(this IList<T> list)
|
||||
/// <summary>
|
||||
/// Provides utility extension methods for maze generation algorithms.
|
||||
/// </summary>
|
||||
public static class Extensions
|
||||
{
|
||||
int n = list.Count;
|
||||
while (n > 1)
|
||||
private static System.Random _rng = new System.Random();
|
||||
|
||||
/// <summary>
|
||||
/// Shuffles the elements of an <see cref="IList{T}"/> using the Fisher-Yates algorithm.
|
||||
/// This is used to randomize directions for maze generation.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of elements in the list.</typeparam>
|
||||
/// <param name="list">The list to shuffle.</param>
|
||||
public static void Shuffle<T>(this IList<T> list)
|
||||
{
|
||||
n--;
|
||||
int k = rng.Next(n + 1);
|
||||
T value = list[k];
|
||||
list[k] = list[n];
|
||||
list[n] = value;
|
||||
int n = list.Count;
|
||||
while (n > 1)
|
||||
{
|
||||
n--;
|
||||
int k = _rng.Next(n + 1);
|
||||
T value = list[k];
|
||||
list[k] = list[n];
|
||||
list[n] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user