commit 2 games dir rename

This commit is contained in:
Xevion
2020-02-21 01:33:15 -06:00
parent 3f66cfe43a
commit 3cd164a3e5
3 changed files with 71 additions and 0 deletions

13
games/GAMES.MD Normal file
View File

@@ -0,0 +1,13 @@
# 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.

View File

@@ -0,0 +1,11 @@
# 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.

View File

@@ -0,0 +1,47 @@
(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)