From f16199016330cb4bed025c946bf09d60959e6524 Mon Sep 17 00:00:00 2001 From: Keisuke Izumiya Date: Thu, 30 Nov 2023 17:13:39 +0900 Subject: [PATCH 1/3] [documentation] API --- pon2.nimble | 6 +++--- src/pon2.nim | 10 ++++++++++ src/pon2pkg/core.nim | 24 ++++++++++++------------ src/pon2pkg/nazopuyo.nim | 10 +++++----- src/pon2pkg/simulator.nim | 8 ++++---- 5 files changed, 34 insertions(+), 24 deletions(-) diff --git a/pon2.nimble b/pon2.nimble index 8d546e5..54f2726 100644 --- a/pon2.nimble +++ b/pon2.nimble @@ -18,7 +18,7 @@ requires "docopt ^= 0.7.1" requires "karax ^= 1.3.3" requires "nigui ^= 0.2.7" requires "nimsimd ^= 1.2.6" -requires "https://github.com/de-odex/suru#head" +requires "https://github.com/de-odex/suru#f6f1e60" # Tasks @@ -40,10 +40,10 @@ task benchmark, "Benchmarking": exec &"nim c -r -d:avx2={avx2} -d:bmi2={bmi2} benchmark/main.nim" task documentation, "Make Documentation": - exec &"nim doc --project -d:avx2=true src/pon2.nim" + exec &"nim doc --project -d:avx2=false src/pon2.nim" mvDir "src/htmldocs", "src/htmldocs2" - exec &"nim doc --project -d:avx2=false src/pon2.nim" + exec &"nim doc --project -d:avx2=true src/pon2.nim" exec "cp -r src/htmldocs2 src/htmldocs" rmDir "src/htmldocs2" diff --git a/src/pon2.nim b/src/pon2.nim index 6497cdc..260854e 100644 --- a/src/pon2.nim +++ b/src/pon2.nim @@ -419,3 +419,13 @@ Options: args.runPermuter else: args.runEditor + +when defined(nimdoc): + # HACK: to generate documentation + import ./pon2pkg/core as coreDoc + import ./pon2pkg/nazopuyo as nazoDoc + import ./pon2pkg/simulator as simDoc + + discard coreDoc.Cell.None + discard nazoDoc.MarkResult.Accept + discard simDoc.SimulatorState.Stable diff --git a/src/pon2pkg/core.nim b/src/pon2pkg/core.nim index c21b45b..06eea1b 100644 --- a/src/pon2pkg/core.nim +++ b/src/pon2pkg/core.nim @@ -4,20 +4,20 @@ ## submodules individually. ## ## Submodule Documentations: -## - [Cell](./corepkg/cell.html) -## - [Environment](./corepkg/environment.html) -## - [Field](./corepkg/field.html) -## - [Misc](./corepkg/misc.html) -## - [MoveResult](./corepkg/moveresult.html) -## - [Pair](./corepkg/pair.html) -## - [Position](./corepkg/position.html) +## - [cell](./corepkg/cell.html) +## - [environment](./corepkg/environment.html) +## - [field](./corepkg/field.html) +## - [misc](./corepkg/misc.html) +## - [moveresult](./corepkg/moveresult.html) +## - [pair](./corepkg/pair.html) +## - [position](./corepkg/position.html) ## ## Compile Options: -## | Option | Description | Default | -## | --------------------- | ---------------------- | ------- | -## | `-d:WaterHeight= | Height of the water. | `8` | -## | `-d:avx2=` | Use AVX2 instructions. | `true` | -## | `-d:bmi2=` | Use BMI2 instructions. | `true` | +## | Option | Description | Default | +## | ---------------------- | ---------------------- | ------- | +## | `-d:WaterHeight=` | Height of the water. | `8` | +## | `-d:avx2=` | Use AVX2 instructions. | `true` | +## | `-d:bmi2=` | Use BMI2 instructions. | `true` | ## {.experimental: "strictDefs".} diff --git a/src/pon2pkg/nazopuyo.nim b/src/pon2pkg/nazopuyo.nim index 77ab5e3..2aa8d5a 100644 --- a/src/pon2pkg/nazopuyo.nim +++ b/src/pon2pkg/nazopuyo.nim @@ -5,11 +5,11 @@ ## submodules individually. ## ## Submodule Documentations: -## - [Generate](./nazopuyopkg/generate.html) -## - [NazoPuyo Core](./nazopuyopkg/nazopuyo.html) -## - [Marking](./nazopuyopkg/mark.html) -## - [Permute](./nazopuyopkg/permute.html) -## - [Solve](./nazopuyopkg/solve.html) +## - [generate](./nazopuyopkg/generate.html) +## - [nazopuyo](./nazopuyopkg/nazopuyo.html) +## - [mark](./nazopuyopkg/mark.html) +## - [permute](./nazopuyopkg/permute.html) +## - [solve](./nazopuyopkg/solve.html) ## {.experimental: "strictDefs".} diff --git a/src/pon2pkg/simulator.nim b/src/pon2pkg/simulator.nim index 1dfdebb..9c5090d 100644 --- a/src/pon2pkg/simulator.nim +++ b/src/pon2pkg/simulator.nim @@ -5,10 +5,10 @@ ## Also, you can write such as `import pon2pkg/simulatorpkg/simulator` to import ## submodules individually. ## -## Submodule Documentations: -## - [Simulator Core](./simulatorpkg/simulator.html) -## - [Native Simulator](./simulatorpkg/native.html) -## - Web Simulator +## Submodule Documentations (module names are shown in `typewriter font`): +## - [simulator](./simulatorpkg/simulator.html) +## - [native](./simulatorpkg/native.html) +## - web ## {.experimental: "strictDefs".} From 63f791d20c7686b3b48d6889255b872baa685a5c Mon Sep 17 00:00:00 2001 From: Keisuke Izumiya Date: Thu, 30 Nov 2023 18:03:58 +0900 Subject: [PATCH 2/3] [other] add benchmark --- benchmark/main.nim | 145 +++++++++++++++++++++++++++++++++++---------- pon2.nimble | 4 +- 2 files changed, 115 insertions(+), 34 deletions(-) diff --git a/benchmark/main.nim b/benchmark/main.nim index c819c1a..46dd859 100644 --- a/benchmark/main.nim +++ b/benchmark/main.nim @@ -1,44 +1,125 @@ {.experimental: "strictDefs".} -import std/[math, options, monotimes, sugar, times, uri] +import std/[math, options, monotimes, times, uri] +import ../src/pon2pkg/corepkg/[cell, field, environment, pair, position] import ../src/pon2pkg/nazopuyopkg/[nazopuyo, solve] -template benchmark(fn: () -> Duration, loop = 1.Positive) = - let durations = collect: - for _ in 0 ..< loop: - fn() +template benchmark(desc: string, loop: Positive, prepare: untyped, + measure: untyped): untyped = + var totalDuration = DurationZero - {.push warning[ProveInit]: off.} - {.push warning[Uninit]: off.} - echo fn.astToStr, ": ", durations.sum div loop - {.pop.} - {.pop.} + for _ in 1..loop: + prepare -template core(duration: var Duration, body: untyped) = - let t1 = getMonoTime() - body - let t2 = getMonoTime() + let t1 = getMonoTime() + measure + let t2 = getMonoTime() - duration = t2 - t1 + totalDuration += t2 - t1 -proc rashomon: Duration = - let nazo = ( - "https://ishikawapuyo.net/simu/pn.html?" & - "c01cw2jo9jAbckAq9zqhacs9jAiSr_c1g1E1E1c1A1__200" - ).parseUri.parseTsuNazoPuyo.nazoPuyo + echo desc, ": ", totalDuration div loop - core result: - discard nazo.solve +when isMainModule: + let env19 = parseTsuEnvironment(""" +by.yrr +gb.gry +rbgyyr +gbgyry +ryrgby +yrgbry +ryrgbr +ryrgbr +rggbyb +gybgbb +rgybgy +rgybgy +rgybgy +------ +bg""").environment -proc galaxy: Duration = - let nazo = ( - "https://ishikawapuyo.net/simu/pn.html?" & - "P00P00PrAOqcOi9OriQpaQxAQzsNziN9aN_g1c1A1E1u16121q1__v0c" - ).parseUri.parseTsuNazoPuyo.nazoPuyo + block: + var field = zeroTsuField() + benchmark "Setter", 10 ^ 4: + field = env19.field + do: + field[2, 3] = Cell.Red - core result: - discard nazo.solve + block: + var field = zeroTsuField() + benchmark "Put", 10 ^ 4: + field = env19.field + do: + field.put GreenYellow, Up2 -when isMainModule: - benchmark rashomon, 1 - benchmark galaxy, 1 + block: + var field = zeroTsuField() + benchmark "Disppear", 10 ^ 4: + field[5, 4] = Cell.Red + field[5, 5] = Cell.Red + field[5, 5] = Cell.Red + field[6, 4] = Cell.Red + do: + discard field.disappear + + block: + var field = zeroTsuField() + benchmark "Drop (Tsu)", 10 ^ 4: + field[2, 3] = Cell.Red + do: + field.drop + + block: + var field = zeroWaterField() + benchmark "Drop (Water)", 10 ^ 3: + field[2, 3] = Cell.Red + do: + field.drop + + block: + var env = initTsuEnvironment 0 + benchmark "move (Vanilla)", 10 ^ 4: + env = env19 + do: + env.move Up3, false + + block: + var env = initTsuEnvironment 0 + benchmark "move (Rough)", 10 ^ 4: + env = env19 + do: + discard env.moveWithRoughTracking(Up3, false) + + block: + var env = initTsuEnvironment 0 + benchmark "move (Detail)", 10 ^ 4: + env = env19 + do: + discard env.moveWithDetailTracking(Up3, false) + block: + var env = initTsuEnvironment 0 + benchmark "move (Full)", 10 ^ 4: + env = env19 + do: + discard env.moveWithFullTracking(Up3, false) + + block: + let nazo = ( + "https://ishikawapuyo.net/simu/pn.html?" & + "c01cw2jo9jAbckAq9zqhacs9jAiSr_c1g1E1E1c1A1__200" + ).parseUri.parseTsuNazoPuyo.nazoPuyo + + benchmark "Solve (Rashomon)", 1: + discard + do: + discard nazo.solve + + block: + let nazo = ( + "https://ishikawapuyo.net/simu/pn.html?" & + "P00P00PrAOqcOi9OriQpaQxAQzsNziN9aN_g1c1A1E1u16121q1__v0c" + ).parseUri.parseTsuNazoPuyo.nazoPuyo + + benchmark "Solve (Galaxy)", 1: + discard + do: + discard nazo.solve diff --git a/pon2.nimble b/pon2.nimble index 54f2726..90f09bf 100644 --- a/pon2.nimble +++ b/pon2.nimble @@ -40,10 +40,10 @@ task benchmark, "Benchmarking": exec &"nim c -r -d:avx2={avx2} -d:bmi2={bmi2} benchmark/main.nim" task documentation, "Make Documentation": - exec &"nim doc --project -d:avx2=false src/pon2.nim" + exec &"nim doc --project -d:avx2=true src/pon2.nim" mvDir "src/htmldocs", "src/htmldocs2" - exec &"nim doc --project -d:avx2=true src/pon2.nim" + exec &"nim doc --project -d:avx2=false src/pon2.nim" exec "cp -r src/htmldocs2 src/htmldocs" rmDir "src/htmldocs2" From 73780ce2352cd29e655e2adb26c9459033256aa6 Mon Sep 17 00:00:00 2001 From: Keisuke Izumiya Date: Thu, 30 Nov 2023 19:49:51 +0900 Subject: [PATCH 3/3] [documentation] CUI document --- README.md | 2 +- docs/{gui.md => edit.md} | 4 ++-- docs/generate.md | 2 +- docs/permute.md | 7 +++---- docs/solve.md | 2 +- 5 files changed, 8 insertions(+), 9 deletions(-) rename docs/{gui.md => edit.md} (94%) diff --git a/README.md b/README.md index 59b25ac..8bf9654 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ See the documentations: - [Solver](./docs/solve.md) - [Generator](./docs/generate.md) - [Permuter](./docs/permute.md) -- [Editor+Simulator](./docs/editor.md) +- [Editor+Simulator](./docs/edit.md) ## For Developers diff --git a/docs/gui.md b/docs/edit.md similarity index 94% rename from docs/gui.md rename to docs/edit.md index 1af06ac..959e1db 100644 --- a/docs/gui.md +++ b/docs/edit.md @@ -1,6 +1,6 @@ -# GUIアプリケーション +# エディタ・シミュレータ -なぞぷよを編集したり,自分でプレイしたりすることができる. +なぞぷよを編集したり,自分でプレイしたりする. ## 使い方 diff --git a/docs/generate.md b/docs/generate.md index 1d10ae9..bea4661 100644 --- a/docs/generate.md +++ b/docs/generate.md @@ -1,6 +1,6 @@ # ジェネレーター -なぞぷよを生成することができる. +なぞぷよを生成する. ## 使い方 diff --git a/docs/permute.md b/docs/permute.md index 0b7e8a8..b05904f 100644 --- a/docs/permute.md +++ b/docs/permute.md @@ -1,6 +1,6 @@ # ツモ探索 -ツモ部分のぷよを入れ替えたなぞぷよのうち,一意解であるものを求めることができる. +ツモ部分のぷよを入れ替えたなぞぷよのうち,一意解であるものを求める. ## 使い方 @@ -14,7 +14,7 @@ pon2 p [options] 例: ```shell -pon2 p https://ishikawapuyo.net/simu/pn.html?Mp6j92mS_o1q1__u03 -d +pon2 p https://ishikawapuyo.net/simu/pn.html?Mp6j92mS_o1q1__u03 -d -f 2 ``` ## オプション @@ -26,5 +26,4 @@ pon2 p https://ishikawapuyo.net/simu/pn.html?Mp6j92mS_o1q1__u03 -d | -B | 生成された問題をブラウザで開く. | 開かない | | -d | 最終手がゾロになるのを許可する. | 禁止 | | -D | いずれかのツモがゾロになるのを許可する. | 許可 | -| -f | 何手目を固定するか. | 固定なし | -| -S | 軸ぷよと子ぷよを入れ替えたツモは飛ばす. | 飛ばす | \ No newline at end of file +| -f | 何手目を固定するか. | 固定なし | \ No newline at end of file diff --git a/docs/solve.md b/docs/solve.md index eb66497..bdcc3c0 100644 --- a/docs/solve.md +++ b/docs/solve.md @@ -1,6 +1,6 @@ # ソルバー -なぞぷよの解を求めることができる. +なぞぷよの解を求める. ## 使い方