読者です 読者をやめる 読者になる 読者になる

IT練習ノート

IT関連で調べたこと(実際は嵌ったこと)を書いています。

Haskellでgithubに公開されているパッケージを取得してサンドボックスで実行するまで

ポーカーゲームを例にしてGithubからパッケージを取得して実行するまでの手順をまとめる。

github.com

作業ディレクトリを作る。

aaa:work03 foo$ mkdir poker
aaa:work03 foo$ cd poker

gitからパッケージを取得する。

aaa:poker foo$ git clone https://github.com/nbouscal/poker.hs.git
Cloning into 'poker.hs'...
remote: Counting objects: 225, done.
remote: Total 225 (delta 0), reused 0 (delta 0), pack-reused 225
Receiving objects: 100% (225/225), 37.05 KiB | 0 bytes/s, done.
Resolving deltas: 100% (83/83), done.
Checking connectivity... done.

取得内容を確認する。poker.cabalがビルドファイル(?)に相当するファイル。

aaa:poker foo$ ls -al ./poker.hs/
drwxr-xr-x   5 foo  staff  170  5 15 11:51 .
drwxr-xr-x   3 foo  staff  102  5 15 11:51 ..
drwxr-xr-x  13 foo  staff  442  5 15 11:51 .git
-rw-r--r--   1 foo  staff  608  5 15 11:51 poker.cabal
drwxr-xr-x   4 foo  staff  136  5 15 11:51 src

サンドボックスを作る。

aaa:poker foo$ cd poker.hs
aaa:poker.hs foo$ cabal sandbox init
Writing a default package environment file to
/Users/foo/work03/poker/poker.hs/cabal.sandbox.config
Creating a new sandbox at
/Users/foo/work03/poker/poker.hs/.cabal-sandbox

必要な依存パッケージを取得する。(時間がかかり、Stackageにしておけばよかったと後悔する。)

aaa:poker.hs foo$ cabal install --only-dependencies
Resolving dependencies...
Notice: installing into a sandbox located at
/Users/foo/work03/poker/poker.hs/.cabal-sandbox
Configuring MonadRandom-0.4.2.3...
Configuring base-orphans-0.5.4...
Configuring monad-loops-0.4.3...
Downloading reflection-2.1.2...
Configuring polyparse-1.12...
Building base-orphans-0.5.4...
Building monad-loops-0.4.3...
Building polyparse-1.12...
Building MonadRandom-0.4.2.3...
Installed monad-loops-0.4.3
Configuring prelude-extras-0.4.0.3...
Building prelude-extras-0.4.0.3...
Configuring tagged-0.8.4...
Installed MonadRandom-0.4.2.3
Building tagged-0.8.4...
Configuring uniplate-1.6.12...
Installed prelude-extras-0.4.0.3
Configuring reflection-2.1.2...
Installed tagged-0.8.4
Building uniplate-1.6.12...
Building reflection-2.1.2...
Configuring random-shuffle-0.0.4...
Installed base-orphans-0.5.4
Building random-shuffle-0.0.4...
Configuring semigroups-0.18.1...
Installed random-shuffle-0.0.4
Building semigroups-0.18.1...
Configuring distributive-0.5.0.2...
Installed polyparse-1.12
Configuring cpphs-1.20.1...
Installed reflection-2.1.2
Building cpphs-1.20.1...
Building distributive-0.5.0.2...
Installed distributive-0.5.0.2
Installed uniplate-1.6.12
Installed semigroups-0.18.1
Configuring void-0.7.1...
Building void-0.7.1...
Installed void-0.7.1
Configuring contravariant-1.4...
Building contravariant-1.4...
Installed cpphs-1.20.1
Configuring haskell-src-exts-1.17.1...
Building haskell-src-exts-1.17.1...
Installed contravariant-1.4
Downloading comonad-5...
Configuring comonad-5...
Building comonad-5...
Installed comonad-5
Downloading bifunctors-5.2...
Configuring bifunctors-5.2...
Building bifunctors-5.2...
Installed bifunctors-5.2
Configuring profunctors-5.2...
Configuring semigroupoids-5.0.1...
Building profunctors-5.2...
Building semigroupoids-5.0.1...
Installed profunctors-5.2
Installed semigroupoids-5.0.1
Downloading free-4.12.4...
Configuring free-4.12.4...
Building free-4.12.4...
Installed free-4.12.4
Downloading adjunctions-4.3...
Configuring adjunctions-4.3...
Building adjunctions-4.3...
Installed adjunctions-4.3
Downloading kan-extensions-5.0.1...
Configuring kan-extensions-5.0.1...
Building kan-extensions-5.0.1...
Installed kan-extensions-5.0.1
Downloading lens-4.14...
Configuring lens-4.14...
Building lens-4.14...
Installed lens-4.14
Downloading lens-action-0.2.0.2...
Configuring lens-action-0.2.0.2...
Building lens-action-0.2.0.2...
Installed lens-action-0.2.0.2
Installed haskell-src-exts-1.17.1
Downloading derive-2.5.25...
Configuring derive-2.5.25...
Building derive-2.5.25...
Installed derive-2.5.25
Updating documentation index
/Users/foo/work03/poker/poker.hs/.cabal-sandbox/share/doc/x86_64-osx-ghc-7.10.3/index.html
aaa:poker.hs foo$ 

