[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/pacmacs 2297996e29 323/472: Smarter running away algorithm
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/pacmacs 2297996e29 323/472: Smarter running away algorithm (#159) |
Date: |
Thu, 6 Jan 2022 21:59:36 -0500 (EST) |
branch: elpa/pacmacs
commit 2297996e290db5c74b2387a4114f825f8efc7f6c
Author: rexim <reximkut@gmail.com>
Commit: rexim <reximkut@gmail.com>
Smarter running away algorithm (#159)
---
pacmacs.el | 59 +++++++++++++++++++++-------------------------------
test/pacmacs-test.el | 12 -----------
2 files changed, 24 insertions(+), 47 deletions(-)
diff --git a/pacmacs.el b/pacmacs.el
index df0c45c607..82fe6eaee8 100644
--- a/pacmacs.el
+++ b/pacmacs.el
@@ -355,27 +355,40 @@
(append next-wave candidate-ways))))
(setq wave next-wave))))))
-(defun pacmacs--track-object (game-object)
+(defun pacmacs--track-object-direction (game-object sort-comparator)
(plist-bind ((row :row)
(column :column))
game-object
- (let* ((candidate-ways (-remove (-lambda ((candidate-row .
candidate-column))
- (pacmacs--wall-at-p candidate-row
candidate-column))
- (pacmacs--possible-side-ways row column)))
+ (let* ((candidate-ways (cons
+ (cons row column)
+ (-remove (-lambda ((candidate-row .
candidate-column))
+ (pacmacs--wall-at-p candidate-row
candidate-column))
+ (pacmacs--possible-side-ways row
column))))
(candidate-distances (-map (-lambda ((candidate-row .
candidate-column))
(pacmacs--cell-wrapped-get
pacmacs--track-board
candidate-row
candidate-column))
candidate-ways))
(next-tile (->> (-zip candidate-distances candidate-ways)
- (-sort (-lambda ((distance-1 . _) (distance-2 . _))
- (< distance-1 distance-2)))
- (car)
- (cdr))))
+ (-sort sort-comparator)
+ (cdar))))
(when next-tile
(->> (pacmacs--vector- next-tile (cons row column))
- (pacmacs--direction-name)
- (pacmacs--switch-direction game-object))))))
+ (pacmacs--direction-name))))))
+
+(defun pacmacs--track-object (game-object)
+ (-when-let (direction (pacmacs--track-object-direction
+ game-object
+ (-lambda ((distance-1 . _) (distance-2 . _))
+ (< distance-1 distance-2))))
+ (pacmacs--switch-direction game-object direction)))
+
+(defun pacmacs--back-track-object (game-object)
+ (-when-let (direction (pacmacs--track-object-direction
+ game-object
+ (-lambda ((distance-1 . _) (distance-2 . _))
+ (> distance-1 distance-2))))
+ (pacmacs--switch-direction game-object direction)))
(defun pacmacs-tick ()
(interactive)
@@ -399,33 +412,9 @@
(pacmacs--track-object ghost)
(pacmacs--step-object ghost)))
-(defun pacmacs--run-away-direction (runner bogey blocked-tile-predicate)
- (plist-bind ((runner-row :row)
- (runner-column :column))
- runner
- (plist-bind ((bogey-row :row)
- (bogey-column :column))
- bogey
- (let* ((current-distance (pacmacs--squared-distance runner-row
runner-column
- bogey-row
bogey-column))
- (possible-ways
- (->> (pacmacs--possible-side-ways runner-row runner-column)
- (-remove (-lambda ((row . column))
- (or (funcall blocked-tile-predicate row column)
- (> current-distance
- (pacmacs--squared-distance row column
- bogey-row
bogey-column))))))))
- (-when-let ((row . column) (car possible-ways))
- (pacmacs--direction-name (cons (- row runner-row)
- (- column runner-column))))))))
-
(defun pacmacs--step-terrified-ghosts ()
(dolist (terrified-ghost pacmacs--terrified-ghosts)
- (-when-let (direction (pacmacs--run-away-direction
- terrified-ghost
- pacmacs--player-state
- #'pacmacs--wall-at-p))
- (pacmacs--switch-direction terrified-ghost direction))
+ (pacmacs--back-track-object terrified-ghost)
(pacmacs--step-object terrified-ghost)))
(defun pacmacs--create-game-object (row column list-name constructor)
diff --git a/test/pacmacs-test.el b/test/pacmacs-test.el
index 4d349cca2d..a8d6e650e8 100644
--- a/test/pacmacs-test.el
+++ b/test/pacmacs-test.el
@@ -42,18 +42,6 @@
(should (equal expected-outcome
pacmacs--terrified-ghosts))))
-(ert-deftest pacmacs--run-away-direction-test ()
- (let ((runner '(:row 2 :column 2))
- (bogey '(:row 2 :column 3))
- (walls '((1 . 2)
- (3 . 2)))
- (blocked-tile-predicate (-lambda (row column)
- (-find (-partial #'equal (cons row column))
- walls))))
- (should (equal (pacmacs--run-away-direction runner bogey
- blocked-tile-predicate)
- 'left))))
-
(ert-deftest pacmacs--replace-game-objects-test ()
(let* ((game-objects '((:row 10 :column 20)
(:row 30 :column 40)))
- [nongnu] elpa/pacmacs d8a7998192 277/472: Extract `cask install` to separate step in README, (continued)
- [nongnu] elpa/pacmacs d8a7998192 277/472: Extract `cask install` to separate step in README, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 614a98ccc7 278/472: Cleanup README, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs fa6eca1731 284/472: Introduce list for terrified ghost objects (#153), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 701da0f16c 285/472: Rename direction switching callbacks (#153), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs cfa4437107 292/472: Implement eating terrified ghosts (#153), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs ece3e76f30 296/472: Rename run-away-direction arguments (#153), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 24ddb1b9ad 303/472: Merge pull request #160 from codingteam/terrified-ghost-state-153, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 5cb14f20fd 301/472: UT for pacmacs--replace-game-objects (#153), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 00b3223066 305/472: Handle ghost bling threshold (#159), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs d608708f15 311/472: UT for handle-ghost-blinking-threshold (#159), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 2297996e29 323/472: Smarter running away algorithm (#159),
ELPA Syncer <=
- [nongnu] elpa/pacmacs 9b714e4678 321/472: Fix pacmacs--track-object UT (#159), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 16a6ac7e98 327/472: UT for pacmacs--render-track-board, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 729de2de92 329/472: Remove big from the first level (#162), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 556098da2e 337/472: Put big pills level before w/o BP ones (#162), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 151da84fdc 338/472: Remove replace-game-object function (#171), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs c4c2fbfa6f 347/472: Merge branch 'master' into unterrified-original-possition-171, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 9375a8a3e7 351/472: Merge branch 'master' into unterrified-original-possition-171, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 51a2ac25fe 354/472: Merge pull request #175 from codingteam/maps-with-big-pills-162, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 470f11b433 357/472: Reset terrified timer on eating BP (#173), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 46219c3370 368/472: Smaller default weight for walls (#138), ELPA Syncer, 2022/01/06