From e902dffc9e3151ff9d36a8140e49d681ca43004d Mon Sep 17 00:00:00 2001 From: Mathieu Loiseau <mathieu.loiseau@liris.cnrs.fr> Date: Fri, 22 Mar 2024 14:35:25 +0100 Subject: [PATCH] =?UTF-8?q?am=C3=A9lioration=20al=C3=A9atoire?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/GD_manager.cs | 2 +- Assets/QCM_manager.cs | 2 +- Assets/mainManager.cs | 21 +++++++++++++++++++-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Assets/GD_manager.cs b/Assets/GD_manager.cs index dea2251c..c2e9bcec 100644 --- a/Assets/GD_manager.cs +++ b/Assets/GD_manager.cs @@ -323,7 +323,7 @@ public class GD_manager : MonoBehaviour if (mM.i.randomiser) { - mM.list_choix_associed_with_prefabs.Sort((a, b) => UnityEngine.Random.Range(-1, 2)); + mM.list_choix_associed_with_prefabs = mM.ShuffleItems(mM.list_choix_associed_with_prefabs); } mM.posScript.CalculateAlignment(mM.list_choix_associed_with_prefabs); diff --git a/Assets/QCM_manager.cs b/Assets/QCM_manager.cs index 3fd3f4ea..143e3672 100644 --- a/Assets/QCM_manager.cs +++ b/Assets/QCM_manager.cs @@ -108,7 +108,7 @@ public class QCM_manager : MonoBehaviour { if (mM.i.randomiser) { - mM.list_choix_associed_with_prefabs.Sort((a, b) => UnityEngine.Random.Range(-1, 2)); + mM.list_choix_associed_with_prefabs = mM.ShuffleItems(mM.list_choix_associed_with_prefabs); } mM.posScript.CalculateAlignment(mM.list_choix_associed_with_prefabs); mM.instancieAllChoixAtOnce(); diff --git a/Assets/mainManager.cs b/Assets/mainManager.cs index a87e3a23..d5594c3d 100644 --- a/Assets/mainManager.cs +++ b/Assets/mainManager.cs @@ -433,13 +433,30 @@ public class mainManager : MonoBehaviour for (int i = 0; i < list.Count; i++) { - int index = UnityEngine.Random.Range(0, temp.Count - 1); + int index = UnityEngine.Random.Range(0, temp.Count); shuffled.Add(temp[index]); temp.RemoveAt(index); } return shuffled; } + + public List<groupemementChoixEtPrefabBoutonQCM> ShuffleItems(List<groupemementChoixEtPrefabBoutonQCM> list) + { + List<groupemementChoixEtPrefabBoutonQCM> temp = new List<groupemementChoixEtPrefabBoutonQCM>(); + List<groupemementChoixEtPrefabBoutonQCM> shuffled = new List<groupemementChoixEtPrefabBoutonQCM>(); + temp.AddRange(list); + + for (int i = 0; i < list.Count; i++) + { + int index = UnityEngine.Random.Range(0, temp.Count); + shuffled.Add(temp[index]); + temp.RemoveAt(index); + } + + return shuffled; + } + private bool initialisationFirstEpreuve_EnCours = false; public void nextEpreuve(bool initialisation=false) { @@ -982,7 +999,7 @@ public class mainManager : MonoBehaviour { bannissementIsOver = false; nextEpreuve(true); - + } } } -- GitLab