packages feed

riichi-scoring 0.7.0.0 → 0.7.0.1

raw patch · 5 files changed

+50/−15 lines, 5 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

CHANGELOG.md view
@@ -74,3 +74,12 @@   the original size of the hand is known by the function. - Now have tile efficiency, driven by shanten calculations, which allows for a   "discard" command that recommends the most efficient discards.++## 0.7.0.0+- Added live command, which repeatedly recomends discards.++## 0.7.0.1+- Fixed shanten edge case where no melds at all are found and the hand is too+  short so 13 orphans and 7 pairs aren't considered.+- Added tests for shanten calculations.+- Tidied up todo a little.
app/Main.hs view
@@ -9,7 +9,6 @@ import Data.Version (showVersion) import Paths_riichi_scoring (version) import Riichi.Display-import Riichi.Display (displayLiveMode) import Riichi.Meld import System.Environment (getArgs) 
riichi-scoring.cabal view
@@ -20,7 +20,7 @@ -- PVP summary:     +-+------- breaking API changes --                  | | +----- non-breaking API additions --                  | | | +--- code changes with no API change-version: 0.7.0.0+version: 0.7.0.1 -- A short (one-line) description of the package. synopsis: A CLI tool for interpreting and scoring Riichi Mahjong hands. -- A longer description of the package.
src/Riichi/Shanten.hs view
@@ -20,7 +20,11 @@ -- | A partial is either a taatsu or a pair. Useful for working out shanten. type Partial = Either Taatsu Pair --- | Get the shanten of a hand.+{- | Get the shanten of a hand. Really it only makes sense to call this on a hand with 13 or 14 tiles.+| When called on anything else, the "basic" shanten only is taken into account (no seven pairs or+| 13 orphans). (This is the meat of the calculation, so we expose it to the user in this case as a utility+| of sorts). This may change in future versions.+-} getShanten :: Hand -> Int getShanten hand     | length hand `elem` [13, 14] = if 0 `elem` list then 0 else minimum list@@ -34,18 +38,20 @@  -- | Get the shanten of a hand with respect to a standard 4 melds and a pair complete hand. basicShanten :: Hand -> Int-basicShanten hand = minimum $ do-    -- The combinatorics can blow up here, especially on a hand like 1111p 2222p 3333p 4444p rr-    -- Need to try to prune out as many cases as we can, and we must dispose of cases that find so-    -- many taatsu or melds that shanten is negative!-    let meldss = formMelds' hand-    melds <- meldss-    let m = length melds-    -- Don't bother if the number of partials pushes us past 5 blocks-    let partialss = splitAcrossSuits (formPartials (5 - m)) (hand \\ concatMelds melds)-    partials <- partialss-    let (t, p) = countTaatsuPairs partials-    return $ 8 - (2 * m) - min (t + p) (4 - m) - (if p >= 1 && (m + t + p >= 5) then 1 else 0)+basicShanten hand =+    minimum $+        8 : do+            -- The combinatorics can blow up here, especially on a hand like 1111p 2222p 3333p 4444p rr+            -- Need to try to prune out as many cases as we can, and we must dispose of cases that find so+            -- many taatsu or melds that shanten is negative!+            let meldss = formMelds' hand+            melds <- meldss+            let m = length melds+            -- Don't bother if the number of partials pushes us past 5 blocks+            let partialss = splitAcrossSuits (formPartials (5 - m)) (hand \\ concatMelds melds)+            partials <- partialss+            let (t, p) = countTaatsuPairs partials+            return $ 8 - (2 * m) - min (t + p) (4 - m) - (if p >= 1 && (m + t + p >= 5) then 1 else 0)  -- | Get the hand's shanten with respect to seven pairs. pairsShanten :: Hand -> Int
test/Test.hs view
@@ -6,6 +6,7 @@ import Riichi.Context import Riichi.Meld import Riichi.Scoring+import Riichi.Shanten import Riichi.Tile  main :: IO ()@@ -19,6 +20,7 @@         , meldsTests         , scoringTests         , showTests+        , shantenTests         ]  tileTests :: TestTree@@ -130,3 +132,22 @@         score = getScore han fu dealer tsumo      in         (han, fu, score)++shantenTests :: TestTree+shantenTests =+    testGroup+        "Shanten test groups"+        [ testCase "Shanten test 1" $ getShanten (mkHand "123p 123m 123s rrr ww ") @?= -1+        , testCase "Shanten test 2" $ getShanten (mkHand "123p 123m 123s rrrr w g") @?= 0+        , testCase "Shanten test 3" $ getShanten (mkHand "123p 123m 123s rrrr w") @?= 0+        , testCase "Shanten test 4" $ getShanten (mkHand "123p 123p 123p 44s r w g") @?= 1+        , testCase "Shanten test 5" $ getShanten (mkHand "456p 1111m 246s ES ww") @?= 2+        , testCase "Shanten test 6" $ getShanten (mkHand "457p 1111m 246s ES ww") @?= 3+        , testCase "Shanten test 7" $ getShanten (mkHand "11p 22p 33s 44m ww rr EE") @?= -1+        , testCase "Shanten test 8" $ getShanten (mkHand "11p 22p 34s 44m ww rr EE") @?= 0+        , testCase "Shanten test 9" $ getShanten (mkHand "11p 22p 34s 44m ww rr E") @?= 1+        , testCase "Shanten test 10" $ getShanten (mkHand "19p 19s 19m rwg NESW") @?= 0+        , testCase "Shanten test 11" $ getShanten (mkHand "19p 19s 19m rrwg NESW") @?= -1+        , testCase "Shanten test 12" $ getShanten (mkHand "28p 27s 38m rwg NESW") @?= 6+        , testCase "Shanten test 13" $ basicShanten (mkHand "28p 27s 38m rwg NESW") @?= 8+        ]