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 Bookshelf topics Top

jimmykiang
This test is broken right out of the box… — FAIL: TestAgent (7.82s) agent_test.go:77: Error Trace: agent_test.go:77 agent_test.go:...
New
jimschubert
In Chapter 3, the source for index introduces Config on page 31, followed by more code including tests; Config isn’t introduced until pag...
New
kuroneko
Whilst the author has been careful to provide exact results for the tests elsewhere in the book (such as surds with the transformation te...
New
belgoros
Following the steps described in Chapter 6 of the book, I’m stuck with running the migration as described on page 84: bundle exec sequel...
New
raul
Page 28: It implements io.ReaderAt on the store type. Sorry if it’s a dumb question but was the io.ReaderAt supposed to be io.ReadAt? ...
New
taguniversalmachine
Hi, I am getting an error I cannot figure out on my test. I have what I think is the exact code from the book, other than I changed “us...
New
davetron5000
Hello faithful readers! If you have tried to follow along in the book, you are asked to start up the dev environment via dx/build and ar...
New
SlowburnAZ
Getting an error when installing the dependencies at the start of this chapter: could not compile dependency :exla, "mix compile" failed...
New
dachristenson
I just bought this book to learn about Android development, and I’m already running into a major issue in Ch. 1, p. 20: “Update activity...
New
dachristenson
I’ve got to the end of Ch. 11, and the app runs, with all tabs displaying what they should – at first. After switching around between St...
New

Other popular topics Top

New
AstonJ
We have a thread about the keyboards we have, but what about nice keyboards we come across that we want? If you have seen any that look n...
New
AstonJ
Thanks to @foxtrottwist’s and @Tomas’s posts in this thread: Poll: Which code editor do you use? I bought Onivim! :nerd_face: https://on...
New
dimitarvp
Small essay with thoughts on macOS vs. Linux: I know @Exadra37 is just waiting around the corner to scream at me “I TOLD YOU SO!!!” but I...
New
Exadra37
I am asking for any distro that only has the bare-bones to be able to get a shell in the server and then just install the packages as we ...
New
AstonJ
Seems like a lot of people caught it - just wondered whether any of you did? As far as I know I didn’t, but it wouldn’t surprise me if I...
New
mafinar
Crystal recently reached version 1. I had been following it for awhile but never got to really learn it. Most languages I picked up out o...
New
foxtrottwist
A few weeks ago I started using Warp a terminal written in rust. Though in it’s current state of development there are a few caveats (tab...
New
First poster: bot
The overengineered Solution to my Pigeon Problem. TL;DR: I built a wifi-equipped water gun to shoot the pigeons on my balcony, controlle...
New
PragmaticBookshelf
Author Spotlight: Bruce Tate @redrapids Programming languages always emerge out of need, and if that’s not always true, they’re defin...
New

Sub Categories: