-
-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8dacf34
commit 8e2f09d
Showing
2 changed files
with
57 additions
and
84 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,27 +1,62 @@ | ||
package chess | ||
package perft | ||
|
||
import cats.syntax.all.* | ||
import weaver.* | ||
|
||
import chess.variant.* | ||
import cats.effect.IO | ||
import cats.kernel.Monoid | ||
|
||
object PerftTest extends SimpleIOSuite: | ||
|
||
given Monoid[Boolean] with | ||
def empty = true | ||
def combine(x: Boolean, y: Boolean) = x && y | ||
|
||
val nodeLimits = 1_000L | ||
|
||
test("random.perft"): | ||
perfts(Perft.randomPerfts, Chess960, 10_000L) | ||
.map(assert(_)) | ||
|
||
test("threeCheck.perft"): | ||
perfts(Perft.threeCheckPerfts, ThreeCheck, nodeLimits) | ||
.map(assert(_)) | ||
|
||
test("antichess.perft"): | ||
perfts(Perft.antichessPerfts, Antichess, nodeLimits) | ||
.map(assert(_)) | ||
|
||
test("atomic.perft"): | ||
perfts(Perft.atomicPerfts, Atomic, nodeLimits) | ||
.map(assert(_)) | ||
|
||
test("crazyhouse.perft"): | ||
perfts(Perft.crazyhousePerfts, Crazyhouse, nodeLimits) | ||
.map(assert(_)) | ||
|
||
test("horde.perft"): | ||
perfts(Perft.hordePerfts, Horde, nodeLimits) | ||
.map(assert(_)) | ||
|
||
test("racingkings.perft"): | ||
perfts(Perft.racingkingsPerfts, RacingKings, nodeLimits) | ||
.map(assert(_)) | ||
|
||
test("tricky.perft"): | ||
perfts(Perft.trickyPerfts, Chess960, nodeLimits) | ||
.map(assert(_)) | ||
|
||
test("chess960.perft"): | ||
perfts(Perft.chess960, Chess960, nodeLimits) | ||
.map(assert(_)) | ||
|
||
private def perfts(perfts: List[Perft], variant: Variant, nodeLimit: Long): IO[Boolean] = | ||
perfts.parFoldMapA(perft => IO(perftTest(perft, variant, nodeLimit))) | ||
|
||
class PerftTest extends ChessTest: | ||
|
||
private def genTests(name: String, tests: List[Perft], variant: Variant, nodeLimit: Long)(using | ||
munit.Location | ||
) = | ||
tests.foreach: perft => | ||
val result = perft.withLimit(nodeLimit).calculate(variant) | ||
result.foreach: r => | ||
test(s"$name ${perft.id} depth: ${r.depth}"): | ||
assertEquals(r.result, r.expected) | ||
|
||
val nodeLimits = 1_000_000L | ||
genTests("calculate ThreeCheck perfts", Perft.threeCheckPerfts, ThreeCheck, nodeLimits) | ||
genTests("calculate Antichess perfts", Perft.antichessPerfts, Antichess, nodeLimits) | ||
genTests("calculate Atomic perfts", Perft.atomicPerfts, Atomic, nodeLimits) | ||
genTests("calculate Crazyhouse perfts", Perft.crazyhousePerfts, Crazyhouse, nodeLimits) | ||
genTests("calculate Horde perfts", Perft.hordePerfts, Horde, nodeLimits) | ||
genTests("calculate RacingKings perfts", Perft.racingkingsPerfts, RacingKings, nodeLimits) | ||
// for the shake of time we only test the first 50 cases in random.peft, run FullRandomPerftTest.scala for all cases | ||
genTests("calculate random perfts", Perft.randomPerfts.take(100), Chess960, nodeLimits) | ||
genTests("calculate tricky perfts", Perft.trickyPerfts, Chess960, nodeLimits) | ||
genTests("calculate chess960 perfts", Perft.chess960, Chess960, nodeLimits) | ||
private def perftTest(perft: Perft, variant: Variant, nodeLimit: Long): Boolean = | ||
perft | ||
.withLimit(nodeLimit) | ||
.calculate(variant) | ||
.forall(r => r.result === r.expected) |