Files
BABA_YAGA/Assets/Scripts/GameSetup/Maze/Extensions.cs

32 lines
992 B
C#
Raw Normal View History

2026-03-27 22:42:43 +07:00
using System.Collections.Generic;
namespace Hallucinate.GameSetup.Maze.Extensions
2026-03-27 22:42:43 +07:00
{
/// <summary>
/// Provides utility extension methods for maze generation algorithms.
/// </summary>
public static class Extensions
2026-03-27 22:42:43 +07:00
{
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)
2026-03-27 22:42:43 +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
}
}
}