/mahjong-engine

An implementation of a game-engine for Mahjong.

Primary LanguageClojureEclipse Public License 1.0EPL-1.0

mahjong-engine

A Clojure library implementing a simple Mahjong game-engine.

Usage

Require the library in the repl

(require '[mahjong-engine.core :as m])

Creating a new game

new-game returns a fn that takes a keyword as argument.

(def game (m/new-game))

Some GETTERS...

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))

Some SETTERS...

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))))

More to come!

License

Copyright © 2017 Stan Verberkt

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.