tomassedovic / tcod-rs

Rust bindings for libtcod 1.6.3 (the Doryen library/roguelike toolkit)
Do What The F*ck You Want To Public License
229 stars 45 forks source link

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

Closed ToferC closed 4 years ago

ToferC commented 4 years ago

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: https://github.com/rust-random/rand/pull/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 commented 4 years ago

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: https://github.com/tomassedovic/roguelike-tutorial/issues/40

ToferC commented 4 years ago

Sorry about that. Closing.