-
-
Save dys-bigwig/ee7e08ffff14416f280f121c130c238b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require "../ncurses/api.rkt") | |
(require "struct.rkt") | |
(require data/pvector) | |
(require data/collection) | |
(require lens) | |
(define WIDTH 2) | |
(define HEIGHT 2) | |
(define NORTH 1) | |
(define SOUTH 2) | |
(define EAST 4) | |
(define WEST 8) | |
(define DX (hash EAST 1 WEST -1 NORTH 0 SOUTH 0)) | |
(define DY (hash EAST 0 WEST 0 NORTH -1 SOUTH 1)) | |
(define OPPOSITE (hash EAST WEST WEST EAST NORTH SOUTH SOUTH NORTH)) | |
(define (carve-passages-from cx cy grid) | |
(define directions (sort (list NORTH SOUTH EAST WEST) | |
< | |
#:key (λ (x) (random)) | |
#:cache-keys? #t)) | |
(for/fold ([grid grid]) | |
([direction directions]) | |
(define nx (+ cx (hash-ref DX direction))) | |
(define ny (+ cy (hash-ref DY direction))) | |
(cond | |
[(and (<= 0 ny (sub1 (length grid))) | |
(<= 0 nx (sub1 (length (nth grid ny)))) | |
(= 0 (nth (nth grid ny) nx))) | |
(define grid^ (lens-transform (pvector-ref-nested-lens cy cx) | |
grid | |
(curry bitwise-ior direction))) | |
(define grid^^ (lens-transform (pvector-ref-nested-lens ny nx) | |
grid^ | |
(curry bitwise-ior (hash-ref OPPOSITE direction)))) | |
(carve-passages-from nx ny grid^^)] | |
[else | |
grid]))) | |
(carve-passages-from 0 0 (make-pvector HEIGHT (make-pvector WIDTH 0))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment