|
|
|
|
@ -146,49 +146,48 @@ score. Hence at the end we look (recursively) in the discard pile and |
|
|
|
|
put the ones that end on the best paths with the same score in the |
|
|
|
|
best pile. |
|
|
|
|
#+begin_src emacs-lisp |
|
|
|
|
(setq start-vector (list start '(1 0) 0)) ; starting point, direction and score |
|
|
|
|
|
|
|
|
|
(defun next-dirs (dir) |
|
|
|
|
(--filter (>= (dot it dir) 0) '((0 1) (0 -1) (-1 0) (1 0)))) |
|
|
|
|
|
|
|
|
|
(defun acceptable-p (p dir) |
|
|
|
|
(not (eq (thing-at (neighbour p dir)) 'wall))) |
|
|
|
|
|
|
|
|
|
(defun sort-vecs (a b) |
|
|
|
|
(< (caddar a) (caddar b))) |
|
|
|
|
|
|
|
|
|
(defun delta-score (olddir newdir) |
|
|
|
|
(if (equal olddir newdir) 1 1001)) |
|
|
|
|
|
|
|
|
|
(defun explore (start-vects) |
|
|
|
|
(let ((start-vect (car start-vects))) |
|
|
|
|
(if (eq (thing-at (car start-vect)) 'end) (progn (push start-vects scores) nil) |
|
|
|
|
(let* ((p (car start-vect)) |
|
|
|
|
(dir (cadr start-vect)) |
|
|
|
|
(score (caddr start-vect)) |
|
|
|
|
(acceptable-next-dirs (--filter (acceptable-p p it) (next-dirs dir)))) |
|
|
|
|
(if (-contains-p book (list p dir)) (progn (push start-vects discard) nil) |
|
|
|
|
(push (list p dir) book) |
|
|
|
|
(--map (cons (list (neighbour p it) it (+ score (delta-score it dir))) start-vects) acceptable-next-dirs)))))) |
|
|
|
|
|
|
|
|
|
(setq book nil |
|
|
|
|
scores nil |
|
|
|
|
discard nil) |
|
|
|
|
|
|
|
|
|
(setq start-list (list (list start-vector))) |
|
|
|
|
(while (setq start-list (-concat (explore (car start-list)) (cdr start-list))) |
|
|
|
|
(setq start-list (-sort #'sort-vecs start-list))) |
|
|
|
|
(let ((best (list (cadr scores))) |
|
|
|
|
(repechage t)) |
|
|
|
|
(while repechage |
|
|
|
|
(setq repechage (-filter (lambda (candidate) |
|
|
|
|
(--any-p (-contains-p it (car candidate)) best)) |
|
|
|
|
discard)) |
|
|
|
|
(setq best (-union repechage best) |
|
|
|
|
discard (-difference discard repechage))) |
|
|
|
|
(length (-distinct (--mapcat (-map #'car it) best)))) |
|
|
|
|
(setq start-vector (list start '(1 0) 0)) ; starting point, direction and score |
|
|
|
|
|
|
|
|
|
(defun next-dirs (dir) |
|
|
|
|
(--filter (>= (dot it dir) 0) '((0 1) (0 -1) (-1 0) (1 0)))) |
|
|
|
|
|
|
|
|
|
(defun acceptable-p (p dir) |
|
|
|
|
(not (eq (thing-at (neighbour p dir)) 'wall))) |
|
|
|
|
|
|
|
|
|
(defun sort-vecs (a b) |
|
|
|
|
(< (caddar a) (caddar b))) |
|
|
|
|
|
|
|
|
|
(defun delta-score (olddir newdir) |
|
|
|
|
(if (equal olddir newdir) 1 1001)) |
|
|
|
|
|
|
|
|
|
(defun explore (start-vects) |
|
|
|
|
(let ((start-vect (car start-vects))) |
|
|
|
|
(if (eq (thing-at (car start-vect)) 'end) (progn (push start-vects scores) nil) |
|
|
|
|
(let* ((p (car start-vect)) |
|
|
|
|
(dir (cadr start-vect)) |
|
|
|
|
(score (caddr start-vect)) |
|
|
|
|
(acceptable-next-dirs (--filter (acceptable-p p it) (next-dirs dir)))) |
|
|
|
|
(if (-contains-p book (list p dir)) (progn (push start-vects discard) nil) |
|
|
|
|
(push (list p dir) book) |
|
|
|
|
(--map (cons (list (neighbour p it) it (+ score (delta-score it dir))) start-vects) acceptable-next-dirs)))))) |
|
|
|
|
|
|
|
|
|
(setq book nil |
|
|
|
|
scores nil |
|
|
|
|
discard nil) |
|
|
|
|
|
|
|
|
|
(setq start-list (list (list start-vector))) |
|
|
|
|
(while (setq start-list (-concat (explore (car start-list)) (cdr start-list))) |
|
|
|
|
(setq start-list (-sort #'sort-vecs start-list))) |
|
|
|
|
(let ((best (list (cadr scores))) |
|
|
|
|
(repechage t)) |
|
|
|
|
(while repechage |
|
|
|
|
(setq repechage (-filter (lambda (candidate) |
|
|
|
|
(--any-p (-contains-p it (car candidate)) best)) |
|
|
|
|
discard)) |
|
|
|
|
(setq best (-union repechage best) |
|
|
|
|
discard (-difference discard repechage))) |
|
|
|
|
(length (-distinct (--mapcat (-map #'car it) best)))) |
|
|
|
|
#+end_src |
|
|
|
|
|
|
|
|
|
#+results: |
|
|
|
|
: 456 |
|
|
|
|
|
|
|
|
|
|