Skip to content

Commit

Permalink
Merge pull request #58 from izumiya-keisuke/unite
Browse files Browse the repository at this point in the history
Unite
  • Loading branch information
24ik authored Nov 30, 2023
2 parents 103a263 + d3b4a18 commit dc94d03
Show file tree
Hide file tree
Showing 11 changed files with 153 additions and 63 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
145 changes: 113 additions & 32 deletions benchmark/main.nim
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions docs/gui.md → docs/edit.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# GUIアプリケーション
# エディタ・シミュレータ

なぞぷよを編集したり,自分でプレイしたりすることができる
なぞぷよを編集したり,自分でプレイしたりする

## 使い方

Expand Down
2 changes: 1 addition & 1 deletion docs/generate.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ジェネレーター

なぞぷよを生成することができる
なぞぷよを生成する

## 使い方

Expand Down
7 changes: 3 additions & 4 deletions docs/permute.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ツモ探索

ツモ部分のぷよを入れ替えたなぞぷよのうち,一意解であるものを求めることができる
ツモ部分のぷよを入れ替えたなぞぷよのうち,一意解であるものを求める

## 使い方

Expand All @@ -14,7 +14,7 @@ pon2 p <question> [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
```

## オプション
Expand All @@ -26,5 +26,4 @@ pon2 p https://ishikawapuyo.net/simu/pn.html?Mp6j92mS_o1q1__u03 -d
| -B | 生成された問題をブラウザで開く. | 開かない |
| -d | 最終手がゾロになるのを許可する. | 禁止 |
| -D | いずれかのツモがゾロになるのを許可する. | 許可 |
| -f | 何手目を固定するか. | 固定なし |
| -S | 軸ぷよと子ぷよを入れ替えたツモは飛ばす. | 飛ばす |
| -f | 何手目を固定するか. | 固定なし |
2 changes: 1 addition & 1 deletion docs/solve.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ソルバー

なぞぷよの解を求めることができる
なぞぷよの解を求める

## 使い方

Expand Down
2 changes: 1 addition & 1 deletion pon2.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 10 additions & 0 deletions src/pon2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
24 changes: 12 additions & 12 deletions src/pon2pkg/core.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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=<int> | Height of the water. | `8` |
## | `-d:avx2=<bool>` | Use AVX2 instructions. | `true` |
## | `-d:bmi2=<bool>` | Use BMI2 instructions. | `true` |
## | Option | Description | Default |
## | ---------------------- | ---------------------- | ------- |
## | `-d:WaterHeight=<int>` | Height of the water. | `8` |
## | `-d:avx2=<bool>` | Use AVX2 instructions. | `true` |
## | `-d:bmi2=<bool>` | Use BMI2 instructions. | `true` |
##

{.experimental: "strictDefs".}
Expand Down
10 changes: 5 additions & 5 deletions src/pon2pkg/nazopuyo.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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".}
Expand Down
8 changes: 4 additions & 4 deletions src/pon2pkg/simulator.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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".}
Expand Down

0 comments on commit dc94d03

Please sign in to comment.