昨日の続き

モジュールに分けてetcはまた先でも出来るだろうからほっといて進もう
T3GameとT3Playを作るのはやめて、GameとPlayにした。

-- ゲームの局面を受け取って選択可能な手のリストを返す
possible_hands :: Game -> [Play]
possible_hands game = [MakePlay i | (v, i) <- zip (value game) [0..], v == 0]
-- マップの開いている位置(リストの値が0のindex)を返す

-- ランダムに選択可能な着手を受け取って一つ選んで返す
random_choice :: [Play] -> IO Play
random_choice hands = do
  i <- getStdRandom (randomR (0, (length hands) - 1))
  return (hands !! i)

-- 人間が選択可能な着手を受け取って一つ選んで返す
human_choice :: [Play] -> IO Play
human_choice hands = do
  hSetBuffering stdout NoBuffering            
  putStr ("Choice a hand: " ++ (show (zip [0..] hands)))
  i <- readNum
  return (hands !! i)
      where readNum :: IO Int
            readNum = readLn