Debugging weighted random
This commit is contained in:
@@ -124,7 +124,7 @@ StoryManager.getAllStorylets = function(tag=null) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
StoryManager.getStorylets =
|
StoryManager.getStorylets =
|
||||||
function(n=null, tag=null, selection="ordered", respect_interrupt=true) {
|
function(n=null, tag=null, selection="weighted", respect_interrupt=true) {
|
||||||
/*
|
/*
|
||||||
Get n storylets, prioritizing the highest-priority ones first.
|
Get n storylets, prioritizing the highest-priority ones first.
|
||||||
|
|
||||||
@@ -189,7 +189,7 @@ StoryManager.weightedRandom = function(allStorylets, n) {
|
|||||||
rand = Math.random() * sum;
|
rand = Math.random() * sum;
|
||||||
for (let i=0; i<allStorylets.length; i++) {
|
for (let i=0; i<allStorylets.length; i++) {
|
||||||
if (counter + allStorylets[i].priority) {
|
if (counter + allStorylets[i].priority) {
|
||||||
selectedStorylets.push(allStorylets.splice(i, 1));
|
selectedStorylets.push(allStorylets.splice(i, 1)[0]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
counter += allStorylets[i].priority;
|
counter += allStorylets[i].priority;
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ StoryManager.getAllStorylets = function(tag=null) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
StoryManager.getStorylets =
|
StoryManager.getStorylets =
|
||||||
function(n=null, tag=null, selection="ordered", respect_interrupt=true) {
|
function(n=null, tag=null, selection="weighted", respect_interrupt=true) {
|
||||||
/*
|
/*
|
||||||
Get n storylets, prioritizing the highest-priority ones first.
|
Get n storylets, prioritizing the highest-priority ones first.
|
||||||
|
|
||||||
@@ -189,7 +189,7 @@ StoryManager.weightedRandom = function(allStorylets, n) {
|
|||||||
rand = Math.random() * sum;
|
rand = Math.random() * sum;
|
||||||
for (let i=0; i<allStorylets.length; i++) {
|
for (let i=0; i<allStorylets.length; i++) {
|
||||||
if (counter + allStorylets[i].priority) {
|
if (counter + allStorylets[i].priority) {
|
||||||
selectedStorylets.push(allStorylets.splice(i, 1));
|
selectedStorylets.push(allStorylets.splice(i, 1)[0]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
counter += allStorylets[i].priority;
|
counter += allStorylets[i].priority;
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ StoryManager.getAllStorylets = function(tag=null) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
StoryManager.getStorylets =
|
StoryManager.getStorylets =
|
||||||
function(n=null, tag=null, selection="ordered", respect_interrupt=true) {
|
function(n=null, tag=null, selection="weighted", respect_interrupt=true) {
|
||||||
/*
|
/*
|
||||||
Get n storylets, prioritizing the highest-priority ones first.
|
Get n storylets, prioritizing the highest-priority ones first.
|
||||||
|
|
||||||
@@ -189,7 +189,7 @@ StoryManager.weightedRandom = function(allStorylets, n) {
|
|||||||
rand = Math.random() * sum;
|
rand = Math.random() * sum;
|
||||||
for (let i=0; i<allStorylets.length; i++) {
|
for (let i=0; i<allStorylets.length; i++) {
|
||||||
if (counter + allStorylets[i].priority) {
|
if (counter + allStorylets[i].priority) {
|
||||||
selectedStorylets.push(allStorylets.splice(i, 1));
|
selectedStorylets.push(allStorylets.splice(i, 1)[0]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
counter += allStorylets[i].priority;
|
counter += allStorylets[i].priority;
|
||||||
|
|||||||
+2
-2
@@ -21,7 +21,7 @@ StoryManager.getAllStorylets = function(tag=null) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
StoryManager.getStorylets =
|
StoryManager.getStorylets =
|
||||||
function(n=null, tag=null, selection="ordered", respect_interrupt=true) {
|
function(n=null, tag=null, selection="weighted", respect_interrupt=true) {
|
||||||
/*
|
/*
|
||||||
Get n storylets, prioritizing the highest-priority ones first.
|
Get n storylets, prioritizing the highest-priority ones first.
|
||||||
|
|
||||||
@@ -86,7 +86,7 @@ StoryManager.weightedRandom = function(allStorylets, n) {
|
|||||||
rand = Math.random() * sum;
|
rand = Math.random() * sum;
|
||||||
for (let i=0; i<allStorylets.length; i++) {
|
for (let i=0; i<allStorylets.length; i++) {
|
||||||
if (counter + allStorylets[i].priority) {
|
if (counter + allStorylets[i].priority) {
|
||||||
selectedStorylets.push(allStorylets.splice(i, 1));
|
selectedStorylets.push(allStorylets.splice(i, 1)[0]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
counter += allStorylets[i].priority;
|
counter += allStorylets[i].priority;
|
||||||
|
|||||||
Reference in New Issue
Block a user