mirror of
https://github.com/Xevion/lisp-projects.git
synced 2025-12-06 07:15:29 -06:00
temporary rename of games dir
This commit is contained in:
@@ -1,13 +0,0 @@
|
||||
# games
|
||||
|
||||
## About
|
||||
|
||||
A list of games completed as I read the book 'Land of Lisp'.
|
||||
|
||||
## Games List
|
||||
|
||||
#### GuessMyNumber
|
||||
|
||||
[source](./GuessMyNumber/GuessMyNumber.lisp) | [explanation](./GuessMyNumber/GuessMyNumber.MD)
|
||||
|
||||
A simple game where the player guesses a number, and the program continuously returns guesses as the player indicates if said guesses are smaller, lower, or equal to the guess given.
|
||||
@@ -1,11 +0,0 @@
|
||||
# GuessMyNumber
|
||||
|
||||
For my first problem, I decided to go beyond the book and create a prompting game.
|
||||
|
||||
Reading from IO is much different, and much harder to understand what's actually happening.
|
||||
|
||||
I copied the `prompt` function from [`Prompt.lisp`](../../scripts/Prompt.lisp), which I acquired from **StackOverflow**.
|
||||
|
||||
I'm honestly having trouble understanding booleans, why hyphens are used, why capitalization is considered horrible, why `car` and `cdr` are used, why they're being introduced instead of some kind of *nth index list access*, among so many other strange concepts that the book introduced.
|
||||
|
||||
Additionally, I'm not sure why the REPL is so emphasized whenever long term programming is done with files, why tiny functions are emphasized with `flet`, and why none of this is explained whenever most people will be coming from a background with `non-lisp`, `C-like` experience, i.e. Java, Python, C++ or Javascript.
|
||||
@@ -1,47 +0,0 @@
|
||||
(defparameter *small* 1)
|
||||
(defparameter *big* 100)
|
||||
|
||||
|
||||
(defun start-over ()
|
||||
(defparameter *small* 1)
|
||||
(defparameter *big* 100)
|
||||
(guess-my-number)
|
||||
)
|
||||
|
||||
(defun smaller()
|
||||
(setf *small* (1- (guess-my-number)))
|
||||
(print (guess-my-number))
|
||||
)
|
||||
|
||||
(defun bigger()
|
||||
(setf *big* (1+ (guess-my-number)))
|
||||
(print (guess-my-number))
|
||||
)
|
||||
|
||||
(defun guess-my-number ()
|
||||
(ash (+ *small* *big*) -1)
|
||||
)
|
||||
|
||||
(defun game-loop ()
|
||||
(flet ((prompt (string)
|
||||
(format "~A " string)
|
||||
(finish-output)
|
||||
(read nil 'eof nil)))
|
||||
(fresh-line)
|
||||
(let
|
||||
((last "?"))
|
||||
(loop while (not (equal last "="))
|
||||
|
||||
do (setf last (prompt (format t "Is '~A' Smaller (<) or Larger (>)?" (guess-my-number))))
|
||||
(cond
|
||||
((string= last "<") (smaller))
|
||||
((string= last ">") (bigger))
|
||||
((string= last "=") (start-over))
|
||||
(t (print "Invalid Input") (print last) (fresh-line))
|
||||
)
|
||||
'DONE))
|
||||
)
|
||||
)
|
||||
|
||||
(print (equal "+" "+"))
|
||||
(game-loop)
|
||||
Reference in New Issue
Block a user