Created
September 10, 2024 04:02
-
-
Save nivekuil/8fcaa814859af1724f2c29ee0e78999e to your computer and use it in GitHub Desktop.
poker.cljc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns game.poker | |
(:require [meander.epsilon :as mean] | |
[hyperfiddle.rcf :as rcf])) | |
(defn match [hand] | |
(mean/find | |
hand | |
(mean/scan {::rank ?x} ..4) | |
::Quad | |
(mean/scan {::rank ?x1} ..3 _ ... {::rank ?x2} ..2) | |
::FullHouse | |
(mean/scan {::rank ?x2} ..2 _ ... {::rank ?x1} ..3) | |
::FullHouse | |
(mean/scan {::rank ?x1} | |
{::rank (mean/pred #(= % (+ 1 ?x1)))} | |
{::rank (mean/pred #(= % (+ 2 ?x1)))} | |
{::rank (mean/pred #(= % (+ 3 ?x1)))} | |
{::rank (mean/pred #(= % (+ 4 ?x1)))}) | |
::Straight | |
(mean/scan {::rank ?x1} | |
{::rank (mean/pred #(= % (- ?x1 1)))} | |
{::rank (mean/pred #(= % (- ?x1 2)))} | |
{::rank (mean/pred #(= % (- ?x1 3)))} | |
{::rank (mean/pred #(= % (- ?x1 4)))}) | |
::Straight | |
(mean/scan {::suit ?x} ..5) | |
::Flush | |
(mean/scan {::rank ?x} ..3) | |
::Triple | |
(mean/scan {::rank ?x} {::rank ?x} . _ ... {::rank ?y} {::rank ?y}) | |
::TwoPair | |
(mean/scan {::rank ?x} {::rank ?x}) | |
::Pair | |
[{::rank _} ..1] ::HighCard)) | |
(rcf/enable!) | |
(rcf/tests | |
(match [{::rank 8} | |
{::rank 1} | |
{::rank 2} | |
{::rank 2} | |
{::rank 2} | |
{::rank 2 | |
::suit ::Club}]) := ::Quad | |
(match [{::rank 2} | |
{::rank 2} | |
{::rank 2} | |
{::rank 5} | |
{::rank 1} | |
{::rank 1 | |
::suit ::Club} | |
{::rank 9 | |
::suit ::Club}]) := ::FullHouse | |
(match [{::rank 1} | |
{::rank 1} | |
{::rank 2} | |
{::rank 2} | |
{::rank 2 | |
::suit ::Club}]) := ::FullHouse | |
(match [{::rank 4} | |
{::rank 7} | |
{::rank 1} | |
{::rank 2} | |
{::rank 3} | |
{::rank 4} | |
{::rank 5 | |
::suit ::Club}]) := ::Straight | |
(match [{::rank 8} | |
{::rank 6} | |
{::rank 5} | |
{::rank 4} | |
{::rank 3 | |
::suit ::Club} | |
{::rank 2 | |
::suit ::Club} | |
{::rank 8 | |
::suit ::Club}]) := ::Straight | |
(match [{::rank 8} | |
{::rank 6} | |
{::rank 8 | |
::suit ::Club} | |
{::rank 4 | |
::suit ::Club} | |
{::rank 10 | |
::suit ::Club} | |
{::rank 2 | |
::suit ::Club} | |
{::rank 8 | |
::suit ::Club} | |
{::rank 9}]) := ::Flush | |
(match [{::rank 3} | |
{::rank 1} | |
{::rank 2} | |
{::rank 4 | |
::suit ::Club}]) := ::HighCard | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment