Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

RandomTable.roll() returning None fairly freqently.

未关闭
#205 1 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
rust
领域
game-dev

调研方向

查找 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,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

amethyst/rustrogueliketutorial 的其他 Issue

查看 amethyst/rustrogueliketutorial 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。