Configureする。

aaa:poker.hs foo$ cabal configure
Resolving dependencies...
Configuring poker-0.1...

ビルドする。

aaa:poker.hs foo$ cabal build
Building poker-0.1...
Preprocessing executable 'poker' for poker-0.1...
[1 of 6] Compiling Poker.Types      ( src/Poker/Types.hs, dist/build/poker/poker-tmp/Poker/Types.o )
[2 of 6] Compiling Poker.Utility    ( src/Poker/Utility.hs, dist/build/poker/poker-tmp/Poker/Utility.o )
[3 of 6] Compiling Poker.Hands      ( src/Poker/Hands.hs, dist/build/poker/poker-tmp/Poker/Hands.o )
[4 of 6] Compiling Poker.Game       ( src/Poker/Game.hs, dist/build/poker/poker-tmp/Poker/Game.o )
[5 of 6] Compiling Poker.Betting    ( src/Poker/Betting.hs, dist/build/poker/poker-tmp/Poker/Betting.o )
[6 of 6] Compiling Main             ( src/Main.hs, dist/build/poker/poker-tmp/Main.o )

src/Main.hs:45:1: Warning: Defined but not used: ‘showBets’
Linking dist/build/poker/poker ...

distディレクトリ配下に実行ファイルができる。

aaa:poker.hs foo$ ls -al ./dist/build/poker/
total 21656
drwxr-xr-x  4 foo  staff       136  5 15 11:41 .
drwxr-xr-x  4 foo  staff       136  5 15 11:41 ..
-rwxr-xr-x  1 foo  staff  11084988  5 15 11:41 poker
drwxr-xr-x  7 foo  staff       238  5 15 11:41 poker-tmp
aaa:poker.hs foo$ ls -al ./dist/build/poker/poker
-rwxr-xr-x  1 foo  staff  11084988  5 15 11:41 ./dist/build/poker/poker

実行する。

aaa:poker.hs foo$ ./dist/build/poker/poker

Pockets: [K♧ ,7] Community: [] Bet: 0 Chips: 1500
Check or Bet?
Bet
Bet how much?
100
Pockets: [9♡ ,5] Community: [] Bet: 100 Chips: 1500
Fold, Call, or Raise?
Raise
Raise by how much?
100
Pockets: [Q♤ ,Q♢ ] Community: [] Bet: 200 Chips: 1500
Fold, Call, or Raise?
Call
Pockets: [K♤ ,8] Community: [] Bet: 200 Chips: 1500
Fold, Call, or Raise?
Call
Pockets: [3♢ ,3] Community: [] Bet: 200 Chips: 1500
Fold, Call, or Raise?
Call
Pockets: [K♧ ,7] Community: [] Bet: 200 Chips: 1400
Fold, Call, or Raise?
Raise
Raise by how much?
200
Pockets: [9♡ ,5] Community: [] Bet: 400 Chips: 1300
Fold, Call, or Raise?
Call
Pockets: [Q♤ ,Q♢ ] Community: [] Bet: 400 Chips: 1300
Fold, Call, or Raise?
^[[A
Fold, Call, or Raise?
Call
Pockets: [K♤ ,8] Community: [] Bet: 400 Chips: 1300
Fold, Call, or Raise?
Call
Pockets: [3♢ ,3] Community: [] Bet: 400 Chips: 1300
Fold, Call, or Raise?
Call
Pockets: [K♧ ,7] Community: [4♧ ,T♤ ,7] Bet: 0 Chips: 1100
Check or Bet?
Check
Pockets: [9♡ ,5] Community: [4♧ ,T♤ ,7] Bet: 0 Chips: 1100
Check or Bet?

そもそもポーカーの遊び方を知らないことに気づく。