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.

Where Next?

Popular Pragmatic Bookshelf topics Top

jeffmcompsci
Title: Design and Build Great Web APIs - typo “https://company-atk.herokuapp.com/2258ie4t68jv” (page 19, third bullet in URL list) Typo:...
New
GilWright
Working through the steps (checking that the Info,plist matches exactly), run the demo game and what appears is grey but does not fill th...
New
sdmoralesma
Title: Web Development with Clojure, Third Edition - migrations/create not working: p159 When I execute the command: user=> (create-...
New
mikecargal
Title: Hands-On Rust (Chap 8 (Adding a Heads Up Display) It looks like ​.with_simple_console_no_bg​(SCREEN_WIDTH*2, SCREEN_HEIGHT*2...
New
adamwoolhether
When trying to generate the protobuf .go file, I receive this error: Unknown flag: --go_opt libprotoc 3.12.3 MacOS 11.3.1 Googling ...
New
brian-m-ops
#book-python-testing-with-pytest-second-edition Hi. Thanks for writing the book. I am just learning so this might just of been an issue ...
New
AndyDavis3416
@noelrappin Running the webpack dev server, I receive the following warning: ERROR in tsconfig.json TS18003: No inputs were found in c...
New
curtosis
Running mix deps.get in the sensor_hub directory fails with the following error: ** (Mix) No SSH public keys found in ~/.ssh. An ssh aut...
New
jskubick
I found an issue in Chapter 7 regarding android:backgroundTint vs app:backgroundTint. How to replicate: load chapter-7 from zipfile i...
New
mcpierce
@mfazio23 I’ve applied the changes from Chapter 5 of the book and everything builds correctly and runs. But, when I try to start a game,...
New

Other popular topics Top

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
The V Programming Language Simple language for building maintainable programs V is already mentioned couple of times in the forum, but I...
New
gagan7995
API 4 Path: /user/following/ Method: GET Description: Returns the list of all names of people whom the user follows Response [ { ...
New
AstonJ
Saw this on TikTok of all places! :lol: Anyone heard of them before? Lite:
New
mafinar
This is going to be a long an frequently posted thread. While talking to a friend of mine who has taken data structure and algorithm cou...
New
AstonJ
If you get Can't find emacs in your PATH when trying to install Doom Emacs on your Mac you… just… need to install Emacs first! :lol: bre...
New
New
AstonJ
Was just curious to see if any were around, found this one: I got 51/100: Not sure if it was meant to buy I am sure at times the b...
New
PragmaticBookshelf
Author Spotlight: Karl Stolley @karlstolley Logic! Rhetoric! Prag! Wow, what a combination. In this spotlight, we sit down with Karl ...
New
New

Sub Categories: