diff --git a/README.md b/README.md index 59d75e2..6240c9e 100644 --- a/README.md +++ b/README.md @@ -1 +1,24 @@ # hask-chess + +## Notes + +Changing order of generated moves starting from king, queen and most valueble pieces instead of the other way around has the following huge speedup + +``` +benchmarking initial position/depth: 5 White +time 3.446 s (3.296 s .. 3.554 s) + 1.000 R² (1.000 R² .. 1.000 R²) +mean 3.436 s (3.397 s .. 3.467 s) +std dev 40.69 ms (17.53 ms .. 54.18 ms) +variance introduced by outliers: 19% (moderately inflated) +``` +to + +``` +benchmarking initial position/depth: 5 White +time 470.2 ms (464.1 ms .. 475.9 ms) + 1.000 R² (1.000 R² .. 1.000 R²) +mean 469.3 ms (466.8 ms .. 470.5 ms) +std dev 2.301 ms (89.80 μs .. 2.860 ms) +variance introduced by outliers: 19% (moderately inflated) +``` \ No newline at end of file diff --git a/bench.html b/bench.html new file mode 100644 index 0000000..1034568 --- /dev/null +++ b/bench.html @@ -0,0 +1,705 @@ + + + + + criterion report + + + + + + + + + +
+
+

criterion performance measurements

+ +

overview

+ +

want to understand this report?

+ +
+ +

initial position/depth: 2 White

+ + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
lower boundestimateupper bound
OLS regressionxxxxxxxxx
R² goodness-of-fitxxxxxxxxx
Mean execution time7.184156479601918e-47.248523730957002e-47.324370498371348e-4
Standard deviation1.8639691512974905e-52.340841664911922e-53.0546112174050066e-5
+ + +

Outlying measurements have moderate + (0.23490619993468234%) + effect on estimated standard deviation.

+
+

initial position/depth: 5 White

+ + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
lower boundestimateupper bound
OLS regressionxxxxxxxxx
R² goodness-of-fitxxxxxxxxx
Mean execution time0.460413838875126660.479763883520831770.4945598152916091
Standard deviation1.1613252334666077e-22.0656366662567663e-22.8647718665592365e-2
+ + +

Outlying measurements have moderate + (0.1875%) + effect on estimated standard deviation.

+
+

initial position/depth: 6 White

+ + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
lower boundestimateupper bound
OLS regressionxxxxxxxxx
R² goodness-of-fitxxxxxxxxx
Mean execution time4.0845637820000324.1536930166249044.184491083624825
Standard deviation1.933709899988889e-25.144117353665631e-27.11250890916982e-2
+ + +

Outlying measurements have moderate + (0.1875%) + effect on estimated standard deviation.

+
+ +

understanding this report

+ +

In this report, each function benchmarked by criterion is assigned + a section of its own. The charts in each section are active; if + you hover your mouse over data points and annotations, you will see + more details.

+ + + +

Under the charts is a small table. + The first two rows are the results of a linear regression run + on the measurements displayed in the right-hand chart.

+ + + +

We use a statistical technique called + the bootstrap + to provide confidence intervals on our estimates. The + bootstrap-derived upper and lower bounds on estimates let you see + how accurate we believe those estimates to be. (Hover the mouse + over the table headers to see the confidence levels.)

+ +

A noisy benchmarking environment can cause some or many + measurements to fall far from the mean. These outlying + measurements can have a significant inflationary effect on the + estimate of the standard deviation. We calculate and display an + estimate of the extent to which the standard deviation has been + inflated by outliers.

