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

fertig! #1054

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

fertig! #1054

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
70 changes: 59 additions & 11 deletions src/p_p_p_pokerface.clj
Original file line number Diff line number Diff line change
@@ -1,34 +1,82 @@
(ns p-p-p-pokerface)

(defn rank [card]
nil)
(let [given-rank (first card)]
(let [rank-map {\T 10, \J 11, \Q 12, \K 13, \A 14}]
(if (Character/isDigit given-rank)
(Integer/valueOf (str given-rank))
(get rank-map given-rank)))))

(defn suit [card]
nil)
(str (second card)))

;(def high-seven ["2H" "3S" "4C" "5C" "7D"])
;(def pair-hand ["2H" "2S" "4C" "5C" "7D"])
;(def two-pairs-hand ["2H" "2S" "4C" "4D" "7D"])
;(def three-of-a-kind-hand ["2H" "2S" "2C" "4D" "7D"])
;(def four-of-a-kind-hand ["2H" "2S" "2C" "2D" "7D"])
;(def straight-hand ["2H" "3S" "6C" "5D" "4D"])
;(def low-ace-straight-hand ["2H" "3S" "4C" "5D" "AD"])
;(def high-ace-straight-hand ["TH" "AS" "QC" "KD" "JD"])
;(def flush-hand ["2H" "4H" "5H" "9H" "7H"])
;(def full-house-hand ["2H" "5D" "2D" "2C" "5S"])
;(def straight-flush-hand ["2H" "3H" "6H" "5H" "4H"])
;(def low-ace-straight-flush-hand ["2D" "3D" "4D" "5D" "AD"])
;(def high-ace-straight-flush-hand ["TS" "AS" "QS" "KS" "JS"])

(defn pair? [hand]
nil)
(> (apply max (vals (frequencies (map rank hand)))) 1))

(defn three-of-a-kind? [hand]
nil)
(contains? (set (vals (frequencies (map rank hand)))) 3))

(defn four-of-a-kind? [hand]
nil)
(contains? (set (vals (frequencies (map rank hand)))) 4))

(defn flush? [hand]
nil)
(contains? (set (vals (frequencies (map suit hand)))) 5))

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

(defn two-pairs? [hand]
nil)
(or (= [1 2 2] (sort (vals (frequencies (map rank hand)))))
(= [1 4] (sort (vals (frequencies (map rank hand)))))))

(defn straight? [hand]
nil)
(let [sorted (sort (map rank hand))
sorted-with-replacement (if (and (= (apply min sorted) 2) (= 14 (apply max sorted)))
(sort (replace {14 1} sorted))
)]
(if (not-empty sorted-with-replacement)
(= (range (apply min sorted-with-replacement) (+ 1 (apply max sorted-with-replacement))) sorted-with-replacement)
(= (range (apply min sorted) (+ 1 (apply max sorted))) sorted)
)))

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

(defn high-card? [hand]
true)

(defn value [hand]
nil)
(cond
(straight-flush? hand) 8
(four-of-a-kind? hand) 7
(full-house? hand) 6
(flush? hand) 5
(straight? hand) 4
(three-of-a-kind? hand) 3
(two-pairs? hand) 2
(pair? hand) 1
(high-card? hand) 0)
;(let [checkers #{[high-card? 0] [pair? 1]
; [two-pairs? 2] [three-of-a-kind? 3]
; [straight? 4] [flush? 5]
; [full-house? 6] [four-of-a-kind? 7]
; [straight-flush? 8]}
; given-hand (fn [checker] ((first checker) hand))]
; (apply max (map second (filter given-hand checkers))))
)