Acey Ducey card game in Clojure
I made a Clojure-version of the Acey Ducey card game from the book BASIC Computer Games for fun and learning purposes. It’s not an exact clone but pretty close. The games in that book have been implemented in a lot of different languages already but I didn’t see a Clojure-version.
This version of Acey Ducey is played like this:
The dealer (computer) deals two cards face up. You have an option to bet or not bet depending on whether or not you feel the card will have a value between the first two. If you do not want to bet, input a 0 (zero).
Here’s a gif showing how the game is played:
The code is on GitLab. Run it with
clj -M acey-ducey.clj
What I learned:
- Get input from the user with
read-line
- Trim a string with
clojure.string/trim
- Convert a string to integer with
Integer/parseInt
- Update an atom with
swap!
Finally, I love how easy and intuitive it was to make a a deck of cards with Clojure:
(def deck-unshuffled
(let [suits '("clubs" "hearts" "spades" "diamonds")
names '("two" "three" "four" "five" "six" "seven" "eight"
"nine" "ten" "jack" "queen" "king" "ace")]
(for [suit suits name names]
{:suit suit :name name :value (.indexOf names name)})))