
mikecargal
Hands-on Rust: can_place logic is "inside out"
Title: Hands-On Rust (Chapter 11: prefab)
Just played a couple of amulet-less games. With a bit of debugging, I believe that your can_place
logic is inside-out. Current code starts with assumption that you can’t place and then set’s it to true if any of the positions work:
let mut can_place = false;// (4)
dimensions.for_each(|pt| {// (5)
let idx = mb.map.point2d_to_index(pt);
let distance = dijkstra_map.map[idx];
if distance < 2000.0 && distance > 20.0 && mb.amulet_start != pt {// (6)
can_place = true;
}
});
I think you need to start with a more positive attitude (you
can_place
unless you find something invalid):
let mut can_place = true;
dimensions.for_each(|pt| {
let idx = mb.map.point2d_to_index(pt);
let distance = dijkstra_map.map[idx];
if distance >= 2000.0 || distance < 20.0 || pt == mb.amulet_start {
can_place = false;
}
});
I’m also seeing some other weirdness:
- player stepping off into darkness,
- inaccessible floor tiles (I can see them diagonally)
- monsters on top of one another (pretty sure I’ve seen that)
I’m assuming the others are typos on my part and I have a good bit of debugging ahead of me. Will let you know what I find.
BTW, normally (i.e. in other environments I’ve coded in), every time something “weird” happened, I’d set up a unit test to catch it and then fix it (ensuring it’s never happen again). Would be interesting how unit testing i handled where there’s so much randomness involved.
Most Liked

herbert
Hey, sorry about the slow replies. I’ve been really rather unwell, and slept through the last week and a half or so. I’ll go over this thread today and turn it into action items. I’m going to have to strike a balance between the focus of the book (teaching Rust/gamedev) and making the procgen content a bit more solid. I’ll get back to you soon with some ideas - thanks for taking the time to look at it all.

mikecargal
Yeah, after spending more time just enhancing things to learn more Rust, I’m definitely seeing the trade off with focus on book topics, and going down side topics too much. Don’t envy you trying to find the right balance.

herbert
The “master” build on github is going through heavy testing, with a view to pushing a bug-fix release very soon. Waiting on a winit
update that fixes a bunch of Big Sur issues to try and include them at the same time.
Popular Prag Prog topics










Other popular topics










Latest in PragProg
Latest (all)
Categories:
Popular Portals
- /elixir
- /rust
- /wasm
- /ruby
- /erlang
- /phoenix
- /keyboards
- /js
- /rails
- /python
- /security
- /go
- /swift
- /vim
- /clojure
- /java
- /haskell
- /emacs
- /svelte
- /onivim
- /typescript
- /crystal
- /c-plus-plus
- /tailwind
- /kotlin
- /gleam
- /react
- /flutter
- /elm
- /ocaml
- /vscode
- /opensuse
- /ash
- /centos
- /php
- /deepseek
- /scala
- /zig
- /html
- /debian
- /nixos
- /lisp
- /agda
- /sublime-text
- /textmate
- /react-native
- /kubuntu
- /arch-linux
- /revery
- /ubuntu
- /manjaro
- /django
- /spring
- /diversity
- /nodejs
- /lua
- /julia
- /slackware
- /c
- /neovim