Replace current shuffle with Fisher-Yates algorithm.

This commit is contained in:
ESwordTheCat
2014-07-05 20:50:28 -08:00
parent 4601ceec62
commit 568308a7a3
4 changed files with 23 additions and 16 deletions

View File

@@ -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)

View File

@@ -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)

View File

@@ -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>