+ + + +
+
+ + + diff --git a/bench/Spec.hs b/bench/Spec.hs new file mode 100644 index 0000000..eaa688d --- /dev/null +++ b/bench/Spec.hs @@ -0,0 +1,13 @@ +import Criterion.Main + +import Fen +import Board +import GameTree + +main = defaultMain [ + bgroup "initial position" [ + bench "depth: 2 White" $ whnf (negamax initialGameState White) 2 + , bench "depth: 5 White" $ whnf (negamax initialGameState White) 5 + , bench "depth: 6 White" $ whnf (negamax initialGameState White) 6 + ] + ] \ No newline at end of file diff --git a/hen.cabal b/hen.cabal new file mode 100644 index 0000000..03c2e81 --- /dev/null +++ b/hen.cabal @@ -0,0 +1,98 @@ +cabal-version: 1.12 + +-- This file has been generated from package.yaml by hpack version 0.33.0. +-- +-- see: https://github.com/sol/hpack +-- +-- hash: 428cef491c676a221e29e7cb0aa5e5191422d48e704d833f35dbe1a4712f85d3 + +name: hen +version: 0.1.0.0 +description: Please see the README on GitHub at +homepage: https://github.com/nazrhom/hen#readme +bug-reports: https://github.com/nazrhom/hen/issues +author: Giovanni Garufi +maintainer: nazrhom@gmail.com +copyright: 2021 Giovanni Garufi +license: BSD3 +license-file: LICENSE +build-type: Simple +extra-source-files: + README.md + ChangeLog.md + +source-repository head + type: git + location: https://github.com/nazrhom/hen + +library + exposed-modules: + Board + Evaluation + Fen + GameTree + MoveGen + Uci + other-modules: + Paths_hen + hs-source-dirs: + src + build-depends: + base >=4.7 && <5 + , containers + , mtl + , parsec + , vector + default-language: Haskell2010 + +executable hen-exe + main-is: Main.hs + other-modules: + Paths_hen + hs-source-dirs: + app + ghc-options: -threaded -rtsopts -with-rtsopts=-N + build-depends: + base >=4.7 && <5 + , containers + , hen + , mtl + , parsec + , vector + default-language: Haskell2010 + +test-suite hen-test + type: exitcode-stdio-1.0 + main-is: Spec.hs + other-modules: + Paths_hen + hs-source-dirs: + test + ghc-options: -threaded -rtsopts -with-rtsopts=-N + build-depends: + HUnit + , base >=4.7 && <5 + , containers + , hen + , mtl + , parsec + , vector + default-language: Haskell2010 + +benchmark hen-bench + type: exitcode-stdio-1.0 + main-is: Spec.hs + other-modules: + Paths_hen + hs-source-dirs: + bench + ghc-options: -threaded -rtsopts -with-rtsopts=-N + build-depends: + base >=4.7 && <5 + , containers + , criterion + , hen + , mtl + , parsec + , vector + default-language: Haskell2010 diff --git a/package.yaml b/package.yaml index 8e6c2d6..4278478 100644 --- a/package.yaml +++ b/package.yaml @@ -25,7 +25,6 @@ dependencies: - mtl - parsec - containers -- HUnit library: source-dirs: src @@ -51,3 +50,16 @@ tests: - -with-rtsopts=-N dependencies: - hen + - HUnit + +benchmarks: + hen-bench: + main: Spec.hs + source-dirs: bench + ghc-options: + - -threaded + - -rtsopts + - -with-rtsopts=-N + dependencies: + - hen + - criterion diff --git a/src/MoveGen.hs b/src/MoveGen.hs index 04ded9d..fedc88c 100644 --- a/src/MoveGen.hs +++ b/src/MoveGen.hs @@ -25,12 +25,12 @@ knightMap = foldl (\m k -> M.insert k (go k m) m) M.empty [0..63] genMoves :: GameState -> Colour -> [Move] genMoves gs col = - genAllPawnMoves gs col - ++ genAllKnightMoves gs col - ++ genAllBishopMoves gs col - ++ genAllRookMoves gs col + genAllKingMoves gs col ++ genAllQueenMoves gs col - ++ genAllKingMoves gs col + ++ genAllRookMoves gs col + ++ genAllBishopMoves gs col + ++ genAllKnightMoves gs col + ++ genAllPawnMoves gs col applyAll :: GameState -> [Move] -> [GameState] applyAll gs moves = map (apply gs) moves