The   game of Pig   is a multiplayer game played with a single six-sided die.   The
object of the game is to reach   100   points or more.  
Play is taken in turns.   On each person's turn that person has the option of either:

 Rolling the dice:   where a roll of two to six is added to their score for that turn and the player's turn continues as the player is given the same choice again;   or a roll of   1   loses the player's total points   for that turn   and their turn finishes with play passing to the next player.
 Holding:   the player's score for that round is added to their total and becomes safe from the effects of throwing a   1   (one).   The player's turn finishes with play passing to the next player.


Task

Create a program to score for, and simulate dice throws for, a two-person game.



Related task

   Pig the dice game/Player


(def max 100)
 
(defn roll-dice []
  (let [roll (inc (rand-int 6))]
    (println "Rolled:" roll) roll))
 
(defn switch [player]
  (if (= player :player1) :player2 :player1))
 
(defn find-winner [game]
  (cond
    (>= (:player1 game) max) :player1
    (>= (:player2 game) max) :player2
    :else nil))
 
(defn bust []
  (println "Busted!") 0)
 
(defn hold [points]
  (println "Sticking with" points) points)
 
(defn play-round [game player temp-points]
  (println (format "%s: (%s, %s).  Want to Roll? (y/n) " (name player) (player game) temp-points))
  (let [input (clojure.string/upper-case (read-line))]
    (if (.equals input "Y")
      (let [roll (roll-dice)]
        (if (= 1 roll)
          (bust)
          (play-round game player (+ roll temp-points))))
      (hold temp-points))))
 
(defn play-game [game player]
    (let [winner (find-winner game)]
      (if (nil? winner)
        (let [points (play-round game player 0)]
          (recur (assoc game player (+ points (player game))) (switch player)))
        (println (name winner) "wins!"))))
 
(defn -main [& args]
  (println "Pig the Dice Game.")
  (play-game {:player1 0, :player2 0} :player1))