A Clojure library implementing a simple Mahjong game-engine.
(require '[mahjong-engine.core :as m])
new-game returns a fn that takes a keyword as argument.
(def game (m/new-game))
Return a collection of maps representing players of the game. Such a map contains :name (string) :hand (coll), :revealed (coll)
((m/game :players))
Return the hand of the current player, should be empty at the start of a new game.
((m/game :hand))
Return the wall of Mahjong-tiles. Tiles are represented as a keyword, e.g. :b1 represents 1 of bamboos, :dg represents green dragon, :wn represents northern wind.
((m/game :wall))
Return a frequency-map of the discarded-tiles
((m/game :discard-pile))
Update the game -> Draw 14 tiles to the hand of the current player
((m/game :draw-tiles) 14)
Update the game -> Discard a tile (requires user input!)
((m/game :discard-tile) (first ((m/game :hand))))
Update the game -> Rotate the players (next player's turn)
((m/game :rotate-players))
Let's say current player has already 13 tiles in is hand
((m/game :draw-tiles) 13)
Usually you'd draw a tile at the beginning of a turn
((m/game :draw-tile))
Return current player's hand
((m/game :hand))
Discard a tile
((m/game :discard-tile) (first ((m/game :hand))))
Copyright © 2017 Stan Verberkt
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.