-
-
Save unarist/6576907 to your computer and use it in GitHub Desktop.
Cookie Clickerで一つの建造物を買えるだけ買い続けたらどうなるかシミュレートするコード群。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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