2026-03-27 22:42:43 +07:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
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.
2026-04-21 21:44:26 +07:00
|
|
|
namespace Hallucinate.GameSetup.Maze.Extensions
|
2026-03-27 22:42:43 +07:00
|
|
|
{
|
2026-04-21 23:28:49 +07:00
|
|
|
public static class ListExtensions
|
2026-03-27 22:42:43 +07:00
|
|
|
{
|
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.
2026-04-21 21:44:26 +07:00
|
|
|
private static System.Random _rng = new System.Random();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2026-04-21 23:28:49 +07:00
|
|
|
/// Shuffles a list using the Fisher-Yates algorithm.
|
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.
2026-04-21 21:44:26 +07:00
|
|
|
/// </summary>
|
|
|
|
|
public static void Shuffle<T>(this IList<T> list)
|
2026-03-27 22:42:43 +07:00
|
|
|
{
|
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.
2026-04-21 21:44:26 +07:00
|
|
|
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;
|
|
|
|
|
}
|
2026-03-27 22:42:43 +07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|