※本記事は工事中です
正月企画🎍で何か作りたいと思いとりあえず案だけ考えてみる。TDDっぽくテストケース→モデルケースの順で書いてみた。
"花札"とは
https://www.nintendo.co.jp/n09/hana-kabu_games/
##内容
https://github.com/dcsyhi/hanafuda
##更新
Model.elm
module Model exposing (..)
import Cards exposing (..)
--Model
type alias Model =
{ yamafuda : Yamafuda
, tefuda : Tefuda
, bafuda : Bafuda
, aifuda : Aifuda
, result : Hand
}
initModel : Model
initModel =
{ yamafuda =
[ tsuru, maku, tsuki, ame_tofu, houou, uguisu, hototogisu, yatsuhashi, cho, inoshishi, kari, sakazuki, shika, tsubame, matsu_tan, ume_tan, sakura_tan, fuji_tan, ayame_tan, botan_tan, hagi_tan, kiku_tan, momiji_tan, yanagi_tan, matsu_kasu1, matsu_kasu2, ume_kasu1, ume_kasu2, sakura_kasu1, sakura_kasu2, fuji_kasu1, fuji_kasu2, ayame_kasu1, ayame_kasu2, botan_kasu1, botan_kasu2, hagi_kasu1, hagi_kasu2, susuki_kasu1, susuki_kasu2, momiji_kasu1, momiji_kasu2, kiku_kasu1, kiku_kasu2, yanagi_kasu, kiri_kasu1, kiri_kasu2, kiri_kasu3 ]
, tefuda = []
, bafuda = []
, aifuda = []
, result = None "" 0
}
{-| 手札の絵札リスト
-}
type alias EfudaListT =
EveryDict Efuda Maisu
{-| 手札の絵柄リスト
-}
type alias EgaraListT =
EveryDict Egara Maisu
{-| 場札の絵札リスト
-}
type alias EfudaListB =
EveryDict Efuda Maisu
{-| 場札の絵柄リスト
-}
type alias EgaraListB =
EveryDict Egara Maisu
{-| 合札の絵柄リスト
-}
type alias EfudaListA =
EveryDict Efuda Maisu
{-| 合札の絵柄リスト
-}
type alias EgaraListA =
EveryDict Egara Maisu
{-| 札の枚数
-}
countYamafuda : Maisu
countYamafuda =
let
model =
initModel
in
List.length model.yamafuda
countTefuda : Maisu
countTefuda =
let
model =
initModel
in
List.length model.tefuda
countBafuda : Maisu
countBafuda =
let
model =
initModel
in
List.length model.bafuda
countAifuda : Maisu
countAifuda =
let
model =
initModel
in
List.length model.aifuda
{-| 手札の追加
-}
drawTefuda : Card -> Tefuda -> Tefuda
drawTefuda card tefuda =
card :: tefuda
putBafuda : Card -> Bafuda -> Bafuda
putBafuda card bafuda =
card :: bafuda
shuffle : Yamafuda -> Yamafuda
shuffle yamafuda =
let
yama_left =
take 37 yamafuda
yama_right =
drop 11 yamafuda
in
append yama_right (reverse yama_left)
shuffleMany : Yamafuda -> Yamafuda
shuffleMany yamafuda =
yamafuda |> shuffle |> shuffle |> shuffle |> shuffle
settingTefuda : (Yamafuda, Tefuda) -> (Yamafuda, Tefuda)
setting yamafuda tefuda =
let
picked = head yamafuda
case picked of
Just picked -> picked
Nothing -> ""
in
(tail yamafuda) (drawTefuda picked tefuda)
settingTefudaMany : Tefuda -> Tefuda
settingTefudaMany tefuda =
tefuda |> settingTefuda |> settingTefuda |> settingTefuda |> settingTefuda |> settingTefuda |> settingTefuda
#参考記事
★Elm開発における思考フロー
★関数型言語Elmでテスト駆動開発