changed function for shifting cells and marks. now allows for wrap around - next up is incorporating logic to delete or clear cells that get wrapped around
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Godot;
|
||||
|
||||
public static partial class Globals
|
||||
{
|
||||
@@ -7,15 +8,29 @@ public static partial class Globals
|
||||
public static Random _rng = new();
|
||||
public static List<string> _addressTranslation = new(){"NW","N","NE","W","C","E","SW","S","SE"};
|
||||
|
||||
public static void Shuffle<T>(this IList<T> list)
|
||||
public static List<T> ShiftList<T>(List<T> LIST, int SHIFT_BY)
|
||||
{
|
||||
int n = list.Count;
|
||||
if (LIST.Count <= SHIFT_BY || LIST.Count == 0 || SHIFT_BY ==0)
|
||||
{
|
||||
return LIST;
|
||||
}
|
||||
int getRangeStart = SHIFT_BY < 0 ? -SHIFT_BY : LIST.Count - SHIFT_BY;
|
||||
int getRangeEnd = SHIFT_BY < 0 ? LIST.Count + SHIFT_BY : SHIFT_BY;
|
||||
int addRangeEnd = SHIFT_BY < 0 ? -SHIFT_BY : LIST.Count - SHIFT_BY;
|
||||
var result = LIST.GetRange(getRangeStart, getRangeEnd);
|
||||
result.AddRange(LIST.GetRange(0, addRangeEnd));
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void Shuffle<T>(IList<T> LIST)
|
||||
{
|
||||
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;
|
||||
T value = LIST[k];
|
||||
LIST[k] = LIST[n];
|
||||
LIST[n] = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user