pudgyturtle

pudgyturtle

Hands-on Rust dungeon crawler bug I can't figure out (Amulet of Yala)

@herbert

Hoping someone can point me in the right direction here: I’m working through the book Hands-On Rust and have just written the code required to spawn the Amulet of Yala in the map at the most accessibly distant tile from where the player spawns. It’s supposed to be added in the corner of some random faraway room, like this:

That image is from the book on pg 180. My code, however, has the amulet spawning not in a room but in one of the four corners of the entire map screen. i.e. completely unreachable:

I combed through every line of code and compared it to what’s in the author’s official repo (HandsOnRust/WinningAndLosing/winning at main · thebracket/HandsOnRust · GitHub) but can’t see what my mistake is. I finally just copied the code from all the files I touched for this Amulet of Yala task to ensure it’s identical, but the amulet is still spawning in a screen corner out of reach. The only files I edited for this are winning/src/components.rs winning/src/spawner.rs winning/src/map_builder.rs winning/src/main.rs winning/src/turn_state.rs and 'winning/src/end_turn.rs. I’m pretty sure the error involves map_builder.rs because it’s the Dijkstra map code that is determining the distance/placement of the amulet in relation to the player:

Anyway, I created a Github repository of all my code in case someone is willing, able, and kind enough to have a look. GitHub - pudgyturtle/dungeoncrawl I’m reluctant to suggest it’s a bug or error with the book because so far every error I’ve had has been my own typo or oversight, but this one has me super stumped. I’d appreciate any suggestions or help!

First Post!

malachid

malachid

@herbert

I’ll start by saying that I compared your code to my older commit and I didn’t see anything wrong with your code. I verified that mine was working and yours wasn’t. I did some debugging and found that yours is always positioned in one of the 4 corners. Specifically in:
idx [ dist ] point
0 [62]: Point { x: 0, y: 0 }
79 [97]: Point { x: 79, y: 0 }
3920 [31]: Point { x: 0, y: 49 }
3999 [66]: Point { x: 79, y: 49 }

I also verified that all 4 corners are always walls, as they should be since all four edges are walls.

As a test, I added this to the mb.amulet_start function:

                .filter(|(idx, dist)| {
                    match mb.map.tiles[*idx] {
                        TileType::Floor => {
                            true
                        },
                        TileType::Wall => {
                            false
                        },
                    }
                })

This resulted in the amulet being reachable.

That being said, I don’t have that code snippet in mine - but maybe that will help you track it down.

Popular Pragmatic topics Top

jesse050717
Title: Web Development with Clojure, Third Edition, pg 116 Hi - I just started chapter 5 and I am stuck on page 116 while trying to star...
New
Alexandr
Hi everyone! There is an error on the page 71 in the book “Programming machine learning from coding to depp learning” P. Perrotta. You c...
New
raul
Hi Travis! Thank you for the cool book! :slight_smile: I made a list of issues and thought I could post them chapter by chapter. I’m rev...
New
JohnS
I can’t setup the Rails source code. This happens in a working directory containing multiple (postgres) Rails apps. With: ruby-3.0.0 s...
New
New
patoncrispy
I’m new to Rust and am using this book to learn more as well as to feed my interest in game dev. I’ve just finished the flappy dragon exa...
New
brunogirin
When installing Cards as an editable package, I get the following error: ERROR: File “setup.py” not found. Directory cannot be installe...
New
brunogirin
When running tox for the first time, I got the following error: ERROR: InterpreterNotFound: python3.10 I realised that I was running ...
New
AufHe
I’m a newbie to Rails 7 and have hit an issue with the bin/Dev script mentioned on pages 112-113. Iteration A1 - Seeing the list of prod...
New
mert
AWDWR 7, page 152, page 153: Hello everyone, I’m a little bit lost on the hotwire part. I didn’t fully understand it. On page 152 @rub...
New

Other popular topics Top

Devtalk
Reading something? Working on something? Planning something? Changing jobs even!? If you’re up for sharing, please let us know what you’...
1017 16965 374
New
wolf4earth
@AstonJ prompted me to open this topic after I mentioned in the lockdown thread how I started to do a lot more for my fitness. https://f...
New
DevotionGeo
I know that these benchmarks might not be the exact picture of real-world scenario, but still I expect a Rust web framework performing a ...
New
siddhant3030
I’m thinking of buying a monitor that I can rotate to use as a vertical monitor? Also, I want to know if someone is using it for program...
New
AstonJ
SpaceVim seems to be gaining in features and popularity and I just wondered how it compares with SpaceMacs in 2020 - anyone have any thou...
New
Margaret
Hello content creators! Happy new year. What tech topics do you think will be the focus of 2021? My vote for one topic is ethics in tech...
New
AstonJ
Continuing the discussion from Thinking about learning Crystal, let’s discuss - I was wondering which languages don’t GC - maybe we can c...
New
PragmaticBookshelf
Author Spotlight James Stanier @jstanier James Stanier, author of Effective Remote Work , discusses how to rethink the office as we e...
New
PragmaticBookshelf
Author Spotlight: Karl Stolley @karlstolley Logic! Rhetoric! Prag! Wow, what a combination. In this spotlight, we sit down with Karl ...
New
New

Latest in PragProg

View all threads ❯