aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoic Guegan <manzerberdes@gmx.com>2019-05-08 18:33:08 +0200
committerLoic Guegan <manzerberdes@gmx.com>2019-05-08 18:33:08 +0200
commit614c7a627897da3250bcc9853ddea8fe4b523e9e (patch)
tree6f33aba44c849b170c57a98c362d1a1fa1764db1
parentf72400bf2216828d442d161bd48158508c4f4526 (diff)
Debug add-food
-rw-r--r--server/game.lisp11
1 files changed, 10 insertions, 1 deletions
diff --git a/server/game.lisp b/server/game.lisp
index a43cd10..517db0d 100644
--- a/server/game.lisp
+++ b/server/game.lisp
@@ -36,6 +36,7 @@
(format t "~%Direction: ~a" dir)
(format t "~%Food: ~a" food)))
+;;; Note that there is no waranty that nb food are added (ex: if food position collide with snake position)
(defgeneric add-food (g nb)
(:documentation "Add food on the game grid."))
@@ -96,6 +97,14 @@
;; Check if we loose
)
+;;; Function to compare two list of two elements
+(defun equal-coord (c1 c2)
+ (let ((x1 (car c1))
+ (x2 (car c2))
+ (y1 (car (cdr c1)))
+ (y2 (car (cdr c2))))
+ (and (eql x1 x2) (eql y1 y2))))
+
(defmethod add-food ((g game) nb)
(with-slots (snake grid-size food) g
(let ((snake-list (coerce snake 'list)) ; To be able to use the function member later
@@ -106,5 +115,5 @@
(dotimes (i nb)
(let ((x (random size-x))
(y (random size-y)))
- (when (eq (member (list x y) snake-list) nil) ; Add if there is no conflict between snake and food position
+ (when (eq (member (list x y) snake-list :test #'equal-coord) nil) ; Add if there is no conflict between snake and food position
(setf food (make-array (1+ food-size) :initial-contents `(,@food-list ,(list x y))))))))))