Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WeightedChoice depreciated - Uses old rand::distributions module #305

Closed
ToferC opened this issue Dec 25, 2019 · 2 comments
Closed

WeightedChoice depreciated - Uses old rand::distributions module #305

ToferC opened this issue Dec 25, 2019 · 2 comments

Comments

@ToferC
Copy link

ToferC commented Dec 25, 2019

First - amazing work and huge thanks for the tutorial and this module. I know you haven't had time to keep it updated, but wanted to add the issue for other users.

I'm fairly new to Rust and love the flow of the tutorial and am finding it really useful to get familiar with basic gamedev and loops as well.

As for the issue, it seems like WeightedChoice and Weighted in https://tomassedovic.github.io/roguelike-tutorial/part-12-monster-item-progression.html has been depreciated in favour of rand::distributions::WeightedIndex

The pull request and discussion seems to have gone on here: rust-random/rand#518

A working update for the first part using WeightedIndex:

let monster_chances = [
                ("orc", 80),
                ("troll", 20),
            ];

let dist = WeightedIndex::new(monster_chances.iter().map(
    |item| item.1)).unwrap();    
                
let mut rng = rand::thread_rng();

let choice = monster_chances[dist.sample(&mut rng)].0;

let mut monster = match choice {
    "orc" => Object {
        // return object
        }

Cheers!

@ThibaultLemaire
Copy link

ThibaultLemaire commented Jan 5, 2020

Yes I ran into the same issue while following the tutorial just a month ago, but I'm afraid you're on the wrong project.

The project hosting the code for the tutorial already has an issue open: tomassedovic/roguelike-tutorial#40

@ToferC
Copy link
Author

ToferC commented Jan 6, 2020

Sorry about that. Closing.

@ToferC ToferC closed this as completed Jan 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants