From e795d3d990937a640a22b15b88eebd2b7beee340 Mon Sep 17 00:00:00 2001 From: Joe Zhao Date: Wed, 26 Aug 2015 17:19:31 -0600 Subject: fst commit --- LICENSE | 20 ++++++ Setup.hs | 2 + dist/build/autogen/Paths_hmj.hs | 35 ++++++++++ dist/build/autogen/cabal_macros.h | 95 ++++++++++++++++++++++++++ dist/build/hmj/hmj | Bin 0 -> 1145032 bytes dist/build/hmj/hmj-tmp/Main.hi | Bin 0 -> 1680 bytes dist/build/hmj/hmj-tmp/Main.o | Bin 0 -> 4264 bytes dist/package.conf.inplace/package.cache | Bin 0 -> 40 bytes dist/setup-config | Bin 0 -> 53555 bytes dist/setup-config.ghc-mod.cabal-components | Bin 0 -> 1276 bytes dist/setup-config.ghc-mod.package-options | Bin 0 -> 307 bytes dist/setup-config.ghc-mod.resolved-components | Bin 0 -> 2478 bytes hmj.cabal | 25 +++++++ src/Mahjong/Hand.hs | 27 ++++++++ src/Mahjong/Pai.hs | 30 ++++++++ src/Mahjong/Set.hs | 20 ++++++ src/Main.hs | 5 ++ 17 files changed, 259 insertions(+) create mode 100644 LICENSE create mode 100644 Setup.hs create mode 100644 dist/build/autogen/Paths_hmj.hs create mode 100644 dist/build/autogen/cabal_macros.h create mode 100755 dist/build/hmj/hmj create mode 100644 dist/build/hmj/hmj-tmp/Main.hi create mode 100644 dist/build/hmj/hmj-tmp/Main.o create mode 100644 dist/package.conf.inplace/package.cache create mode 100644 dist/setup-config create mode 100644 dist/setup-config.ghc-mod.cabal-components create mode 100644 dist/setup-config.ghc-mod.package-options create mode 100644 dist/setup-config.ghc-mod.resolved-components create mode 100644 hmj.cabal create mode 100644 src/Mahjong/Hand.hs create mode 100644 src/Mahjong/Pai.hs create mode 100644 src/Mahjong/Set.hs create mode 100644 src/Main.hs 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 Binary files /dev/null and b/dist/build/hmj/hmj 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 Binary files /dev/null and b/dist/build/hmj/hmj-tmp/Main.hi 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 Binary files /dev/null and b/dist/build/hmj/hmj-tmp/Main.o differ diff --git a/dist/package.conf.inplace/package.cache b/dist/package.conf.inplace/package.cache new file mode 100644 index 0000000..b3cae5c Binary files /dev/null and b/dist/package.conf.inplace/package.cache differ diff --git a/dist/setup-config b/dist/setup-config new file mode 100644 index 0000000..2217067 Binary files /dev/null and b/dist/setup-config 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 Binary files /dev/null and b/dist/setup-config.ghc-mod.cabal-components 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 Binary files /dev/null and b/dist/setup-config.ghc-mod.package-options 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 Binary files /dev/null and b/dist/setup-config.ghc-mod.resolved-components 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" -- cgit v1.2.3-70-g09d2