-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from izumiya-keisuke/unite
Unite
- Loading branch information
Showing
11 changed files
with
153 additions
and
63 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
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 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# GUIアプリケーション | ||
# エディタ・シミュレータ | ||
|
||
なぞぷよを編集したり,自分でプレイしたりすることができる. | ||
なぞぷよを編集したり,自分でプレイしたりする. | ||
|
||
## 使い方 | ||
|
||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# ジェネレーター | ||
|
||
なぞぷよを生成することができる. | ||
なぞぷよを生成する. | ||
|
||
## 使い方 | ||
|
||
|
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# ソルバー | ||
|
||
なぞぷよの解を求めることができる. | ||
なぞぷよの解を求める. | ||
|
||
## 使い方 | ||
|
||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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