Toggle navigation
Egison
Documentations
Try It Out
Online Tools
Online Egison Interpreter
Online Egison Tutorial
Online Demonstrations
Poker Hands
Mahjong
Prime Numbers
Trees
Graph (Bellman-Ford Algorithm)
Randomized 3-SAT
Time-Series Data
Math
Blog
Community
Mahjong Demonstration
You can edit and run the following code. Enjoy Egison programming!
-- -- -- Mah-jong example -- -- -- -- Matcher definitions -- inductive Suit := Wan | Pin | Sou inductive Honor := Ton | Nan | Sha | Pe | Haku | Hatsu | Chun inductive Tile := Num Suit Integer | Hnr Honor inductive pattern Suit := | wan | pin | sou inductive pattern Honor := | ton | nan | sha | pe | haku | hatsu | chun inductive pattern Tile := | num Suit Integer | hnr Honor def suit := algebraicDataMatcher | wan | pin | sou def honor := algebraicDataMatcher | ton | nan | sha | pe | haku | hatsu | chun def tile := algebraicDataMatcher | num suit integer | hnr honor -- -- Pattern modularization -- def pattern twin (pat1 : Tile) (pat2 : [Tile]) : [Tile] := ($pat & ~pat1) :: #pat :: ~pat2 def pattern shuntsu (pat1 : Tile) (pat2 : [Tile]) : [Tile] := (num $s $n & ~pat1) :: num #s #(n + 1) :: num #s #(n + 2) :: ~pat2 -- (num $s $n & ~pat1) :: num #s #(i.+ n 1) :: num #s #(i.+ n 2) :: ~pat2 def pattern kohtsu (pat1 : Tile) (pat2 : [Tile]) : [Tile] := ($pat & ~pat1) :: #pat :: #pat :: ~pat2 -- -- A function that determines whether the hand is completed or not. -- def complete? : [Tile] -> Bool := \match as multiset tile with | twin $th_1 (shuntsu $sh_1 (shuntsu $sh_2 (shuntsu $sh_3 (shuntsu $sh_4 [] | kohtsu $kh_1 []) | kohtsu $kh_1 (kohtsu $kh_2 [])) | kohtsu $kh_1 (kohtsu $kh_2 (kohtsu $kh_3 []))) | kohtsu $kh_1 (kohtsu $kh_2 (kohtsu $kh_3 (kohtsu $kh_4 [])))) | (twin $th_2 (twin $th_3 (twin $th_4 (twin $th_5 (twin $th_6 (twin $th_7 [])))))) -> True | _ -> False -- -- Demonstration code -- assertEqual "mahjong 1" (complete? [ Hnr Haku, Hnr Haku , Num Wan 3, Num Wan 4, Num Wan 5 , Num Wan 6, Num Wan 7, Num Wan 8 , Num Pin 2, Num Pin 3, Num Pin 4 , Num Sou 6, Num Sou 6, Num Sou 6 ]) True assertEqual "mahjong 2" (complete? [ Hnr Haku, Hnr Haku , Num Pin 1, Num Pin 3, Num Pin 4 , Num Wan 6, Num Wan 7, Num Wan 8 , Num Wan 3, Num Wan 4, Num Wan 5 , Num Sou 6, Num Sou 6, Num Sou 6 ]) False
Run
What to do next...
Next Demonstration
Back to Home
This website in other langauge:
English
,
日本語