Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1035

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Fix #1035

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: clojure
lein: lein2
script: lein2 midje :config .midje-grading-config.clj
lein: lein
script: lein midje :config .midje-grading-config.clj
jdk:
- openjdk7
notifications:
Expand Down
67 changes: 56 additions & 11 deletions src/p_p_p_pokerface.clj
Original file line number Diff line number Diff line change
@@ -1,34 +1,79 @@
(ns p-p-p-pokerface)

(def rank-replacements
{\T 10, \J 11, \Q 12, \K 13, \A 14})

(defn rank [card]
nil)
(let [[fst _] card]
(if (Character/isDigit fst)
(Integer/valueOf (str fst))
(get rank-replacements fst))))

(defn suit [card]
nil)
(let [[_ snd] card]
(str snd)))

(defn x-of-a-kind? [x hand]
(let [ranks-in-hand (map rank hand)]
(= x (apply max (vals (frequencies ranks-in-hand))))))

(defn pair? [hand]
nil)
(x-of-a-kind? 2 hand))

(defn three-of-a-kind? [hand]
nil)
(x-of-a-kind? 3 hand))

(defn four-of-a-kind? [hand]
nil)
(x-of-a-kind? 4 hand))

(defn flush? [hand]
nil)
(let [suits-in-hand (map suit hand)]
(= 5 (apply max (vals (frequencies suits-in-hand))))))

(defn full-house? [hand]
nil)
(let [rank-frequencies (set (vals (frequencies (map rank hand))))]
(and
(contains? rank-frequencies 2)
(contains? rank-frequencies 3))))

(defn two-pairs? [hand]
nil)
(let [rank-frequencies (vals (frequencies (map rank hand)))
two? (fn [x] (= 2 x))]
(= 2 (count (filter two? rank-frequencies)))))

; uh
(defn straight? [hand]
nil)
(let [rank-set (set (map rank hand))
min-rank (apply min rank-set)]
(or
(= rank-set #{10 11 12 13 14})
(= rank-set #{14 2 3 4 5})
(and
(contains? rank-set (+ 1 min-rank))
(contains? rank-set (+ 2 min-rank))
(contains? rank-set (+ 3 min-rank))
(contains? rank-set (+ 4 min-rank))))))

(defn straight-flush? [hand]
nil)
(and (straight? hand) (flush? hand)))

(defn high-card? [hand]
true)

(def value-tests
[{:test high-card?, :value 0}
{:test pair?, :value 1}
{:test two-pairs?, :value 2}
{:test three-of-a-kind?, :value 3}
{:test straight?, :value 4}
{:test flush?, :value 5}
{:test full-house?, :value 6}
{:test four-of-a-kind?, :value 7}
{:test straight-flush?, :value 8}])

(defn value [hand]
nil)
(let [if-test-ok-then-value (fn [value-test]
(if ((:test value-test) hand)
(:value value-test)
0))]
(apply max (map if-test-ok-then-value value-tests))))