mirror of
https://github.com/vgstation-coders/vgstation13.git
synced 2025-12-10 02:16:05 +00:00
Replace current shuffle with Fisher-Yates algorithm.
This commit is contained in:
@@ -154,17 +154,25 @@ proc/listclearnulls(list/list)
|
||||
output += L[i]
|
||||
return output
|
||||
|
||||
//Randomize: Return the list in a random order
|
||||
/proc/shuffle(var/list/shufflelist)
|
||||
if(!shufflelist)
|
||||
return
|
||||
var/list/new_list = list()
|
||||
var/list/old_list = shufflelist.Copy()
|
||||
while(old_list.len)
|
||||
var/item = pick(old_list)
|
||||
new_list += item
|
||||
old_list -= item
|
||||
return new_list
|
||||
/*
|
||||
* Using Fisher-Yates shuffle modern algorithm.
|
||||
* Stephen001 snippet at http://www.byond.com/forum/?post=1604987#comment10716726
|
||||
*/
|
||||
/proc/shuffle(var/list/L)
|
||||
var/length = length(L)
|
||||
|
||||
if(length < 2)
|
||||
return L
|
||||
|
||||
var/j
|
||||
|
||||
for (var/i in 1 to length)
|
||||
j = rand(i, length)
|
||||
|
||||
if(i != j)
|
||||
L.Swap(i, j)
|
||||
|
||||
return L
|
||||
|
||||
//Return a list with no duplicate entries
|
||||
/proc/uniquelist(var/list/L)
|
||||
|
||||
@@ -125,8 +125,7 @@ var/list/advance_cures = list(
|
||||
// Mix the symptoms of two diseases (the src and the argument)
|
||||
/datum/disease/advance/proc/Mix(var/datum/disease/advance/D)
|
||||
if(!(src.IsSame(D)))
|
||||
var/list/possible_symptoms = shuffle(D.symptoms)
|
||||
for(var/datum/symptom/S in possible_symptoms)
|
||||
for(var/datum/symptom/S in shuffle(D.symptoms))
|
||||
AddSymptom(new S.type)
|
||||
|
||||
/datum/disease/advance/proc/HasSymptom(var/datum/symptom/S)
|
||||
|
||||
@@ -76,7 +76,7 @@
|
||||
<!-- Suggestion: Group changes not merged into master into a single [IN DEVELOPMENT] block, then change the date to today before merging. Makes the changes from the last release a bit easier to comprehend. -->
|
||||
<div class="commit sansserif">
|
||||
<h2 class="date">2014.07.05</h2>
|
||||
<h3 class="author">ESWordTheCat updated:</h3>
|
||||
<h3 class="author">ESwordTheCat updated:</h3>
|
||||
<ul class="changes bgimages16">
|
||||
<li class="bugfix">Fix more link of flavor text</li>
|
||||
</ul>
|
||||
|
||||
Reference in New Issue
Block a user