diff --git a/min-steps.scm b/min-steps.scm index 76bb17e..4d33bd7 100755 --- a/min-steps.scm +++ b/min-steps.scm @@ -1,6 +1,8 @@ #! /usr/bin/env guile -e main -s !# +;; TODO: make this a module + (use-modules (srfi srfi-1) (srfi srfi-9 gnu) (srfi srfi-11) @@ -107,13 +109,27 @@ ;; board = (player-pos (wall goal box)-bitsets) (define (string->board s) - ;; string-trim-both instead of filter (compose not string-null?) keeps internal - ;; blanks while removing (almost always) useless leading and trailing blanks - (define lines (list->vector (string-split (string-trim-both s) #\newline))) + ;; string-trim alone doesn't work because e.g. + ;; ### + ;; ###.# + ;; #@ $# + ;; # # + ;; ##### + ;; becomes + ;; ### + ;; ###.# + ;; #@ $# + ;; # # + ;; ##### + ;; which is just no good + + (define lines (list->vector + (string-split (string-trim-both s (lambda (c) (eqv? c #\newline))) + #\newline))) (define widths (vector-map (lambda (_ line) (string-length line)) lines)) (define width (apply max (vector->list widths))) (define height (vector-length lines)) - + (define player-x #f) (define player-y #f) @@ -276,9 +292,6 @@ ")) -(define (main . args) +(define (main args) (define-values (cost node) (min-steps (string->board (get-string-all (current-input-port))))) (format #t "~a\n~a\n" cost node)) - -;; TODO: lol i have immutable board movement, so just make this actually playable -;; with super easy undo lol