Permalink
Browse files

robots.lisp

  • Loading branch information...
1 parent d1ddf54 commit 46857d1ebfe1cd9bd9c4e993e2928e0f350180a8 Andrey Paramonov committed Dec 5, 2010
Showing with 42 additions and 0 deletions.
  1. +42 −0 robots.lisp
View
@@ -0,0 +1,42 @@
+(defun robots ()
+ (loop named main
+ with directions = '((q . -65) (w . -64) (e . -63) (a . -1)
+ (d . 1) (z . 63) (x . 64) (c . 65))
+ for pos = 544
+ then (progn (format t "~%qwe/asd/zxc to move, (t)eleport, (l)eave:")
+ (force-output)
+ (let* ((c (read))
+ (d (assoc c directions)))
+ (cond (d (+ pos (cdr d)))
+ ((eq 't c) (random 1024))
+ ((eq 'l c) (return-from main 'bye))
+ (t pos))))
+ for monsters = (loop repeat 10
+ collect (random 1024))
+ then (loop for mpos in monsters
+ collect (if (> (count mpos monsters) 1)
+ mpos
+ (cdar (sort (loop for (k . d) in directions
+ for new-mpos = (+ mpos d)
+ collect (cons (+ (abs (- (mod new-mpos 64)
+ (mod pos 64)))
+ (abs (- (ash new-mpos -6)
+ (ash pos -6))))
+ new-mpos))
+ '<
+ :key #'car))))
+ when (loop for mpos in monsters
+ always (> (count mpos monsters) 1))
+ return 'player-wins
+ do (format t
+ "~%|~{~<|~%|~,65:;~A~>~}|"
+ (loop for p
+ below 1024
+ collect (cond ((member p monsters)
+ (cond ((= p pos) (return-from main 'player-loses))
+ ((> (count p monsters) 1) #\#)
+ (t #\A)))
+ ((= p pos)
+ #\@)
+ (t
+ #\ ))))))

0 comments on commit 46857d1

Please sign in to comment.