質問

うように国民の損失が非常に大きな実施のためのチェッカーのようなゲームを自分で学ぶウります。の機能をうまくと、リストのためのゲーム状態、発生のリストの後継ゲームです。のようなチェッカーの場合、ジャンプ、プレーヤーになれば点は入ると信じていました。場合があり、プレイヤーが選択できます。

では、この作品のリストmonad:ループの全ての入力ゲーム、ループを全てのビー玉が飛び、ループ全ジャンプの大理石でできている。このリストmonadく偏平にすべてのリストとして提出してください簡単なリストです。

フレキシビリティとは、いない場合はジャンプが指定されたゲームの状態を返し、現在のゲームの状態ではなく、空のリスト。以下のコードは最良の方法は私たちのそうですが、本当に醜います。他の方法については"クリーンです。

eHex :: Coord -> Coord -- Returns the coordinates immediately to the east on the board
nwHex :: Coord -> Coord -- Returns the coordinates immediately to the northwest on the board

generateJumpsIter :: [ZertzState] -> [ZertzState]
generateJumpsIter states = do
    ws <- states
    case children ws of
      [] -> return ws
      n@_ -> n
  where 
    children ws@(ZertzState s1 s2 b p) = do
      (c, color)  <- occupiedCoords ws
      (start, end) <- [(eHex, wHex), (wHex, eHex), (swHex, neHex),
                       (neHex, swHex), (nwHex, seHex), (seHex, nwHex)]
      if (hexOccupied b $ start c) && (hexOpen b $ end c)
        then case p of
          1 -> return $ ZertzState (scoreMarble s1 color) s2
                                   (jumpMarble (start c) c (end c) b) p
          (-1) -> return $ ZertzState s1 (scoreMarble s2 color)
                                      (jumpMarble (start c) c (end c) b) p
        else []

編集:をタイプ署名を六角レンチます。

役に立ちましたか?

解決

フレキシビリティとは、いない場合はジャンプが指定されたゲームの状態を返し、現在のゲームの状態ではなく、空のリスト。

なぜですか?長々と書きましたがミニマックスに数回、想像できない利用となります。ない方が良いよと機能タイプ

nextStates :: [ZertzState] -> [Maybe [ZertzState]]

または

nextStates :: [ZertzState] -> [[ZertzState]]

しかしん返し"のいずれかをクリック、またはそのリストが空の状態からの"をタイプしたいです

nextStates :: [ZertzState] -> [Either ZertzState [ZertzState]]

できるカーブを平坦化し簡単です。

どのように実施し、推薦を定めるためのヘルパー関数の型

[ZertzState] -> [(ZertzState, [ZertzState])]

とまで地図

(\(start, succs) -> if null succs then Left start else Right succs)

以上の結果、様々なっていません。

としてのフレッドブルックスと言(言い換え),ロサンゼルス生まれの種類のコードを実際に書き込みます。

他のヒント

な虐待monads表記リストで重り沿いにある老舗鰻料理屋。さらに利用できるリスト内包のファッション:

do x <- [1..3]
   y <- [2..5]      <=>  [ x + y | x <- [1..3], y <- [2..5] ]
   return x + y

現在の簡素化'

listOfHex :: [(Coord -> Coord,Coord -> Coord)]
listOfHex = [ (eHex, wHex), (wHex, eHex), (swHex, neHex)
            , (neHex, swHex), (nwHex, seHex), (seHex, nwHex)]

generateJumpsIter :: [ZertzState] -> [ZertzState]
generateJumpsIter states =
    [if null ws then ws else children ws | ws <- states]
  where -- I named it foo because I don t know what it do....
    foo True   1  = ZertzState (scoreMarble s1 color) s2
                               (jumpMarble (start c) c (end c) b) p
    foo True (-1) = ZertzState s1 (scoreMarble s2 color)
                               (jumpMarble (start c) c (end c) b) p
    foo False  _  = []
    foo _ _ = error "Bleh"

    children ws@(ZertzState s1 s2 b p) =
      [ foo (valid c hex) p | (c, _)  <- occupiedCoords ws, hex <- listOfHex ]
        where valid c (start, end) =
                 (hexOccupied b $ start c) && (hexOpen b $ end c)

のようにそしてリストcommprehensionの迷惑いているからだと思っていたすべてのコードを書かないことにしましたどうやって実行するかである。場合を修正することができます深まることをお勧めした使用によりcombinators(図foldr,foldl"などという観点からは、本当を削減コードサイズが楽しめます。

注意のコードを試していない場合にはコンパイル。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top