Skip to content

Instantly share code, notes, and snippets.

Created September 16, 2013 05:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/6576895 to your computer and use it in GitHub Desktop.
Save anonymous/6576895 to your computer and use it in GitHub Desktop.
Cookie Clickerで一つの建造物を買えるだけ買い続けたらどうなるかシミュレートするコード群
-- Main> simulation State {...} 適当な秒数
module Main where
data State = State {
baseCost:: Integer, -- 初期コスト。これを元にコストが計算される。
baseCpS:: Integer, -- 一基あたりのCpS。baseって名づけたけどこっちは変動なし。
buildingCount:: Int, -- 所有数。
totalCpS:: Integer, -- 全体のCpS。baseCpSを足していくだけなので、最初から値を入れておけばずらせる。
totalCookies:: Integer -- クッキーおいしい。
} deriving Show
pow :: Num b => b -> Int -> b
pow base n = foldl (*) 1 (take n $ repeat base)
currentCost :: State -> Integer
currentCost state = truncate $ base * factor
where
base = fromIntegral $ baseCost state
factor = pow 1.15 $ buildingCount state
buyAll :: State -> State
buyAll state
| currentCost state <= totalCookies state =
buyAll state {
buildingCount = buildingCount state + 1,
totalCpS = totalCpS state + baseCpS state,
totalCookies = totalCookies state - currentCost state}
| otherwise = state
step :: State -> State
step state = state {
totalCookies = totalCookies state + totalCpS state}
simulation :: State -> Int -> State
simulation state times
| times > 0 = simulation (step $ buyAll state) (times - 1)
| otherwise = state
main::IO()
main = undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment