[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/pacmacs 25193bcdbf 289/472: Better running away algorithm
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/pacmacs 25193bcdbf 289/472: Better running away algorithm (#153) |
Date: |
Thu, 6 Jan 2022 21:59:32 -0500 (EST) |
branch: elpa/pacmacs
commit 25193bcdbfe4e934be7b3a3a31bc5ea65a46be55
Author: rexim <reximkut@gmail.com>
Commit: rexim <reximkut@gmail.com>
Better running away algorithm (#153)
---
pacmacs-utils.el | 6 ++++++
pacmacs.el | 37 ++++++++++++++++++++++++++++---------
2 files changed, 34 insertions(+), 9 deletions(-)
diff --git a/pacmacs-utils.el b/pacmacs-utils.el
index f00b07a980..c3650756d6 100644
--- a/pacmacs-utils.el
+++ b/pacmacs-utils.el
@@ -64,6 +64,12 @@ side-effects."
'down (cons 1 0))))
(plist-get direction-table direction)))
+(defun pacmacs--squared-distance (row1 column1 row2 column2)
+ (let ((d-row (- row2 row1))
+ (d-column (- column2 column1)))
+ (+ (* d-row d-row)
+ (* d-column d-column))))
+
(defun pacmacs--direction-name (direction-vector)
(let ((direction-table '((( 0 . -1) . left)
(( 0 . 1) . right)
diff --git a/pacmacs.el b/pacmacs.el
index 439e8ec689..3b444f6696 100644
--- a/pacmacs.el
+++ b/pacmacs.el
@@ -336,13 +336,6 @@
(let ((direction (pacmacs--cell-wrapped-get pacmacs--track-board row
column)))
(pacmacs--switch-direction game-object direction))))
-(defun pacmacs--back-track-object (game-object)
- (plist-bind ((row :row)
- (column :column))
- game-object
- (let ((direction (pacmacs--cell-wrapped-get pacmacs--track-board row
column)))
- (pacmacs--switch-direction game-object (pacmacs--opposite-direction-name
direction)))))
-
(defun pacmacs-tick ()
(interactive)
@@ -365,10 +358,36 @@
(pacmacs--track-object ghost)
(pacmacs--step-object ghost)))
+(defun pacmacs--run-away-direction (game-object-1 game-object-2)
+ (plist-bind ((row-1 :row)
+ (column-1 :column))
+ game-object-1
+ (plist-bind ((row-2 :row)
+ (column-2 :column))
+ game-object-2
+ (let* ((current-distance (pacmacs--squared-distance row-1 column-1
+ row-2 column-2))
+ (possible-ways
+ (->> (pacmacs--possible-side-ways row-1 column-1)
+ (-remove (-lambda ((row . column))
+ (or (pacmacs--wall-at-p row column)
+ (> current-distance
+ (pacmacs--squared-distance row column
+ row-2
column-2))))))))
+ (-when-let ((row . column) (car possible-ways))
+ (pacmacs--direction-name (cons (- row row-1)
+ (- column column-1))))))))
+
(defun pacmacs--step-terrified-ghosts ()
(dolist (terrified-ghost pacmacs--terrified-ghosts)
- (pacmacs--back-track-object terrified-ghost)
- (pacmacs--step-object terrified-ghost)))
+ (plist-bind ((row :row)
+ (column :column))
+ terrified-ghost
+ (-when-let (direction (pacmacs--run-away-direction
+ terrified-ghost
+ pacmacs--player-state))
+ (pacmacs--switch-direction terrified-ghost direction))
+ (pacmacs--step-object terrified-ghost))))
(defun pacmacs--detect-pill-collision ()
(plist-bind ((row :row)
- [nongnu] elpa/pacmacs 805d91d22b 194/472: Rename all the buffer stuff to board back (#105), (continued)
- [nongnu] elpa/pacmacs 805d91d22b 194/472: Rename all the buffer stuff to board back (#105), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 1ab8264214 198/472: Remove dead vars for board size (#126), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 144a973d83 203/472: Merge branch 'slow-object-look-up-126'. Close #126, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 6a4bf8c87f 214/472: Merge branch 'integration-test-recorder-115'. Close #115, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs b73dd8215c 220/472: Merge branch 'integration-test-replayer-122'. Close #122, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 1eadfb94fd 225/472: Refactor out pacmacs--wall-cells list (#81), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 843d428744 226/472: Refactor out pacmacs--big-pills list (#81), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 7eafd1bf11 017/472: Merge branch 'split-merged-modules-19'. Close #19, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs f88ea61b10 035/472: Merge branch 'ut-coverage-27'. Close #27, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 9acb9eefa4 286/472: Introduce a constructor for terrified ghosts (#153), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 25193bcdbf 289/472: Better running away algorithm (#153),
ELPA Syncer <=
- [nongnu] elpa/pacmacs 8fd7660240 290/472: Terrify ghosts by eating big pill (#153), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs e4e4053c26 306/472: Ghost terrified time as constant (#159), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 1978363e9d 310/472: Fix handle-ghost-blinking-threshold (#159), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs a896a83366 312/472: Merge pull request #164 from codingteam/blink-almost-timed-out-159, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs d3c94de6da 320/472: Remove UT for pacmacs--track-point (#159), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 8b40dc51cf 330/472: Add 1st big pill level (#162), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 49292e34d3 342/472: UT for terrified-ghost-timed-out-p function (#171), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 40a3d00209 367/472: Implement glowing walls (#138), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 5c45e17c40 399/472: Add docs for destroy function (#134), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs f79355209d 060/472: Refactor out functions for creating images (#51), ELPA Syncer, 2022/01/06