summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Zhao <ztuowen@gmail.com>2015-08-26 17:19:31 -0600
committerJoe Zhao <ztuowen@gmail.com>2015-08-26 17:19:31 -0600
commite795d3d990937a640a22b15b88eebd2b7beee340 (patch)
treeec367330ae9fa2502d29434c298bb8dad83592ee
downloadhmj-e795d3d990937a640a22b15b88eebd2b7beee340.tar.gz
hmj-e795d3d990937a640a22b15b88eebd2b7beee340.tar.bz2
hmj-e795d3d990937a640a22b15b88eebd2b7beee340.zip
fst commit
-rw-r--r--LICENSE20
-rw-r--r--Setup.hs2
-rw-r--r--dist/build/autogen/Paths_hmj.hs35
-rw-r--r--dist/build/autogen/cabal_macros.h95
-rwxr-xr-xdist/build/hmj/hmjbin0 -> 1145032 bytes
-rw-r--r--dist/build/hmj/hmj-tmp/Main.hibin0 -> 1680 bytes
-rw-r--r--dist/build/hmj/hmj-tmp/Main.obin0 -> 4264 bytes
-rw-r--r--dist/package.conf.inplace/package.cachebin0 -> 40 bytes
-rw-r--r--dist/setup-configbin0 -> 53555 bytes
-rw-r--r--dist/setup-config.ghc-mod.cabal-componentsbin0 -> 1276 bytes
-rw-r--r--dist/setup-config.ghc-mod.package-optionsbin0 -> 307 bytes
-rw-r--r--dist/setup-config.ghc-mod.resolved-componentsbin0 -> 2478 bytes
-rw-r--r--hmj.cabal25
-rw-r--r--src/Mahjong/Hand.hs27
-rw-r--r--src/Mahjong/Pai.hs30
-rw-r--r--src/Mahjong/Set.hs20
-rw-r--r--src/Main.hs5
17 files changed, 259 insertions, 0 deletions
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..49205a6
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2015 Joe Zhao
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/Setup.hs b/Setup.hs
new file mode 100644
index 0000000..9a994af
--- /dev/null
+++ b/Setup.hs
@@ -0,0 +1,2 @@
+import Distribution.Simple
+main = defaultMain
diff --git a/dist/build/autogen/Paths_hmj.hs b/dist/build/autogen/Paths_hmj.hs
new file mode 100644
index 0000000..0ca6d46
--- /dev/null
+++ b/dist/build/autogen/Paths_hmj.hs
@@ -0,0 +1,35 @@
+module Paths_hmj (
+ version,
+ getBinDir, getLibDir, getDataDir, getLibexecDir,
+ getDataFileName, getSysconfDir
+ ) where
+
+import qualified Control.Exception as Exception
+import Data.Version (Version(..))
+import System.Environment (getEnv)
+import Prelude
+
+catchIO :: IO a -> (Exception.IOException -> IO a) -> IO a
+catchIO = Exception.catch
+
+version :: Version
+version = Version [0,1,0,0] []
+bindir, libdir, datadir, libexecdir, sysconfdir :: FilePath
+
+bindir = "/home/joe/.cabal/bin"
+libdir = "/home/joe/.cabal/lib/x86_64-linux-ghc-7.10.1/hmj_EJVUBKD2OSK8NwQkzGMiCB"
+datadir = "/home/joe/.cabal/share/x86_64-linux-ghc-7.10.1/hmj-0.1.0.0"
+libexecdir = "/home/joe/.cabal/libexec"
+sysconfdir = "/home/joe/.cabal/etc"
+
+getBinDir, getLibDir, getDataDir, getLibexecDir, getSysconfDir :: IO FilePath
+getBinDir = catchIO (getEnv "hmj_bindir") (\_ -> return bindir)
+getLibDir = catchIO (getEnv "hmj_libdir") (\_ -> return libdir)
+getDataDir = catchIO (getEnv "hmj_datadir") (\_ -> return datadir)
+getLibexecDir = catchIO (getEnv "hmj_libexecdir") (\_ -> return libexecdir)
+getSysconfDir = catchIO (getEnv "hmj_sysconfdir") (\_ -> return sysconfdir)
+
+getDataFileName :: FilePath -> IO FilePath
+getDataFileName name = do
+ dir <- getDataDir
+ return (dir ++ "/" ++ name)
diff --git a/dist/build/autogen/cabal_macros.h b/dist/build/autogen/cabal_macros.h
new file mode 100644
index 0000000..02c1076
--- /dev/null
+++ b/dist/build/autogen/cabal_macros.h
@@ -0,0 +1,95 @@
+/* DO NOT EDIT: This file is automatically generated by Cabal */
+
+/* package base-4.8.0.0 */
+#define VERSION_base "4.8.0.0"
+#define MIN_VERSION_base(major1,major2,minor) (\
+ (major1) < 4 || \
+ (major1) == 4 && (major2) < 8 || \
+ (major1) == 4 && (major2) == 8 && (minor) <= 0)
+
+/* tool alex-3.1.4 */
+#define TOOL_VERSION_alex "3.1.4"
+#define MIN_TOOL_VERSION_alex(major1,major2,minor) (\
+ (major1) < 3 || \
+ (major1) == 3 && (major2) < 1 || \
+ (major1) == 3 && (major2) == 1 && (minor) <= 4)
+
+/* tool cpphs-1.19.2 */
+#define TOOL_VERSION_cpphs "1.19.2"
+#define MIN_TOOL_VERSION_cpphs(major1,major2,minor) (\
+ (major1) < 1 || \
+ (major1) == 1 && (major2) < 19 || \
+ (major1) == 1 && (major2) == 19 && (minor) <= 2)
+
+/* tool gcc-5.2.0 */
+#define TOOL_VERSION_gcc "5.2.0"
+#define MIN_TOOL_VERSION_gcc(major1,major2,minor) (\
+ (major1) < 5 || \
+ (major1) == 5 && (major2) < 2 || \
+ (major1) == 5 && (major2) == 2 && (minor) <= 0)
+
+/* tool ghc-7.10.1 */
+#define TOOL_VERSION_ghc "7.10.1"
+#define MIN_TOOL_VERSION_ghc(major1,major2,minor) (\
+ (major1) < 7 || \
+ (major1) == 7 && (major2) < 10 || \
+ (major1) == 7 && (major2) == 10 && (minor) <= 1)
+
+/* tool ghc-pkg-7.10.1 */
+#define TOOL_VERSION_ghc_pkg "7.10.1"
+#define MIN_TOOL_VERSION_ghc_pkg(major1,major2,minor) (\
+ (major1) < 7 || \
+ (major1) == 7 && (major2) < 10 || \
+ (major1) == 7 && (major2) == 10 && (minor) <= 1)
+
+/* tool haddock-2.16.0 */
+#define TOOL_VERSION_haddock "2.16.0"
+#define MIN_TOOL_VERSION_haddock(major1,major2,minor) (\
+ (major1) < 2 || \
+ (major1) == 2 && (major2) < 16 || \
+ (major1) == 2 && (major2) == 16 && (minor) <= 0)
+
+/* tool happy-1.19.5 */
+#define TOOL_VERSION_happy "1.19.5"
+#define MIN_TOOL_VERSION_happy(major1,major2,minor) (\
+ (major1) < 1 || \
+ (major1) == 1 && (major2) < 19 || \
+ (major1) == 1 && (major2) == 19 && (minor) <= 5)
+
+/* tool hpc-0.67 */
+#define TOOL_VERSION_hpc "0.67"
+#define MIN_TOOL_VERSION_hpc(major1,major2,minor) (\
+ (major1) < 0 || \
+ (major1) == 0 && (major2) < 67 || \
+ (major1) == 0 && (major2) == 67 && (minor) <= 0)
+
+/* tool hsc2hs-0.67 */
+#define TOOL_VERSION_hsc2hs "0.67"
+#define MIN_TOOL_VERSION_hsc2hs(major1,major2,minor) (\
+ (major1) < 0 || \
+ (major1) == 0 && (major2) < 67 || \
+ (major1) == 0 && (major2) == 67 && (minor) <= 0)
+
+/* tool hscolour-1.22 */
+#define TOOL_VERSION_hscolour "1.22"
+#define MIN_TOOL_VERSION_hscolour(major1,major2,minor) (\
+ (major1) < 1 || \
+ (major1) == 1 && (major2) < 22 || \
+ (major1) == 1 && (major2) == 22 && (minor) <= 0)
+
+/* tool pkg-config-0.28 */
+#define TOOL_VERSION_pkg_config "0.28"
+#define MIN_TOOL_VERSION_pkg_config(major1,major2,minor) (\
+ (major1) < 0 || \
+ (major1) == 0 && (major2) < 28 || \
+ (major1) == 0 && (major2) == 28 && (minor) <= 0)
+
+/* tool strip-2.25 */
+#define TOOL_VERSION_strip "2.25"
+#define MIN_TOOL_VERSION_strip(major1,major2,minor) (\
+ (major1) < 2 || \
+ (major1) == 2 && (major2) < 25 || \
+ (major1) == 2 && (major2) == 25 && (minor) <= 0)
+
+#define CURRENT_PACKAGE_KEY "hmj_EJVUBKD2OSK8NwQkzGMiCB"
+
diff --git a/dist/build/hmj/hmj b/dist/build/hmj/hmj
new file mode 100755
index 0000000..2d96ba6
--- /dev/null
+++ b/dist/build/hmj/hmj
Binary files differ
diff --git a/dist/build/hmj/hmj-tmp/Main.hi b/dist/build/hmj/hmj-tmp/Main.hi
new file mode 100644
index 0000000..fb75bcd
--- /dev/null
+++ b/dist/build/hmj/hmj-tmp/Main.hi
Binary files differ
diff --git a/dist/build/hmj/hmj-tmp/Main.o b/dist/build/hmj/hmj-tmp/Main.o
new file mode 100644
index 0000000..57210f2
--- /dev/null
+++ b/dist/build/hmj/hmj-tmp/Main.o
Binary files differ
diff --git a/dist/package.conf.inplace/package.cache b/dist/package.conf.inplace/package.cache
new file mode 100644
index 0000000..b3cae5c
--- /dev/null
+++ b/dist/package.conf.inplace/package.cache
Binary files differ
diff --git a/dist/setup-config b/dist/setup-config
new file mode 100644
index 0000000..2217067
--- /dev/null
+++ b/dist/setup-config
Binary files differ
diff --git a/dist/setup-config.ghc-mod.cabal-components b/dist/setup-config.ghc-mod.cabal-components
new file mode 100644
index 0000000..6b6a23b
--- /dev/null
+++ b/dist/setup-config.ghc-mod.cabal-components
Binary files differ
diff --git a/dist/setup-config.ghc-mod.package-options b/dist/setup-config.ghc-mod.package-options
new file mode 100644
index 0000000..0bc2770
--- /dev/null
+++ b/dist/setup-config.ghc-mod.package-options
Binary files differ
diff --git a/dist/setup-config.ghc-mod.resolved-components b/dist/setup-config.ghc-mod.resolved-components
new file mode 100644
index 0000000..984c6cf
--- /dev/null
+++ b/dist/setup-config.ghc-mod.resolved-components
Binary files differ
diff --git a/hmj.cabal b/hmj.cabal
new file mode 100644
index 0000000..b8524b0
--- /dev/null
+++ b/hmj.cabal
@@ -0,0 +1,25 @@
+-- Initial hmj.cabal generated by cabal init. For further documentation,
+-- see http://haskell.org/cabal/users-guide/
+
+name: hmj
+version: 0.1.0.0
+-- synopsis:
+-- description:
+license: MIT
+license-file: LICENSE
+author: Joe Zhao
+maintainer: ztuowen@gmail.com
+-- copyright:
+category: Game
+build-type: Simple
+-- extra-source-files:
+cabal-version: >=1.10
+synopsis: This is a mahjong lib/game written in haskell just for fun.
+
+executable hmj
+ main-is: Main.hs
+ -- other-modules:
+ -- other-extensions:
+ build-depends: base >=4.8 && <4.9
+ hs-source-dirs: src
+ default-language: Haskell2010
diff --git a/src/Mahjong/Hand.hs b/src/Mahjong/Hand.hs
new file mode 100644
index 0000000..1d1bb80
--- /dev/null
+++ b/src/Mahjong/Hand.hs
@@ -0,0 +1,27 @@
+module Hand where
+
+import Set
+import Pai
+
+data Hand = Hand {getHand::MSet, getCall::[MSet]}
+
+max2Win = 7
+
+pairs c (h:hs) = (if length (filter (==h) hs) >= c then 1 else 0) + (pairs $ filter (/=h) hs)
+pairs c [] = 0
+
+seven h = 7 - (pairs 1 h)
+mosou h = 14 - (pairs 0 h') - (if pairs 1 h' > 0 then 1 else 0)
+ where h' = filter is19 h
+
+costM a b = (sum $ zipWith (snd.sMmin) a b,zipWith (fst.sMmin) a b)
+sMmin a b = if (a>b) then (a-b,0) else (0,b-a)
+
+parseCol xx@(a:b:c:xs) (t,m,p) =
+ concat []
+parseCol _ r = return r
+
+normal h = cm =
+ where cm = pairs 2 $ filter isCha h
+ cp = (pairs 1 $ filter isCha h) - cm
+
diff --git a/src/Mahjong/Pai.hs b/src/Mahjong/Pai.hs
new file mode 100644
index 0000000..08115e9
--- /dev/null
+++ b/src/Mahjong/Pai.hs
@@ -0,0 +1,30 @@
+module Pai where
+
+import Data.Char (toUpper)
+
+data MCol = Man | Pin | Sou | Cha
+ deriving (Eq,Ord)
+data MCard = MCard MCol Int
+ deriving (Eq,Ord)
+
+charMcol = [(Man,'M'),(Pin,'P'),(Sou,'S'),(Cha,'C')]
+instance Show MCol where
+ show x = [snd a | a <-charMcol, fst a == x]
+
+instance Read MCol where
+ readsPrec p r = [(fst a,t)|(c,t) <- lex r, a <- charMcol, map toUpper c == [snd a]]
+
+instance Show MCard where
+ show (MCard a b) = show b ++ show a
+
+instance Read MCard where
+ readsPrec p r = [ (MCard col n,u) | (c1,t)<- lex r,
+ let n = (read c1)::Int,
+ (c2,u) <-lex t,
+ let col=(read c2)::MCol]
+
+isCha c@(MCard col n) = (col == Cha)
+isLaoTou c@(MCard col n) = ((n == 1) || (n == 9)) && (not $ isCha c)
+is19 c@(MCard col n) = (isCha c) || (isLaoTou c)
+
+
diff --git a/src/Mahjong/Set.hs b/src/Mahjong/Set.hs
new file mode 100644
index 0000000..4c3e799
--- /dev/null
+++ b/src/Mahjong/Set.hs
@@ -0,0 +1,20 @@
+module Set where
+
+import Pai
+import Data.List (sort)
+import Data.Char (isDigit)
+import Data.Either
+
+data MSet = MSet {getMSet:: [MCard]}
+
+instance Show MSet where
+ show xs = fst $ foldr f ("",Nothing) $ sort $ getMSet xs
+ where f (MCard col n) (o,p) = let o' = show n ++ (if Just col == p then ""
+ else show col) ++ o in (o', Just col)
+
+readMSet r = fst $ foldr f ([],Man) $ map g r
+ where g x | isDigit x = Left ((read [x])::Int)
+ | otherwise = Right ((read [x])::MCol)
+ f (Left a) (xs,col) = ((MCard col a):xs,col)
+ f (Right a) (xs,col) = (xs,a)
+
diff --git a/src/Main.hs b/src/Main.hs
new file mode 100644
index 0000000..6a8ebb3
--- /dev/null
+++ b/src/Main.hs
@@ -0,0 +1,5 @@
+-- This is the default main
+module Main where
+
+main = do
+ print "Just a test"