RandomTable.roll() returning None fairly freqently.
还没有人认领这个 Issue。
评估
调研方向
查找 RandomTable.roll() 的实现,并检查 issue 中显示的循环。验证 roll 为 0 以及 roll 恰好等于累积权重时的边界行为,然后执行从第 45 章开始的随机地图,并确认有效的 roll 不再返回 None 或产生警告。
由索引模型根据 Issue 内容生成。
描述
To see the problem in action, get to a random map from chapter 45 on-wards.
The message "WARNING: We don't know how to spawn [None]!" should show up a number of times in the log.
Currently, whenever you roll 0, or exactly the sum of a number of item weights, nothing is spawned.
For example, if the first few items are weighted at [1,3,2,3,1...], then roll() would return "None" if the rng hits 0,1,4,6,9 or 10.
I'm assuming this is unintended behavior, but you can see pretty clearly why this happens in the code:
while roll > 0 {
if roll < self.entries[index].weight {
return self.entries[index].name.clone();
}
roll -= self.entries[index].weight;
index += 1;
}
There are two easy fixes that I can see. Both effectively just looping more:
while roll >= 0 { ...
or
while index < self.entries.len() { ..
- 主要语言
- Rust
- 星标
- 968
- 派生
- 166
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
我们还没有检查这个项目的环境配置文件。先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
amethyst/rustrogueliketutorial 的其他 Issue
-
难度 1/5 1 小时以内 新手友好度 68/100
-
难度 1/5 1 小时以内 新手友好度 68/100
-
难度 1/5 1 小时以内 新手友好度 68/100
-
难度 1/5 1 小时以内 新手友好度 68/100
-
难度 1/5 1-3 小时 新手友好度 45/100
查看 amethyst/rustrogueliketutorial 的全部 Issue
相似的 Issue
-
area:casework bug criticality:p3 triage:needs-implementation
难度 2/5 1-3 小时 新手友好度 84/100
registrystack/registry-stack#1623 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
DioxusLabs/anyrender#98 ·
-
难度 2/5 1-3 小时 新手友好度 76/100
leptos-rs/leptos#4885 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
longbridge/gpui-kit#3276 ·
维护者通常 1 天内回复