Skip to content

Instantly share code, notes, and snippets.

@righ1113
Last active October 2, 2019 12:03
Show Gist options
  • Save righ1113/3d6dfd042beb91ae55bccfcfc699d146 to your computer and use it in GitHub Desktop.
Save righ1113/3d6dfd042beb91ae55bccfcfc699d146 to your computer and use it in GitHub Desktop.
ジョーカー付きポーカー役判定をnew syntaxで
;; > egison -N
;; > loadFile("poker-N.egi")
;;;
;;;
;;; Poker-hands demonstration
;;;
;;;
;;
;; Matcher definitions
;;
def suit = algebraicDataMatcher(<spade>, <heart>, <club>, <diamond>)
def card = matcher
| <card $ $> as (suit, mod(13)) ->
| <Card $x $y> -> {(x, y)}
| <Joker> -> matchAll ([<Spade>, <Heart>, <Club>, <Diamond>], 1..13) as (set(suit), set(integer))
| ($s <:> _, $n <:> _) -> (s, n)
| <joker> as () ->
| <Joker> -> {()}
| $ as something ->
| $tgt -> {tgt}
;; Egison s bug
def pred1 = 1#(%1 - 1)
def pred2 = 1#(%1 - 2)
def pred3 = 1#(%1 - 3)
def pred4 = 1#(%1 - 4)
;; A function that determins poker-hands
;;
def pokerHands =
matchLambda as multiset(card)
| <card $s $n> <:> <card s pred1(n)> <:> <card s pred2(n)> <:> <card s pred3(n)>
<:> <card s ?($ < 11) and pred4(n)> <:> <nil>
-> <Straight-Flush>
| <card $s _> <:> <card s _> <:> <card s _> <:> <card s _> <:> <card s _> <:> <nil>
-> <Flush>
def test1 = io(each(print, map(show, map(pokerHands,
[[<Card <Club> 12>,
<Card <Club> 10>,
<Joker>,
<Card <Club> 1>,
<Card <Club> 11>],
[<Card <Heart> 4>,
<Card <Heart> 2>,
<Card <Heart> 13>,
<Card <Heart> 1>,
<Card <Heart> 3>]] ))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment