branch: elpa/pacmacs
commit 12942ddeffe80701a7f68f72ab967cc40f3cd740
Author: rexim <[email protected]>
Commit: rexim <[email protected]>
Refactor out pacmacs--fill-board (#74)
---
pacmacs-board.el | 9 +++++++++
pacmacs.el | 15 ++-------------
test/pacmacs-board-test.el | 12 ++++++++++++
test/pacmacs-test.el | 9 ---------
4 files changed, 23 insertions(+), 22 deletions(-)
diff --git a/pacmacs-board.el b/pacmacs-board.el
index 33934a1acd..628afabab8 100644
--- a/pacmacs-board.el
+++ b/pacmacs-board.el
@@ -82,6 +82,15 @@
(cons (mod (+ row d-row) height)
(mod (+ column d-column) width)))))
+(defun pacmacs--fill-board (board value)
+ (plist-bind ((width :width)
+ (height :height)
+ (data :data))
+ board
+ (dotimes (row height)
+ (dotimes (column width)
+ (aset (aref data row) column value)))))
+
(provide 'pacmacs-board)
;;; pacmacs-board.el ends here
diff --git a/pacmacs.el b/pacmacs.el
index 244def47c9..2e5e18b665 100644
--- a/pacmacs.el
+++ b/pacmacs.el
@@ -186,11 +186,6 @@
(plist-put game-object :column new-column)))
(plist-put game-object :speed-counter (1- speed-counter)))))
-(defun pacmacs--fill-board (board width height value)
- (dotimes (row height)
- (dotimes (column width)
- (aset (aref board row) column value))))
-
(defun pacmacs--possible-ways (row column)
(list (cons (1+ row) column)
(cons row (1+ column))
@@ -220,10 +215,7 @@
pacmacs-inversed-direction-table)))))
(defun pacmacs--recalc-track-board ()
- (pacmacs--fill-board pacmacs-track-board
- pacmacs-board-width
- pacmacs-board-height
- nil)
+ (pacmacs--fill-board pacmacs-track-board nil)
(plist-bind ((player-row :row)
(player-column :column))
pacmacs-player-state
@@ -321,10 +313,7 @@
(when pacmacs-debug-output
(pacmacs-render-track-board))
- (pacmacs--fill-board pacmacs-board
- pacmacs-board-width
- pacmacs-board-height
- (pacmacs--make-empty-cell))
+ (pacmacs--fill-board pacmacs-board (pacmacs--make-empty-cell))
(pacmacs--put-object pacmacs-player-state)
diff --git a/test/pacmacs-board-test.el b/test/pacmacs-board-test.el
index fa81b026ce..f936a17905 100644
--- a/test/pacmacs-board-test.el
+++ b/test/pacmacs-board-test.el
@@ -54,3 +54,15 @@
row column
'left)))))
+(ert-deftest pacmacs--fill-board-test ()
+ (let ((input-board (list :width 2
+ :height 2
+ :data [[nil nil]
+ [nil nil]]))
+ (expected-board (list :width 2
+ :height 2
+ :data [[5 5]
+ [5 5]])))
+ (pacmacs--fill-board input-board 5)
+ (should (equal expected-board
+ input-board))))
diff --git a/test/pacmacs-test.el b/test/pacmacs-test.el
index 58c61a2d55..e3e434d898 100644
--- a/test/pacmacs-test.el
+++ b/test/pacmacs-test.el
@@ -1,13 +1,4 @@
-(ert-deftest pacmacs--fill-board-test ()
- (let ((input-board [[nil nil]
- [nil nil]])
- (expected-board [[5 5]
- [5 5]]))
- (pacmacs--fill-board input-board 2 2 5)
- (should (equal expected-board
- input-board))))
-
(ert-deftest pacmacs--cell-tracked-p-test ()
(let ((pacmacs-track-board (list :width 2
:height 2