Compare commits

...

10 Commits

25 changed files with 3887 additions and 327 deletions

2
.gitignore vendored
View File

@ -1,2 +1,2 @@
/target target/
tarpaulin-report.html tarpaulin-report.html

View File

@ -1,11 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<module type="CPP_MODULE" version="4"> <module type="CPP_MODULE" version="4">
<component name="FacetManager">
<facet type="Python" name="Python facet">
<configuration sdkName="Python 3.10" />
</facet>
</component>
<component name="NewModuleRootManager"> <component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/bamboo/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/poceae/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target" /> <excludeFolder url="file://$MODULE_DIR$/target" />
<excludeFolder url="file://$MODULE_DIR$/poceae/target" />
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Python 3.10 interpreter library" level="application" />
</component> </component>
</module> </module>

942
Cargo.lock generated
View File

@ -2,6 +2,17 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 3 version = 3
[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi 0.1.19",
"libc",
"winapi",
]
[[package]] [[package]]
name = "autocfg" name = "autocfg"
version = "1.1.0" version = "1.1.0"
@ -12,9 +23,325 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
name = "bamboo" name = "bamboo"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"hex",
"spin", "spin",
] ]
[[package]]
name = "bincode"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a6301db0b49fb63551bc15b5ae348147101cdf323242b93ec7546d5002ff1af"
dependencies = [
"byteorder",
"serde",
]
[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bitstring"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22a39c0db600cfe77ef1b6d9ea71173bdccf190722877969d526d380519b6ecc"
[[package]]
name = "bstr"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223"
dependencies = [
"lazy_static",
"memchr",
"regex-automata",
"serde",
]
[[package]]
name = "byteorder"
version = "1.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
[[package]]
name = "bytes"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be"
[[package]]
name = "cc"
version = "1.0.79"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clap"
version = "4.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f13b9c79b5d1dd500d20ef541215a6423c75829ef43117e1b4d17fd8af0b5d76"
dependencies = [
"bitflags",
"clap_derive",
"clap_lex",
"is-terminal",
"once_cell",
"strsim",
"termcolor",
]
[[package]]
name = "clap_derive"
version = "4.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "684a277d672e91966334af371f1a7b5833f9aa00b07c84e92fbce95e00208ce8"
dependencies = [
"heck",
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "clap_lex"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "783fe232adfca04f90f56201b26d79682d4cd2625e0bc7290b95123afe558ade"
dependencies = [
"os_str_bytes",
]
[[package]]
name = "colored"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3616f750b84d8f0de8a58bda93e08e2a81ad3f523089b05f1dffecab48c6cbd"
dependencies = [
"atty",
"lazy_static",
"winapi",
]
[[package]]
name = "console"
version = "0.15.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3d79fbe8970a77e3e34151cc13d3b3e248aa0faaecb9f6091fa07ebefe5ad60"
dependencies = [
"encode_unicode",
"lazy_static",
"libc",
"unicode-width",
"windows-sys 0.42.0",
]
[[package]]
name = "csv"
version = "1.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22813a6dc45b335f9bade10bf7271dc477e81113e89eb251a0bc2a8a81c536e1"
dependencies = [
"bstr",
"csv-core",
"itoa 0.4.8",
"ryu",
"serde",
]
[[package]]
name = "csv-core"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b2466559f260f48ad25fe6317b3c8dac77b5bdb5763ac7d9d6103530663bc90"
dependencies = [
"memchr",
]
[[package]]
name = "dotenv"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f"
[[package]]
name = "either"
version = "1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91"
[[package]]
name = "encode_unicode"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f"
[[package]]
name = "envor"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6edde1c2487f9e5da9e3afdbb0a853f22347c348b800d901debf937234f5803b"
dependencies = [
"dotenv",
]
[[package]]
name = "errno"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1"
dependencies = [
"errno-dragonfly",
"libc",
"winapi",
]
[[package]]
name = "errno-dragonfly"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf"
dependencies = [
"cc",
"libc",
]
[[package]]
name = "fuchsia-cprng"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
[[package]]
name = "getrandom"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31"
dependencies = [
"cfg-if",
"libc",
"wasi",
]
[[package]]
name = "heck"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
[[package]]
name = "hermit-abi"
version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
dependencies = [
"libc",
]
[[package]]
name = "hermit-abi"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7"
dependencies = [
"libc",
]
[[package]]
name = "hermit-abi"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286"
[[package]]
name = "hex"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
[[package]]
name = "indicatif"
version = "0.17.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cef509aa9bc73864d6756f0d34d35504af3cf0844373afe9b8669a5b8005a729"
dependencies = [
"console",
"number_prefix",
"portable-atomic",
"unicode-width",
]
[[package]]
name = "io-lifetimes"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1abeb7a0dd0f8181267ff8adc397075586500b81b28a73e8a0208b00fc170fb3"
dependencies = [
"libc",
"windows-sys 0.45.0",
]
[[package]]
name = "is-terminal"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22e18b0a45d56fe973d6db23972bf5bc46f988a4a2385deac9cc29572f09daef"
dependencies = [
"hermit-abi 0.3.1",
"io-lifetimes",
"rustix",
"windows-sys 0.45.0",
]
[[package]]
name = "itertools"
version = "0.10.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473"
dependencies = [
"either",
]
[[package]]
name = "itoa"
version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4"
[[package]]
name = "itoa"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440"
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.139"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79"
[[package]]
name = "linux-raw-sys"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4"
[[package]] [[package]]
name = "lock_api" name = "lock_api"
version = "0.4.9" version = "0.4.9"
@ -25,12 +352,371 @@ dependencies = [
"scopeguard", "scopeguard",
] ]
[[package]]
name = "log"
version = "0.4.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
dependencies = [
"cfg-if",
]
[[package]]
name = "memchr"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
[[package]]
name = "mio"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5d732bc30207a6423068df043e3d02e0735b155ad7ce1a6f76fe2baa5b158de"
dependencies = [
"libc",
"log",
"wasi",
"windows-sys 0.42.0",
]
[[package]]
name = "neuroflow"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4cc1d18776c6954a1e478e6ea7c79c7a99f8f4765f7a4f74a935f03f3a5b521d"
dependencies = [
"bincode",
"csv",
"rand 0.3.23",
"serde",
"serde_derive",
"serde_json",
]
[[package]]
name = "num_cpus"
version = "1.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b"
dependencies = [
"hermit-abi 0.2.6",
"libc",
]
[[package]]
name = "num_threads"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44"
dependencies = [
"libc",
]
[[package]]
name = "number_prefix"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3"
[[package]]
name = "once_cell"
version = "1.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66"
[[package]]
name = "os_str_bytes"
version = "6.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee"
[[package]]
name = "parking_lot"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f"
dependencies = [
"lock_api",
"parking_lot_core",
]
[[package]]
name = "parking_lot_core"
version = "0.9.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521"
dependencies = [
"cfg-if",
"libc",
"redox_syscall",
"smallvec",
"windows-sys 0.45.0",
]
[[package]]
name = "pin-project-lite"
version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116"
[[package]]
name = "poceae"
version = "0.1.0"
dependencies = [
"bamboo",
"bitstring",
"clap",
"indicatif",
"itertools",
"log",
"neuroflow",
"rand 0.8.5",
"simple_logger",
"tokio",
"uciengine",
]
[[package]]
name = "portable-atomic"
version = "0.3.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26f6a7b87c2e435a3241addceeeff740ff8b7e76b74c13bf9acb17fa454ea00b"
[[package]]
name = "ppv-lite86"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
name = "proc-macro-error"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
dependencies = [
"proc-macro-error-attr",
"proc-macro2",
"quote",
"syn",
"version_check",
]
[[package]]
name = "proc-macro-error-attr"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
dependencies = [
"proc-macro2",
"quote",
"version_check",
]
[[package]]
name = "proc-macro2"
version = "1.0.51"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b"
dependencies = [
"proc-macro2",
]
[[package]]
name = "rand"
version = "0.3.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64ac302d8f83c0c1974bf758f6b041c6c8ada916fbb44a609158ca8b064cc76c"
dependencies = [
"libc",
"rand 0.4.6",
]
[[package]]
name = "rand"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293"
dependencies = [
"fuchsia-cprng",
"libc",
"rand_core 0.3.1",
"rdrand",
"winapi",
]
[[package]]
name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core 0.6.4",
]
[[package]]
name = "rand_chacha"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core 0.6.4",
]
[[package]]
name = "rand_core"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b"
dependencies = [
"rand_core 0.4.2",
]
[[package]]
name = "rand_core"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc"
[[package]]
name = "rand_core"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [
"getrandom",
]
[[package]]
name = "rdrand"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2"
dependencies = [
"rand_core 0.3.1",
]
[[package]]
name = "redox_syscall"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a"
dependencies = [
"bitflags",
]
[[package]]
name = "regex-automata"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
[[package]]
name = "rustix"
version = "0.36.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f43abb88211988493c1abb44a70efa56ff0ce98f233b7b276146f1f3f7ba9644"
dependencies = [
"bitflags",
"errno",
"io-lifetimes",
"libc",
"linux-raw-sys",
"windows-sys 0.45.0",
]
[[package]]
name = "ryu"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde"
[[package]] [[package]]
name = "scopeguard" name = "scopeguard"
version = "1.1.0" version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "serde"
version = "1.0.152"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.152"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "serde_json"
version = "1.0.93"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cad406b69c91885b5107daf2c29572f6c8cdb3c66826821e286c533490c0bc76"
dependencies = [
"itoa 1.0.5",
"ryu",
"serde",
]
[[package]]
name = "signal-hook-registry"
version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1"
dependencies = [
"libc",
]
[[package]]
name = "simple_logger"
version = "4.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e190a521c2044948158666916d9e872cbb9984f755e9bb3b5b75a836205affcd"
dependencies = [
"atty",
"colored",
"log",
"time",
"windows-sys 0.42.0",
]
[[package]]
name = "smallvec"
version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0"
[[package]]
name = "socket2"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd"
dependencies = [
"libc",
"winapi",
]
[[package]] [[package]]
name = "spin" name = "spin"
version = "0.9.5" version = "0.9.5"
@ -39,3 +725,259 @@ checksum = "7dccf47db1b41fa1573ed27ccf5e08e3ca771cb994f776668c5ebda893b248fc"
dependencies = [ dependencies = [
"lock_api", "lock_api",
] ]
[[package]]
name = "strsim"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "syn"
version = "1.0.107"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "termcolor"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6"
dependencies = [
"winapi-util",
]
[[package]]
name = "thiserror"
version = "1.0.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "time"
version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a561bf4617eebd33bca6434b988f39ed798e527f51a1e797d0ee4f61c0a38376"
dependencies = [
"itoa 1.0.5",
"libc",
"num_threads",
"serde",
"time-core",
"time-macros",
]
[[package]]
name = "time-core"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd"
[[package]]
name = "time-macros"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d967f99f534ca7e495c575c62638eebc2898a8c84c119b89e250477bc4ba16b2"
dependencies = [
"time-core",
]
[[package]]
name = "tokio"
version = "1.25.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c8e00990ebabbe4c14c08aca901caed183ecd5c09562a12c824bb53d3c3fd3af"
dependencies = [
"autocfg",
"bytes",
"libc",
"memchr",
"mio",
"num_cpus",
"parking_lot",
"pin-project-lite",
"signal-hook-registry",
"socket2",
"tokio-macros",
"windows-sys 0.42.0",
]
[[package]]
name = "tokio-macros"
version = "1.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "uciengine"
version = "0.1.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40fbc4b3240348173c7ebe246c03ba7948c6b958fea6151c54369e451bd85c8f"
dependencies = [
"envor",
"log",
"serde",
"serde_json",
"thiserror",
"tokio",
]
[[package]]
name = "unicode-ident"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc"
[[package]]
name = "unicode-width"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b"
[[package]]
name = "version_check"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
dependencies = [
"winapi",
]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows-sys"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows-sys"
version = "0.45.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608"
[[package]]
name = "windows_aarch64_msvc"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7"
[[package]]
name = "windows_i686_gnu"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640"
[[package]]
name = "windows_i686_msvc"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605"
[[package]]
name = "windows_x86_64_gnu"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463"
[[package]]
name = "windows_x86_64_msvc"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd"

View File

@ -1,9 +1,5 @@
[package] [workspace]
name = "bamboo" members = [
version = "0.1.0" "poceae",
edition = "2021" "bamboo"
]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
spin = "0.9.5"

674
LICENSE.txt Normal file
View File

@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<https://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.

2
README.md Normal file
View File

@ -0,0 +1,2 @@
# Bamboo
Bamboo is a chess engine written in Rust that uses a machine learning model for board evaluation.

910
bamboo/Cargo.lock generated Normal file
View File

@ -0,0 +1,910 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi 0.1.19",
"libc",
"winapi",
]
[[package]]
name = "autocfg"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "bamboo"
version = "0.1.0"
dependencies = [
"hex",
"neuroflow",
"spin",
]
[[package]]
name = "bincode"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a6301db0b49fb63551bc15b5ae348147101cdf323242b93ec7546d5002ff1af"
dependencies = [
"byteorder",
"serde",
]
[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bstr"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223"
dependencies = [
"lazy_static",
"memchr",
"regex-automata",
"serde",
]
[[package]]
name = "byteorder"
version = "1.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
[[package]]
name = "bytes"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be"
[[package]]
name = "cc"
version = "1.0.79"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clap"
version = "4.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f13b9c79b5d1dd500d20ef541215a6423c75829ef43117e1b4d17fd8af0b5d76"
dependencies = [
"bitflags",
"clap_derive",
"clap_lex",
"is-terminal",
"once_cell",
"strsim",
"termcolor",
]
[[package]]
name = "clap_derive"
version = "4.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "684a277d672e91966334af371f1a7b5833f9aa00b07c84e92fbce95e00208ce8"
dependencies = [
"heck",
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "clap_lex"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "783fe232adfca04f90f56201b26d79682d4cd2625e0bc7290b95123afe558ade"
dependencies = [
"os_str_bytes",
]
[[package]]
name = "colored"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3616f750b84d8f0de8a58bda93e08e2a81ad3f523089b05f1dffecab48c6cbd"
dependencies = [
"atty",
"lazy_static",
"winapi",
]
[[package]]
name = "csv"
version = "1.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22813a6dc45b335f9bade10bf7271dc477e81113e89eb251a0bc2a8a81c536e1"
dependencies = [
"bstr",
"csv-core",
"itoa 0.4.8",
"ryu",
"serde",
]
[[package]]
name = "csv-core"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b2466559f260f48ad25fe6317b3c8dac77b5bdb5763ac7d9d6103530663bc90"
dependencies = [
"memchr",
]
[[package]]
name = "dotenv"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f"
[[package]]
name = "envor"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6edde1c2487f9e5da9e3afdbb0a853f22347c348b800d901debf937234f5803b"
dependencies = [
"dotenv",
]
[[package]]
name = "errno"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1"
dependencies = [
"errno-dragonfly",
"libc",
"winapi",
]
[[package]]
name = "errno-dragonfly"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf"
dependencies = [
"cc",
"libc",
]
[[package]]
name = "fuchsia-cprng"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
[[package]]
name = "getrandom"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31"
dependencies = [
"cfg-if",
"libc",
"wasi",
]
[[package]]
name = "heck"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
[[package]]
name = "hermit-abi"
version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
dependencies = [
"libc",
]
[[package]]
name = "hermit-abi"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7"
dependencies = [
"libc",
]
[[package]]
name = "hermit-abi"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286"
[[package]]
name = "hex"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
[[package]]
name = "io-lifetimes"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1abeb7a0dd0f8181267ff8adc397075586500b81b28a73e8a0208b00fc170fb3"
dependencies = [
"libc",
"windows-sys 0.45.0",
]
[[package]]
name = "is-terminal"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22e18b0a45d56fe973d6db23972bf5bc46f988a4a2385deac9cc29572f09daef"
dependencies = [
"hermit-abi 0.3.1",
"io-lifetimes",
"rustix",
"windows-sys 0.45.0",
]
[[package]]
name = "itoa"
version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4"
[[package]]
name = "itoa"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440"
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.139"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79"
[[package]]
name = "linux-raw-sys"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4"
[[package]]
name = "lock_api"
version = "0.4.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df"
dependencies = [
"autocfg",
"scopeguard",
]
[[package]]
name = "log"
version = "0.4.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
dependencies = [
"cfg-if",
]
[[package]]
name = "memchr"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
[[package]]
name = "mio"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5d732bc30207a6423068df043e3d02e0735b155ad7ce1a6f76fe2baa5b158de"
dependencies = [
"libc",
"log",
"wasi",
"windows-sys 0.42.0",
]
[[package]]
name = "neuroflow"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4cc1d18776c6954a1e478e6ea7c79c7a99f8f4765f7a4f74a935f03f3a5b521d"
dependencies = [
"bincode",
"csv",
"rand 0.3.23",
"serde",
"serde_derive",
"serde_json",
]
[[package]]
name = "num_cpus"
version = "1.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b"
dependencies = [
"hermit-abi 0.2.6",
"libc",
]
[[package]]
name = "num_threads"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44"
dependencies = [
"libc",
]
[[package]]
name = "once_cell"
version = "1.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66"
[[package]]
name = "os_str_bytes"
version = "6.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee"
[[package]]
name = "parking_lot"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f"
dependencies = [
"lock_api",
"parking_lot_core",
]
[[package]]
name = "parking_lot_core"
version = "0.9.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521"
dependencies = [
"cfg-if",
"libc",
"redox_syscall",
"smallvec",
"windows-sys 0.45.0",
]
[[package]]
name = "pin-project-lite"
version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116"
[[package]]
name = "poceae"
version = "0.1.0"
dependencies = [
"clap",
"log",
"neuroflow",
"rand 0.8.5",
"simple_logger",
"tokio",
"uciengine",
]
[[package]]
name = "ppv-lite86"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
name = "proc-macro-error"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
dependencies = [
"proc-macro-error-attr",
"proc-macro2",
"quote",
"syn",
"version_check",
]
[[package]]
name = "proc-macro-error-attr"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
dependencies = [
"proc-macro2",
"quote",
"version_check",
]
[[package]]
name = "proc-macro2"
version = "1.0.51"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b"
dependencies = [
"proc-macro2",
]
[[package]]
name = "rand"
version = "0.3.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64ac302d8f83c0c1974bf758f6b041c6c8ada916fbb44a609158ca8b064cc76c"
dependencies = [
"libc",
"rand 0.4.6",
]
[[package]]
name = "rand"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293"
dependencies = [
"fuchsia-cprng",
"libc",
"rand_core 0.3.1",
"rdrand",
"winapi",
]
[[package]]
name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core 0.6.4",
]
[[package]]
name = "rand_chacha"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core 0.6.4",
]
[[package]]
name = "rand_core"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b"
dependencies = [
"rand_core 0.4.2",
]
[[package]]
name = "rand_core"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc"
[[package]]
name = "rand_core"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [
"getrandom",
]
[[package]]
name = "rdrand"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2"
dependencies = [
"rand_core 0.3.1",
]
[[package]]
name = "redox_syscall"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a"
dependencies = [
"bitflags",
]
[[package]]
name = "regex-automata"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
[[package]]
name = "rustix"
version = "0.36.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f43abb88211988493c1abb44a70efa56ff0ce98f233b7b276146f1f3f7ba9644"
dependencies = [
"bitflags",
"errno",
"io-lifetimes",
"libc",
"linux-raw-sys",
"windows-sys 0.45.0",
]
[[package]]
name = "ryu"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde"
[[package]]
name = "scopeguard"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "serde"
version = "1.0.152"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.152"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "serde_json"
version = "1.0.93"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cad406b69c91885b5107daf2c29572f6c8cdb3c66826821e286c533490c0bc76"
dependencies = [
"itoa 1.0.5",
"ryu",
"serde",
]
[[package]]
name = "signal-hook-registry"
version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1"
dependencies = [
"libc",
]
[[package]]
name = "simple_logger"
version = "4.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e190a521c2044948158666916d9e872cbb9984f755e9bb3b5b75a836205affcd"
dependencies = [
"atty",
"colored",
"log",
"time",
"windows-sys 0.42.0",
]
[[package]]
name = "smallvec"
version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0"
[[package]]
name = "socket2"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd"
dependencies = [
"libc",
"winapi",
]
[[package]]
name = "spin"
version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7dccf47db1b41fa1573ed27ccf5e08e3ca771cb994f776668c5ebda893b248fc"
dependencies = [
"lock_api",
]
[[package]]
name = "strsim"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "syn"
version = "1.0.107"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "termcolor"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6"
dependencies = [
"winapi-util",
]
[[package]]
name = "thiserror"
version = "1.0.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "time"
version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a561bf4617eebd33bca6434b988f39ed798e527f51a1e797d0ee4f61c0a38376"
dependencies = [
"itoa 1.0.5",
"libc",
"num_threads",
"serde",
"time-core",
"time-macros",
]
[[package]]
name = "time-core"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd"
[[package]]
name = "time-macros"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d967f99f534ca7e495c575c62638eebc2898a8c84c119b89e250477bc4ba16b2"
dependencies = [
"time-core",
]
[[package]]
name = "tokio"
version = "1.25.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c8e00990ebabbe4c14c08aca901caed183ecd5c09562a12c824bb53d3c3fd3af"
dependencies = [
"autocfg",
"bytes",
"libc",
"memchr",
"mio",
"num_cpus",
"parking_lot",
"pin-project-lite",
"signal-hook-registry",
"socket2",
"tokio-macros",
"windows-sys 0.42.0",
]
[[package]]
name = "tokio-macros"
version = "1.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "uciengine"
version = "0.1.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40fbc4b3240348173c7ebe246c03ba7948c6b958fea6151c54369e451bd85c8f"
dependencies = [
"envor",
"log",
"serde",
"serde_json",
"thiserror",
"tokio",
]
[[package]]
name = "unicode-ident"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc"
[[package]]
name = "version_check"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
dependencies = [
"winapi",
]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows-sys"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows-sys"
version = "0.45.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608"
[[package]]
name = "windows_aarch64_msvc"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7"
[[package]]
name = "windows_i686_gnu"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640"
[[package]]
name = "windows_i686_msvc"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605"
[[package]]
name = "windows_x86_64_gnu"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463"
[[package]]
name = "windows_x86_64_msvc"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd"

10
bamboo/Cargo.toml Normal file
View File

@ -0,0 +1,10 @@
[package]
name = "bamboo"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
spin = "0.9.5"
hex = "0.4.3"

332
bamboo/src/board.rs Normal file
View File

@ -0,0 +1,332 @@
// Bamboo, a NNUE chess engine written in Rust.
// Copyright (C) 2023 c0repwn3r
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//! Provides structs and functions for managing representations of a chess board.
use crate::boardfield::{Boardfield, BoardfieldOps};
use crate::error::FENParseError;
use crate::piece::{PieceColor, PieceOnBoard, PieceType};
use crate::utils::{algebraic_to_boardloc};
#[derive(Debug, PartialEq, Eq, Clone)]
#[allow(clippy::struct_excessive_bools)]
/// A struct to represent a chessboard and the pieces and state associated with it.
pub struct Board {
bitfield: Boardfield,
// While this is a less efficient memory layout, having an array of where all the pieces are will make move generation significantly faster.
piecelist: Vec<PieceOnBoard>,
turn: PieceColor,
castle_white_kingside: bool,
castle_white_queenside: bool,
castle_black_kingside: bool,
castle_black_queenside: bool,
en_passant_target: Option<isize>,
move_counter: usize,
halfmove_counter: usize
}
impl Board {
/// Convert the current state of the board into a 41-byte packed board ID. This packed representation contains all piece data and flags associated with the chessboard and is sufficient for unique identification and compact storage of chessboards.
pub fn to_board_id(&self) -> [u8; 41] {
let mut res = [0u8; 41];
res[0..32].copy_from_slice(&self.bitfield.get_field());
let mut flags_byte = res[32];
// FLAGS BYTE:
//
// / unused
// |
// 000 0 0 0 0 0
// | | | | \
// | | | | turn to move (1 white, 0 black)
// | | | \
// | | | white kingside castling
// | | \
// | | white queenside castling
// | \
// | black kingside castling
// \
// black queenside castling
if self.turn == PieceColor::White {
flags_byte |= 0b1;
}
if self.castle_white_kingside {
flags_byte |= 0b1 << 1;
}
if self.castle_white_queenside {
flags_byte |= 0b1 << 2;
}
if self.castle_black_kingside {
flags_byte |= 0b1 << 3;
}
if self.castle_black_queenside {
flags_byte |= 0b1 << 4;
}
res[32] = flags_byte;
#[allow(clippy::cast_possible_truncation)] {
let en_passant_target: [u8; 4] = self.en_passant_target.map_or_else(|| u32::MAX.to_le_bytes(), |target| (target as i32).to_le_bytes());
res[33..37].copy_from_slice(&en_passant_target);
res[37..39].copy_from_slice(&(self.halfmove_counter as u16).to_le_bytes());
res[39..41].copy_from_slice(&(self.move_counter as u16).to_le_bytes());
}
res
}
/// Create a new `Board` from a FEN string.
/// # Errors
/// This function will return an error if an invalid FEN string is passed.
/// # Panics
/// This function, while containing code that can panic, will never panic as the string is bounds checked.
#[allow(clippy::cast_possible_wrap)]
#[allow(clippy::match_on_vec_items)]
pub fn from_fen(fen: &str) -> Result<Self, FENParseError> {
let components = fen.split(' ').collect::<Vec<&str>>();
if components.len() != 6 {
return Err(FENParseError::InvalidNumberOfComponents { got: components.len() as isize });
}
// turn to move
let turn = match components[1] {
"w" => PieceColor::White,
"b" => PieceColor::Black,
_ => return Err(FENParseError::InvalidPlayerToMove { got: components[0].to_string() })
};
// castling rights
let castle_white_kingside = components[2].contains('K');
let castle_white_queenside = components[2].contains('Q');
let castle_black_kingside = components[2].contains('k');
let castle_black_queenside = components[2].contains('q');
let en_passant_target = match components[3] {
"-" => None,
_ => match algebraic_to_boardloc(components[3]) {
Ok(t) => Some(t),
Err(e) => return Err(FENParseError::EnPassantTargetParseError { e })
}
};
let halfmove_counter = match components[4].parse() {
Ok(r) => r,
Err(e) => return Err(FENParseError::InvalidMoveCounter { e })
};
let move_counter = match components[5].parse() {
Ok(r) => r,
Err(e) => return Err(FENParseError::InvalidMoveCounter { e })
};
// parse the actual piece string
let mut piecelist = Vec::new();
let mut bitfield = Boardfield::new();
let mut rank = 0;
let mut file = 0;
// parse component 1: piece data
for char in components[0].chars() {
match char {
'r' | 'n' | 'b' | 'q' | 'k' | 'p' | 'R' | 'N' | 'B' | 'Q' | 'K' | 'P' => {
piecelist.push(create_fen_piece(char, 8 - rank, file)?);
bitfield.set_pos(((8 - rank) + file * 8) - 1, create_bitfield_piece(char)?);
file += 1;
}
_ if char.is_numeric() => {
let num;
// see above (.is_numeric())
#[allow(clippy::unwrap_used)] {
num = char.to_digit(10).unwrap() as isize;
}
if !(1..=8).contains(&num) {
return Err(FENParseError::CannotSkipToOutsideOfBoard { got: num, which_is: num });
}
if file + num > 8 {
return Err(FENParseError::CannotSkipToOutsideOfBoard { got: num, which_is: file + num });
}
file += num;
}
'/' => {
if rank == 7 {
return Err(FENParseError::CannotSkipToOutsideOfBoard { got: 1, which_is: file + 1 });
}
rank += 1;
file = 0;
}
_ => return Err(FENParseError::InvalidPieceCharacter { got: char })
}
}
Ok(Self {
bitfield,
piecelist,
turn,
castle_white_kingside,
castle_white_queenside,
castle_black_kingside,
castle_black_queenside,
en_passant_target,
move_counter,
halfmove_counter,
})
}
}
const fn create_fen_piece(c: char, rank: isize, file: isize) -> Result<PieceOnBoard, FENParseError> {
Ok(PieceOnBoard {
loc: (rank + file * 8) - 1,
value: match c {
'r' => PieceColor::Black as u8 | PieceType::Rook as u8,
'n' => PieceColor::Black as u8 | PieceType::Knight as u8,
'b' => PieceColor::Black as u8 | PieceType::Bishop as u8,
'q' => PieceColor::Black as u8 | PieceType::Queen as u8,
'k' => PieceColor::Black as u8 | PieceType::King as u8,
'p' => PieceColor::Black as u8 | PieceType::Pawn as u8,
'R' => PieceColor::White as u8 | PieceType::Rook as u8,
'N' => PieceColor::White as u8 | PieceType::Knight as u8,
'B' => PieceColor::White as u8 | PieceType::Bishop as u8,
'Q' => PieceColor::White as u8 | PieceType::Queen as u8,
'K' => PieceColor::White as u8 | PieceType::King as u8,
'P' => PieceColor::White as u8 | PieceType::Pawn as u8,
_ => return Err(FENParseError::InvalidPieceCharacter { got: c })
},
})
}
const fn create_bitfield_piece(c: char) -> Result<u8, FENParseError> {
match c {
'r' => Ok(PieceColor::Black as u8 | PieceType::Rook as u8),
'n' => Ok(PieceColor::Black as u8 | PieceType::Knight as u8),
'b' => Ok(PieceColor::Black as u8 | PieceType::Bishop as u8),
'q' => Ok(PieceColor::Black as u8 | PieceType::Queen as u8),
'k' => Ok(PieceColor::Black as u8 | PieceType::King as u8),
'p' => Ok(PieceColor::Black as u8 | PieceType::Pawn as u8),
'R' => Ok(PieceColor::White as u8 | PieceType::Rook as u8),
'N' => Ok(PieceColor::White as u8 | PieceType::Knight as u8),
'B' => Ok(PieceColor::White as u8 | PieceType::Bishop as u8),
'Q' => Ok(PieceColor::White as u8 | PieceType::Queen as u8),
'K' => Ok(PieceColor::White as u8 | PieceType::King as u8),
'P' => Ok(PieceColor::White as u8 | PieceType::Pawn as u8),
_ => Err(FENParseError::InvalidPieceCharacter { got: c })
}
}
#[cfg(test)]
#[allow(clippy::unwrap_used)]
#[allow(clippy::expect_used)]
mod tests {
use crate::board::{Board, create_bitfield_piece, create_fen_piece};
use crate::boardfield::BoardfieldOps;
use crate::boardloc;
use crate::piece::{PieceColor, PieceType};
#[test]
pub fn test_serialization() {
assert_eq!(Board::from_fen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w - - 0 1").unwrap().to_board_id(), [156, 0, 0, 65, 154, 0, 0, 33, 155, 0, 0, 49, 157, 0, 0, 81, 158, 0, 0, 97, 155, 0, 0, 49, 154, 0, 0, 33, 156, 0, 0, 65, 1, 255, 255, 255, 255, 0, 0, 1, 0]);
assert_eq!(Board::from_fen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w q - 0 1").unwrap().to_board_id(), [156, 0, 0, 65, 154, 0, 0, 33, 155, 0, 0, 49, 157, 0, 0, 81, 158, 0, 0, 97, 155, 0, 0, 49, 154, 0, 0, 33, 156, 0, 0, 65, 17, 255, 255, 255, 255, 0, 0, 1, 0]);
assert_eq!(Board::from_fen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w k - 0 1").unwrap().to_board_id(), [156, 0, 0, 65, 154, 0, 0, 33, 155, 0, 0, 49, 157, 0, 0, 81, 158, 0, 0, 97, 155, 0, 0, 49, 154, 0, 0, 33, 156, 0, 0, 65, 9, 255, 255, 255, 255, 0, 0, 1, 0]);
assert_eq!(Board::from_fen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w kq - 0 1").unwrap().to_board_id(), [156, 0, 0, 65, 154, 0, 0, 33, 155, 0, 0, 49, 157, 0, 0, 81, 158, 0, 0, 97, 155, 0, 0, 49, 154, 0, 0, 33, 156, 0, 0, 65, 25, 255, 255, 255, 255, 0, 0, 1, 0]);
assert_eq!(Board::from_fen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w Q - 0 1").unwrap().to_board_id(), [156, 0, 0, 65, 154, 0, 0, 33, 155, 0, 0, 49, 157, 0, 0, 81, 158, 0, 0, 97, 155, 0, 0, 49, 154, 0, 0, 33, 156, 0, 0, 65, 5, 255, 255, 255, 255, 0, 0, 1, 0]);
assert_eq!(Board::from_fen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w Qq - 0 1").unwrap().to_board_id(), [156, 0, 0, 65, 154, 0, 0, 33, 155, 0, 0, 49, 157, 0, 0, 81, 158, 0, 0, 97, 155, 0, 0, 49, 154, 0, 0, 33, 156, 0, 0, 65, 21, 255, 255, 255, 255, 0, 0, 1, 0]);
assert_eq!(Board::from_fen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w Qk - 0 1").unwrap().to_board_id(), [156, 0, 0, 65, 154, 0, 0, 33, 155, 0, 0, 49, 157, 0, 0, 81, 158, 0, 0, 97, 155, 0, 0, 49, 154, 0, 0, 33, 156, 0, 0, 65, 13, 255, 255, 255, 255, 0, 0, 1, 0]);
assert_eq!(Board::from_fen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w Qkq - 0 1").unwrap().to_board_id(), [156, 0, 0, 65, 154, 0, 0, 33, 155, 0, 0, 49, 157, 0, 0, 81, 158, 0, 0, 97, 155, 0, 0, 49, 154, 0, 0, 33, 156, 0, 0, 65, 29, 255, 255, 255, 255, 0, 0, 1, 0]);
assert_eq!(Board::from_fen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w K - 0 1").unwrap().to_board_id(), [156, 0, 0, 65, 154, 0, 0, 33, 155, 0, 0, 49, 157, 0, 0, 81, 158, 0, 0, 97, 155, 0, 0, 49, 154, 0, 0, 33, 156, 0, 0, 65, 3, 255, 255, 255, 255, 0, 0, 1, 0]);
assert_eq!(Board::from_fen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w Kq - 0 1").unwrap().to_board_id(), [156, 0, 0, 65, 154, 0, 0, 33, 155, 0, 0, 49, 157, 0, 0, 81, 158, 0, 0, 97, 155, 0, 0, 49, 154, 0, 0, 33, 156, 0, 0, 65, 19, 255, 255, 255, 255, 0, 0, 1, 0]);
assert_eq!(Board::from_fen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w Kk - 0 1").unwrap().to_board_id(), [156, 0, 0, 65, 154, 0, 0, 33, 155, 0, 0, 49, 157, 0, 0, 81, 158, 0, 0, 97, 155, 0, 0, 49, 154, 0, 0, 33, 156, 0, 0, 65, 11, 255, 255, 255, 255, 0, 0, 1, 0]);
assert_eq!(Board::from_fen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQ - 0 1").unwrap().to_board_id(), [156, 0, 0, 65, 154, 0, 0, 33, 155, 0, 0, 49, 157, 0, 0, 81, 158, 0, 0, 97, 155, 0, 0, 49, 154, 0, 0, 33, 156, 0, 0, 65, 7, 255, 255, 255, 255, 0, 0, 1, 0]);
assert_eq!(Board::from_fen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQq - 0 1").unwrap().to_board_id(), [156, 0, 0, 65, 154, 0, 0, 33, 155, 0, 0, 49, 157, 0, 0, 81, 158, 0, 0, 97, 155, 0, 0, 49, 154, 0, 0, 33, 156, 0, 0, 65, 23, 255, 255, 255, 255, 0, 0, 1, 0]);
assert_eq!(Board::from_fen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQk - 0 1").unwrap().to_board_id(), [156, 0, 0, 65, 154, 0, 0, 33, 155, 0, 0, 49, 157, 0, 0, 81, 158, 0, 0, 97, 155, 0, 0, 49, 154, 0, 0, 33, 156, 0, 0, 65, 15, 255, 255, 255, 255, 0, 0, 1, 0]);
assert_eq!(Board::from_fen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR b KQkq a4 0 1").unwrap().to_board_id(), [156, 0, 0, 65, 154, 0, 0, 33, 155, 0, 0, 49, 157, 0, 0, 81, 158, 0, 0, 97, 155, 0, 0, 49, 154, 0, 0, 33, 156, 0, 0, 65, 30, 3, 0, 0, 0, 0, 0, 1, 0]);
println!("{}", Board::from_fen("d").unwrap_err());
println!("{}", Board::from_fen("8/8/8/8/8/8/8/8 h - - 0 1").unwrap_err());
println!("{}", Board::from_fen("8/8/8/8/8/8/8 w KQkq j4 0 1").unwrap_err());
println!("{}", Board::from_fen("9/8/8/8/8/8/8 w KQkq a4 0 1").unwrap_err());
println!("{}", Board::from_fen("18/8/8/8/8/8/8 w KQkq a4 0 1").unwrap_err());
println!("{}", Board::from_fen("8/8/8/8/8/8/8/8/8 w KQkq a4 0 1").unwrap_err());
println!("{}", Board::from_fen("8/8/8/8/8/8/8/8 w KQkq a4 a 1").unwrap_err());
println!("{}", Board::from_fen("8/8/8/8/8/8/8/8 w KQkq a4 0 a").unwrap_err());
println!("{}", Board::from_fen("s w KQkq a4 0 1").unwrap_err());
assert_eq!(Board::from_fen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1").unwrap().to_board_id(), [156, 0, 0, 65, 154, 0, 0, 33, 155, 0, 0, 49, 157, 0, 0, 81, 158, 0, 0, 97, 155, 0, 0, 49, 154, 0, 0, 33, 156, 0, 0, 65, 31, 255, 255, 255, 255, 0, 0, 1, 0]);
}
#[test]
pub fn fen_error_testing() {
assert!(create_fen_piece('m', 0, 0).is_err());
println!("{}", create_fen_piece('m', 0, 0).unwrap_err());
assert!(create_bitfield_piece('m').is_err());
println!("{}", create_bitfield_piece('m').unwrap_err());
}
#[test]
#[allow(clippy::cognitive_complexity)]
pub fn fen_parse_testing() {
let board = Board::from_fen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1").unwrap();
let field = board.bitfield;
assert_eq!(field.get_pos(boardloc!("a1")), PieceType::Rook as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(boardloc!("b1")), PieceType::Knight as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(boardloc!("c1")), PieceType::Bishop as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(boardloc!("d1")), PieceType::Queen as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(boardloc!("e1")), PieceType::King as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(boardloc!("f1")), PieceType::Bishop as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(boardloc!("g1")), PieceType::Knight as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(boardloc!("h1")), PieceType::Rook as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(boardloc!("a2")), PieceType::Pawn as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(boardloc!("b2")), PieceType::Pawn as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(boardloc!("c2")), PieceType::Pawn as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(boardloc!("d2")), PieceType::Pawn as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(boardloc!("e2")), PieceType::Pawn as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(boardloc!("f2")), PieceType::Pawn as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(boardloc!("g2")), PieceType::Pawn as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(boardloc!("h2")), PieceType::Pawn as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(boardloc!("a7")), PieceType::Pawn as u8 | PieceColor::Black as u8);
assert_eq!(field.get_pos(boardloc!("b7")), PieceType::Pawn as u8 | PieceColor::Black as u8);
assert_eq!(field.get_pos(boardloc!("c7")), PieceType::Pawn as u8 | PieceColor::Black as u8);
assert_eq!(field.get_pos(boardloc!("d7")), PieceType::Pawn as u8 | PieceColor::Black as u8);
assert_eq!(field.get_pos(boardloc!("e7")), PieceType::Pawn as u8 | PieceColor::Black as u8);
assert_eq!(field.get_pos(boardloc!("f7")), PieceType::Pawn as u8 | PieceColor::Black as u8);
assert_eq!(field.get_pos(boardloc!("g7")), PieceType::Pawn as u8 | PieceColor::Black as u8);
assert_eq!(field.get_pos(boardloc!("h7")), PieceType::Pawn as u8 | PieceColor::Black as u8);
assert_eq!(field.get_pos(boardloc!("a8")), PieceType::Rook as u8 | PieceColor::Black as u8);
assert_eq!(field.get_pos(boardloc!("b8")), PieceType::Knight as u8 | PieceColor::Black as u8);
assert_eq!(field.get_pos(boardloc!("c8")), PieceType::Bishop as u8 | PieceColor::Black as u8);
assert_eq!(field.get_pos(boardloc!("d8")), PieceType::Queen as u8 | PieceColor::Black as u8);
assert_eq!(field.get_pos(boardloc!("e8")), PieceType::King as u8 | PieceColor::Black as u8);
assert_eq!(field.get_pos(boardloc!("f8")), PieceType::Bishop as u8 | PieceColor::Black as u8);
assert_eq!(field.get_pos(boardloc!("g8")), PieceType::Knight as u8 | PieceColor::Black as u8);
assert_eq!(field.get_pos(boardloc!("h8")), PieceType::Rook as u8 | PieceColor::Black as u8);
}
}

189
bamboo/src/boardfield.rs Normal file
View File

@ -0,0 +1,189 @@
// Bamboo, a NNUE chess engine written in Rust.
// Copyright (C) 2023 c0repwn3r
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//! Operations for working with a packed square-wise representation of a chessboard.
use crate::boardloc;
use crate::piece::{PieceColor, PieceType};
/// A Boardfield is a packed, square-wise representation of a chessboard. It **does not** include any extra metadata such as castling rights.
pub type Boardfield = [u8; 32];
/// A trait to contain the operations available on a `Boardfield`
pub trait BoardfieldOps {
/// Create a new, entirely empty `Boardfield`.
fn new() -> Self where Self: Sized;
/// Create a new `Boardfield` from the standard chess starting position.
fn startpos() -> Self where Self: Sized;
/// Get the piece value stored at the provided boardloc.
fn get_pos(&self, boardloc: isize) -> u8;
/// Set the piece stored at the provided boardloc to the given piece value.
fn set_pos(&mut self, boardloc: isize, piece: u8);
/// Get the entire boardfield as a 32-length bytearray.
fn get_field(&self) -> [u8; 32];
}
impl BoardfieldOps for Boardfield {
fn new() -> Self where Self: Sized {
[0u8; 32]
}
fn startpos() -> Self where Self: Sized {
let mut field = Self::new();
// a1-h1 (RNBQKBNR)
field.set_pos(boardloc!("a1"), PieceColor::White as u8 | PieceType::Rook as u8);
field.set_pos(boardloc!("b1"), PieceColor::White as u8 | PieceType::Knight as u8);
field.set_pos(boardloc!("c1"), PieceColor::White as u8 | PieceType::Bishop as u8);
field.set_pos(boardloc!("d1"), PieceColor::White as u8 | PieceType::Queen as u8);
field.set_pos(boardloc!("e1"), PieceColor::White as u8 | PieceType::King as u8);
field.set_pos(boardloc!("f1"), PieceColor::White as u8 | PieceType::Bishop as u8);
field.set_pos(boardloc!("g1"), PieceColor::White as u8 | PieceType::Knight as u8);
field.set_pos(boardloc!("h1"), PieceColor::White as u8 | PieceType::Rook as u8);
// a2-h2 (PPPPPPPP)
field.set_pos(boardloc!("a2"), PieceColor::White as u8 | PieceType::Pawn as u8);
field.set_pos(boardloc!("b2"), PieceColor::White as u8 | PieceType::Pawn as u8);
field.set_pos(boardloc!("c2"), PieceColor::White as u8 | PieceType::Pawn as u8);
field.set_pos(boardloc!("d2"), PieceColor::White as u8 | PieceType::Pawn as u8);
field.set_pos(boardloc!("e2"), PieceColor::White as u8 | PieceType::Pawn as u8);
field.set_pos(boardloc!("f2"), PieceColor::White as u8 | PieceType::Pawn as u8);
field.set_pos(boardloc!("g2"), PieceColor::White as u8 | PieceType::Pawn as u8);
field.set_pos(boardloc!("h2"), PieceColor::White as u8 | PieceType::Pawn as u8);
// a7-h7 (pppppppp)
field.set_pos(boardloc!("a7"), PieceColor::Black as u8 | PieceType::Pawn as u8);
field.set_pos(boardloc!("b7"), PieceColor::Black as u8 | PieceType::Pawn as u8);
field.set_pos(boardloc!("c7"), PieceColor::Black as u8 | PieceType::Pawn as u8);
field.set_pos(boardloc!("d7"), PieceColor::Black as u8 | PieceType::Pawn as u8);
field.set_pos(boardloc!("e7"), PieceColor::Black as u8 | PieceType::Pawn as u8);
field.set_pos(boardloc!("f7"), PieceColor::Black as u8 | PieceType::Pawn as u8);
field.set_pos(boardloc!("g7"), PieceColor::Black as u8 | PieceType::Pawn as u8);
field.set_pos(boardloc!("h7"), PieceColor::Black as u8 | PieceType::Pawn as u8);
// a8-h8 (RNBQKBNR)
field.set_pos(boardloc!("a8"), PieceColor::Black as u8 | PieceType::Rook as u8);
field.set_pos(boardloc!("b8"), PieceColor::Black as u8 | PieceType::Knight as u8);
field.set_pos(boardloc!("c8"), PieceColor::Black as u8 | PieceType::Bishop as u8);
field.set_pos(boardloc!("d8"), PieceColor::Black as u8 | PieceType::Queen as u8);
field.set_pos(boardloc!("e8"), PieceColor::Black as u8 | PieceType::King as u8);
field.set_pos(boardloc!("f8"), PieceColor::Black as u8 | PieceType::Bishop as u8);
field.set_pos(boardloc!("g8"), PieceColor::Black as u8 | PieceType::Knight as u8);
field.set_pos(boardloc!("h8"), PieceColor::Black as u8 | PieceType::Rook as u8);
field
}
#[allow(clippy::cast_sign_loss)]
fn get_pos(&self, boardloc: isize) -> u8 {
// bf1: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
// bf2: 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
assert!(boardloc <= 63, "boardloc out of range");
assert!(boardloc >= 0, "boardloc out of range");
let field = self[(boardloc / 2) as usize];
let shift = 4 * (boardloc % 2);
(field & (0b1111 << shift)) >> shift
}
#[allow(clippy::cast_sign_loss)]
fn set_pos(&mut self, boardloc: isize, piece: u8) {
assert!(boardloc <= 63, "boardloc out of range {boardloc}");
assert!(boardloc >= 0, "boardloc out of range {boardloc}");
let field = self[(boardloc / 2) as usize];
let shift = 4 * (boardloc % 2);
// clear out the field
let bf_cleared = field & !(0b1111 << shift);
// then shift over the actual piece data
let piece_shifted = piece << shift;
// then OR them together
let bf_new = bf_cleared | piece_shifted;
self[(boardloc / 2) as usize] = bf_new;
}
fn get_field(&self) -> [u8; 32] {
*self
}
}
#[cfg(test)]
mod tests {
use crate::boardfield::{Boardfield, BoardfieldOps};
use crate::boardloc;
use crate::piece::{PieceColor, PieceType};
#[test]
#[should_panic]
fn get_out_of_bounds() {
let field = Boardfield::startpos();
field.get_pos(64);
}
#[test]
#[should_panic]
fn set_out_of_bounds() {
let mut field = Boardfield::startpos();
field.set_pos(64, 0u8);
}
#[test]
#[allow(clippy::cognitive_complexity)]
fn bitfield_board() {
let field = Boardfield::startpos();
assert_eq!(field.get_pos(boardloc!("a1")), PieceType::Rook as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(boardloc!("b1")), PieceType::Knight as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(boardloc!("c1")), PieceType::Bishop as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(boardloc!("d1")), PieceType::Queen as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(boardloc!("e1")), PieceType::King as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(boardloc!("f1")), PieceType::Bishop as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(boardloc!("g1")), PieceType::Knight as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(boardloc!("h1")), PieceType::Rook as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(boardloc!("a2")), PieceType::Pawn as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(boardloc!("b2")), PieceType::Pawn as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(boardloc!("c2")), PieceType::Pawn as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(boardloc!("d2")), PieceType::Pawn as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(boardloc!("e2")), PieceType::Pawn as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(boardloc!("f2")), PieceType::Pawn as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(boardloc!("g2")), PieceType::Pawn as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(boardloc!("h2")), PieceType::Pawn as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(boardloc!("a7")), PieceType::Pawn as u8 | PieceColor::Black as u8);
assert_eq!(field.get_pos(boardloc!("b7")), PieceType::Pawn as u8 | PieceColor::Black as u8);
assert_eq!(field.get_pos(boardloc!("c7")), PieceType::Pawn as u8 | PieceColor::Black as u8);
assert_eq!(field.get_pos(boardloc!("d7")), PieceType::Pawn as u8 | PieceColor::Black as u8);
assert_eq!(field.get_pos(boardloc!("e7")), PieceType::Pawn as u8 | PieceColor::Black as u8);
assert_eq!(field.get_pos(boardloc!("f7")), PieceType::Pawn as u8 | PieceColor::Black as u8);
assert_eq!(field.get_pos(boardloc!("g7")), PieceType::Pawn as u8 | PieceColor::Black as u8);
assert_eq!(field.get_pos(boardloc!("h7")), PieceType::Pawn as u8 | PieceColor::Black as u8);
assert_eq!(field.get_pos(boardloc!("a8")), PieceType::Rook as u8 | PieceColor::Black as u8);
assert_eq!(field.get_pos(boardloc!("b8")), PieceType::Knight as u8 | PieceColor::Black as u8);
assert_eq!(field.get_pos(boardloc!("c8")), PieceType::Bishop as u8 | PieceColor::Black as u8);
assert_eq!(field.get_pos(boardloc!("d8")), PieceType::Queen as u8 | PieceColor::Black as u8);
assert_eq!(field.get_pos(boardloc!("e8")), PieceType::King as u8 | PieceColor::Black as u8);
assert_eq!(field.get_pos(boardloc!("f8")), PieceType::Bishop as u8 | PieceColor::Black as u8);
assert_eq!(field.get_pos(boardloc!("g8")), PieceType::Knight as u8 | PieceColor::Black as u8);
assert_eq!(field.get_pos(boardloc!("h8")), PieceType::Rook as u8 | PieceColor::Black as u8);
}
}

122
bamboo/src/error.rs Normal file
View File

@ -0,0 +1,122 @@
// Bamboo, a NNUE chess engine written in Rust.
// Copyright (C) 2023 c0repwn3r
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//! Module to contain the various types of errors used by Bamboo.
use std::error::Error;
use std::fmt::{Display, Formatter};
use std::num::ParseIntError;
#[derive(Debug)]
/// An error type to represent the possible errors while parsing a FEN string
pub enum FENParseError {
/// A FEN string is expected to have six space-delimited components, but there were less or more than 6 components provided.
InvalidNumberOfComponents {
/// How many components were actually found in the string
got: isize
},
/// The Player To Move field should either be a `w`, indicating white to move, or `b`, indicating black to move, but neither were found.
InvalidPlayerToMove {
/// The actual Player To Move field found in the FEN string.
got: String
},
/// An error occured parsing the en passant target square.
EnPassantTargetParseError {
/// The actual error that occured
e: AlgebraicNotationError
},
/// An error occured parsing the fullmove or halfmove color.
InvalidMoveCounter {
/// The parsing error that occured
e: ParseIntError
},
/// While parsing the piece data, an unexpected character was found
InvalidPieceCharacter {
/// The unexpected character that was found
got: char
},
/// Chess boards are 8x8 but this FEN string attempted to place a piece outside of the board.
CannotSkipToOutsideOfBoard {
/// The skip value that was found
got: isize,
/// The location that skip value would place a piece at
which_is: isize
},
}
impl Error for FENParseError {}
impl Display for FENParseError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::InvalidNumberOfComponents { got } => write!(f, "Invalid number of components: got {got}, expected 6"),
Self::InvalidPlayerToMove { got } => write!(f, "Invalid player to move: expected one of `wb`, got `{got}`"),
Self::EnPassantTargetParseError { e } => write!(f, "Error parsing en passant target: {e}"),
Self::InvalidMoveCounter { e } => write!(f, "Invalid move counter: {e}"),
Self::InvalidPieceCharacter { got } => write!(f, "Invalid piece character: expected one of `rnbqkpRNBQKP`, got `{got}`"),
Self::CannotSkipToOutsideOfBoard { got, which_is } => write!(f, "Cannot skip files to outside the board (tried to skip {got} positions, which would be at position {which_is})")
}
}
}
#[derive(Debug)]
/// Represents an error that occured parsing an algebraic notation coordinate.
pub enum AlgebraicNotationError {
/// An invalid rank (1-8) was encountered
InvalidRank {
/// The rank that was provided
got: String
},
/// An invalid file (a-h) was encountered
InvalidFile {
/// The file that was provided
got: String
},
/// Algebraic notation is two characters long, but this string was not two characters long
InvalidLength {
/// The length of the provided string
got: isize
}
}
impl Error for AlgebraicNotationError {}
impl Display for AlgebraicNotationError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::InvalidRank { got } => write!(f, "Invalid rank: expected one of `12345678`, got `{got}`"),
Self::InvalidFile { got } => write!(f, "Invalid file: expected one of `abcdefgh`, got `{got}`"),
Self::InvalidLength { got } => write!(f, "Invalid length, expected 2, got `{got}`")
}
}
}
#[derive(Debug)]
/// Represents an error that occured making or unmaking an error.
pub enum MoveApplicationError {
}
impl Error for MoveApplicationError {}
impl Display for MoveApplicationError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
return Ok(());
/*match self {
}*/
}
}

38
bamboo/src/lib.rs Normal file
View File

@ -0,0 +1,38 @@
// Bamboo, a NNUE chess engine written in Rust.
// Copyright (C) 2023 c0repwn3r
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//! # Bamboo
//! Bamboo is a pure-rust chess engine that uses a machine learning model to provide NNUE-like board evaluation.
#![warn(clippy::pedantic)]
#![warn(clippy::nursery)]
#![deny(missing_docs)]
#![deny(clippy::unwrap_used)]
#![deny(clippy::expect_used)]
#![deny(clippy::missing_errors_doc)]
#![deny(clippy::missing_panics_doc)]
#![deny(clippy::missing_safety_doc)]
#![allow(clippy::must_use_candidate)]
#![allow(clippy::too_many_lines)]
#![allow(clippy::module_name_repetitions)]
pub mod boardfield;
pub mod piece;
pub mod board;
#[macro_use]
pub mod utils;
pub mod nn;
pub mod error;
pub mod moves;

86
bamboo/src/main.rs Normal file
View File

@ -0,0 +1,86 @@
// Bamboo, a NNUE chess engine written in Rust.
// Copyright (C) 2023 c0repwn3r
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use std::{io};
use std::sync::{Arc};
use crate::uci::{uci_handle_command, UCIState};
use spin::Mutex;
use crate::board::Board;
#[cfg(not(tarpaulin_include))] // UCI parse engine is not tested with tarpaulin, outer test harness is planned
pub mod uci;
pub mod boardfield;
pub mod piece;
pub mod board;
#[macro_use]
pub mod utils;
pub mod nn;
pub mod error;
pub const ENGINE_NAME: &str = "Bamboo";
pub const ENGINE_VERSION: &str = "1.0";
pub const ENGINE_AUTHOR: &str = "c0repwn3r";
#[cfg(not(tarpaulin_include))]
fn main() {
if std::env::args().len() > 1 {
let args = std::env::args().collect::<Vec<String>>();
if args[1] == "--serBoard" && args.len() != 3 {
println!("usage: bamboo [--serBoard <fenString>]");
std::process::exit(1);
} else if args[1] == "--serBoard" {
match Board::from_fen(args[2].as_str()) {
Ok(b) => {
println!("{}", hex::encode(b.to_board_id()));
std::process::exit(0);
},
Err(e) => {
println!("Error decoding FEN string: {}", e);
std::process::exit(1);
}
}
} else {
println!("usage: bamboo [--serBoard <fenString>]");
std::process::exit(1);
}
}
println!("{} {} by {}", ENGINE_NAME, ENGINE_VERSION, ENGINE_AUTHOR);
let uci_state = UCIState::new();
let uci_lock = Arc::new(Mutex::new(uci_state));
loop {
let mut cmdbuf = String::new();
match io::stdin().read_line(&mut cmdbuf) {
Ok(_) => (),
Err(e) => {
println!("fatal error reading standard input: {}", e);
return;
}
}
let resp = match uci_handle_command(uci_lock.clone(), cmdbuf.clone()) {
Ok(response) => response,
Err(e) => {
format!("error handling uci command: {}", e)
}
};
print!("{}", resp);
}
}

73
bamboo/src/moves.rs Normal file
View File

@ -0,0 +1,73 @@
// Bamboo, a NNUE chess engine written in Rust.
// Copyright (C) 2023 c0repwn3r
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//! Traits and functions to make and unmake moves on a chessboard.
use crate::error::MoveApplicationError;
use crate::piece::{PieceColor, PieceOnBoard, PieceType};
/// Represents a move on a chessboard.
pub enum Move {
/// Represents a linear move, from A to B on the chessboard. No capture.
Linear {
/// The boardloc the piece is coming from.
from: isize,
/// The boardloc the piece is going to.
to: isize,
/// The `PieceOnBoard` struct of the piece BEFORE the move.
piece: PieceOnBoard
},
/// Represents a linear from, move A to B on the chessboard, and capturing a piece.
LinearCapture {
/// The boardloc the piece is coming from.
from: isize,
/// The boardloc the piece is going to.
to: isize,
/// The `PieceOnBoard` struct of the piece BEFORE the move.
piece: PieceOnBoard,
/// The `PieceOnBoard` struct of the piece being captured, BEFORE the move.
capturing: PieceOnBoard
},
/// Represents a castle, either white or black, kingside or queenside.
Castle {
/// The player that is performing the castle
player: PieceColor,
/// Which direction that player is castling, kingside or queenside.
queenside: bool
},
/// Represents a pawn promotion.
Promotion {
/// The pawn that is being promoted, BEFORE the move
piece: PieceOnBoard,
/// The location of the pawn, BEFORE the move
from: isize,
/// The location of the pawn, AFTER the move
to: isize,
/// The type of piece the pawn is promoting to.
becoming: PieceType
}
}
/// A trait to provide the operations of making and unmaking moves.
pub trait MoveApplicator {
/// Perform the given move on the chessboard.
/// # Errors
/// This function will error if any error occurs while applying the move.
fn make_move(&mut self, make: Move) -> Result<(), MoveApplicationError>;
/// Undo the given move on the chessboard. This will probably break if that move wasn't the last move made.
/// # Errors
/// This function will error if any error occurs while unmaking the move.
fn unmake_move(&mut self, unmake: Move) -> Result<(), MoveApplicationError>;
}

24
bamboo/src/nn/mod.rs Normal file
View File

@ -0,0 +1,24 @@
// Bamboo, a NNUE chess engine written in Rust.
// Copyright (C) 2023 c0repwn3r
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//! Functions, structs, traits and macros for working with `BambooNN`.
#[derive(Default, Debug)]
/// A feed-forward machine learning model used to evaluate board positions
pub struct BNNModel {
}
// Model architecture

222
bamboo/src/piece.rs Normal file
View File

@ -0,0 +1,222 @@
// Bamboo, a NNUE chess engine written in Rust.
// Copyright (C) 2023 c0repwn3r
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//! Structs and methods for working with chess pieces.
use crate::piece::PieceType::{Bishop, King, Knight, Pawn, Queen, Rook};
#[derive(Debug, Ord, PartialOrd, Eq, PartialEq, Clone)]
/// Represents a piece on the chessboard. Used for the piece-based evaluation in `Board`.
pub struct PieceOnBoard {
/// The boardloc this piece is at
pub loc: isize,
/// The value of the piece
pub value: Piece
}
impl PieceOnBoard {
const fn empty(loc: isize) -> Self {
Self {
loc,
value: 0u8
}
}
const fn new(loc: isize, value: Piece) -> Self {
Self {
loc,
value
}
}
}
#[derive(Debug, Ord, PartialOrd, Eq, PartialEq, Clone, Copy)]
#[repr(u8)]
/// The type of a chess piece, used for `u8`/four-bit piece representations
pub enum PieceType {
/// Represents a pawn
Pawn = 1,
/// Represents a knight
Knight = 2,
/// Represents a bishop
Bishop = 3,
/// Represents a rook
Rook = 4,
/// Represents a queen
Queen = 5,
/// Represents a king
King = 6
}
#[derive(Debug, Ord, PartialOrd, Eq, PartialEq, Clone, Copy)]
#[repr(u8)]
/// Represents the color of a piece, used for `u8`/four-bit piece representations
pub enum PieceColor {
/// Represents a white piece
White = 8,
/// Represents a black piece
Black = 0
}
impl PieceColor {
/// Get the opposite of this color, e.g. for white return black and vice versa.
#[must_use]
pub const fn invert(&self) -> Self {
match self {
Self::White => Self::Black,
Self::Black => Self::White
}
}
}
/// Represents a four-bit packed chess piece.
pub type Piece = u8;
/// A trait for the operations that can be done on a `Piece`
pub trait PieceOps {
/// Determines if this piece is white. Inverse of `is_black`
fn is_white(value: u8) -> bool;
/// Determines if this piece is black. Inverse of `is_black`
fn is_black(value: u8) -> bool;
/// Get the `PieceType` of this piece. This returns an option, as a Piece can be any `u8`, but not all of them are actual piece types.
fn get_type(value: u8) -> Option<PieceType>;
/// Gets the color of this piece. This effectively just checks if the fourth bit is set, and as such does not return an option.
fn get_color(value: u8) -> PieceColor;
}
impl PieceOps for Piece {
fn is_white(value: u8) -> bool {
if value < 8 {
false
} else {
value & PieceColor::White as Self != 0
}
}
fn is_black(value: u8) -> bool {
!Self::is_white(value)
}
fn get_type(value: u8) -> Option<PieceType> {
match value & 0b111 {
1 => Some(Pawn),
2 => Some(Knight),
3 => Some(Bishop),
4 => Some(Rook),
5 => Some(Queen),
6 => Some(King),
_ => None
}
}
fn get_color(value: u8) -> PieceColor {
if Self::is_white(value) {
PieceColor::White
} else {
PieceColor::Black
}
}
}
#[cfg(test)]
#[allow(clippy::unwrap_used)]
mod piece_tests {
use crate::piece::{Piece, PieceColor, PieceOnBoard, PieceOps, PieceType};
#[test]
fn piece_constructor() {
assert_eq!(PieceOnBoard::empty(0), PieceOnBoard {
loc: 0,
value: 0,
});
}
#[test]
fn piece_serialization() {
assert_eq!(PieceOnBoard::new(0, 0), PieceOnBoard {
loc: 0,
value: 0,
});
assert_eq!(PieceType::Pawn as u8 | PieceColor::White as u8, 0b1001);
assert_eq!(PieceType::Pawn as u8 | PieceColor::Black as u8, 0b0001);
assert_eq!(PieceType::Knight as u8 | PieceColor::White as u8, 0b1010);
assert_eq!(PieceType::Knight as u8 | PieceColor::Black as u8, 0b0010);
assert_eq!(PieceType::Bishop as u8 | PieceColor::White as u8, 0b1011);
assert_eq!(PieceType::Bishop as u8 | PieceColor::Black as u8, 0b0011);
assert_eq!(PieceType::Rook as u8 | PieceColor::White as u8, 0b1100);
assert_eq!(PieceType::Rook as u8 | PieceColor::Black as u8, 0b0100);
assert_eq!(PieceType::Queen as u8 | PieceColor::White as u8, 0b1101);
assert_eq!(PieceType::Queen as u8 | PieceColor::Black as u8, 0b0101);
assert_eq!(PieceType::King as u8 | PieceColor::White as u8, 0b1110);
assert_eq!(PieceType::King as u8 | PieceColor::Black as u8, 0b0110);
}
#[test]
pub fn piece_deserialization_test() {
assert_eq!(Piece::get_type(PieceType::King as u8).unwrap(), PieceType::King);
assert_eq!(Piece::get_type(PieceType::Queen as u8).unwrap(), PieceType::Queen);
assert_eq!(Piece::get_type(PieceType::Rook as u8).unwrap(), PieceType::Rook);
assert_eq!(Piece::get_type(PieceType::Bishop as u8).unwrap(), PieceType::Bishop);
assert_eq!(Piece::get_type(PieceType::Knight as u8).unwrap(), PieceType::Knight);
assert_eq!(Piece::get_type(PieceType::Pawn as u8).unwrap(), PieceType::Pawn);
assert_eq!(Piece::get_type(191u8), None);
assert_eq!(Piece::get_color(PieceColor::Black as u8), PieceColor::Black);
assert_eq!(Piece::get_color(PieceColor::White as u8), PieceColor::White);
}
#[test]
#[allow(clippy::cognitive_complexity)]
fn piece_color_checks() {
assert!(!Piece::is_white(PieceType::Pawn as u8 | PieceColor::Black as u8));
assert!(Piece::is_white(PieceType::Pawn as u8 | PieceColor::White as u8));
assert!(Piece::is_black(PieceType::Pawn as u8 | PieceColor::Black as u8));
assert!(!Piece::is_black(PieceType::Pawn as u8 | PieceColor::White as u8));
assert!(!Piece::is_white(PieceType::Knight as u8 | PieceColor::Black as u8));
assert!(Piece::is_white(PieceType::Knight as u8 | PieceColor::White as u8));
assert!(Piece::is_black(PieceType::Knight as u8 | PieceColor::Black as u8));
assert!(!Piece::is_black(PieceType::Knight as u8 | PieceColor::White as u8));
assert!(!Piece::is_white(PieceType::Bishop as u8 | PieceColor::Black as u8));
assert!(Piece::is_white(PieceType::Bishop as u8 | PieceColor::White as u8));
assert!(Piece::is_black(PieceType::Bishop as u8 | PieceColor::Black as u8));
assert!(!Piece::is_black(PieceType::Bishop as u8 | PieceColor::White as u8));
assert!(!Piece::is_white(PieceType::Rook as u8 | PieceColor::Black as u8));
assert!(Piece::is_white(PieceType::Rook as u8 | PieceColor::White as u8));
assert!(Piece::is_black(PieceType::Rook as u8 | PieceColor::Black as u8));
assert!(!Piece::is_black(PieceType::Rook as u8 | PieceColor::White as u8));
assert!(!Piece::is_white(PieceType::Queen as u8 | PieceColor::Black as u8));
assert!(Piece::is_white(PieceType::Queen as u8 | PieceColor::White as u8));
assert!(Piece::is_black(PieceType::Queen as u8 | PieceColor::Black as u8));
assert!(!Piece::is_black(PieceType::Queen as u8 | PieceColor::White as u8));
assert!(!Piece::is_white(PieceType::King as u8 | PieceColor::Black as u8));
assert!(Piece::is_white(PieceType::King as u8 | PieceColor::White as u8));
assert!(Piece::is_black(PieceType::King as u8 | PieceColor::Black as u8));
assert!(!Piece::is_black(PieceType::King as u8 | PieceColor::White as u8));
assert_eq!(PieceColor::White.invert(), PieceColor::Black);
assert_eq!(PieceColor::Black.invert(), PieceColor::White);
}
}

View File

@ -1,13 +1,30 @@
// Bamboo, a NNUE chess engine written in Rust.
// Copyright (C) 2023 c0repwn3r
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use std::error::Error; use std::error::Error;
use crate::{ENGINE_AUTHOR, ENGINE_NAME, ENGINE_VERSION}; use crate::{ENGINE_AUTHOR, ENGINE_NAME, ENGINE_VERSION};
use std::fmt::Write; use std::fmt::Write;
use std::sync::{Arc}; use std::sync::{Arc};
use spin::Mutex; use spin::Mutex;
use crate::nn::BNNModel;
#[derive(Default)] #[derive(Default)]
pub struct UCIState { pub struct UCIState {
debug: bool, debug: bool,
is_blocking: bool is_blocking: bool,
nn_model: BNNModel
} }
impl UCIState { impl UCIState {

114
bamboo/src/utils.rs Normal file
View File

@ -0,0 +1,114 @@
// Bamboo, a NNUE chess engine written in Rust.
// Copyright (C) 2023 c0repwn3r
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//! Provides various utility functions and macros
use crate::error::AlgebraicNotationError;
/// Convert an algebraic notation, such as `a1`, to the corresponding boardloc.
/// # Errors
/// This function will return an error if the algebraic string is invalid.
#[allow(clippy::cast_sign_loss)]
#[allow(clippy::cast_possible_wrap)]
pub fn algebraic_to_boardloc(algebraic: &str) -> Result<isize, AlgebraicNotationError> {
if algebraic.chars().count() != 2 {
return Err(AlgebraicNotationError::InvalidLength { got: algebraic.chars().count() as isize })
}
let chars: Vec<char> = algebraic.chars().collect();
let file_char = chars[0];
let rank_char = chars[1];
if (file_char as u8) < b'a' || (file_char as u8) > b'h' {
return Err(AlgebraicNotationError::InvalidFile { got: file_char.to_string() })
}
if (rank_char as u8) < b'1' || (rank_char as u8) > b'8' {
return Err(AlgebraicNotationError::InvalidRank { got: rank_char.to_string() })
}
let file = (file_char as u8 - 97) as isize;
let rank = (rank_char as u8 - 49) as isize;
Ok(rank + file * 8)
}
/// An array for converting boardloc to algebraic notation. Do not use this directly, use `boardloc_to_algebraic`.
pub const BOARDLOC_TO_ALG: [&str; 64] = ["a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8", "c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8", "e1", "e2", "e3", "e4", "e5", "e6", "e7", "e8", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "g1", "g2", "g3", "g4", "g5", "g6", "g7", "g8", "h1", "h2", "h3", "h4", "h5", "h6", "h7", "h8"];
/// Convert a 0-63 boardloc into an algebraic notation string.
/// # Panics
/// This function will **panic** if you provide an invalid boardloc. Please bounds check it first.
#[allow(clippy::cast_sign_loss)]
#[allow(clippy::cast_possible_wrap)]
pub const fn boardloc_to_algebraic<'a>(boardloc: isize) -> &'a str {
BOARDLOC_TO_ALG[boardloc as usize]
}
/// A macro to shorten `algebraic_to_boardloc`. This will **panic** if you provide an invalid algebraic notation.
#[macro_export]
macro_rules! boardloc {
($alg:expr) => {
$crate::utils::algebraic_to_boardloc($alg).unwrap()
};
}
/// A macro to shorten `boardloc_to_algebraic`. This will **panic** if you provide an invalid (out of boudns) boardloc.
#[macro_export]
macro_rules! algebraic {
($boardloc:expr) => {
$crate::utils::BOARDLOC_TO_ALG[$boardloc as usize]
}
}
#[cfg(test)]
#[allow(clippy::unwrap_used)]
mod tests {
use crate::utils::{algebraic_to_boardloc, boardloc_to_algebraic};
#[test]
fn boardloc_testing() {
for i in 0..64 {
assert_eq!(algebraic_to_boardloc(boardloc_to_algebraic(i)).unwrap(), i);
}
}
#[test]
#[should_panic]
fn boardloc_invalid_file() {
if let Err(e) = algebraic_to_boardloc("j8") {
println!("{e}");
panic!();
}
}
#[test]
#[should_panic]
fn boardloc_invalid_length() {
if let Err(e) = algebraic_to_boardloc("jsdf8") {
println!("{e}");
panic!();
}
}
#[test]
#[should_panic]
fn boardloc_invalid_rank() {
if let Err(e) = algebraic_to_boardloc("a9") {
println!("{e}");
panic!();
}
}
}

7
poceae/Cargo.lock generated Normal file
View File

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "poceae"
version = "0.1.0"

20
poceae/Cargo.toml Normal file
View File

@ -0,0 +1,20 @@
[package]
name = "poceae"
description = "Generate and train models for BambooNN."
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rand = "0.8.5"
uciengine = "0.1.33"
tokio = "1.25.0"
simple_logger = "4.0.0"
log = "0.4.17"
neuroflow = "0.1.3"
clap = { version = "4.1.4", features = ["derive"] }
indicatif = "0.17.3"
itertools = "0.10.5"
bitstring = "0.1.2"
bamboo = { version = "0.1.0", path = "../bamboo" }

88
poceae/src/main.rs Normal file
View File

@ -0,0 +1,88 @@
// Bamboo, a NNUE chess engine written in Rust.
// Copyright (C) 2023 c0repwn3r
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use std::path::PathBuf;
use clap::{Parser, Subcommand};
#[derive(Parser)]
#[command(author = "c0repwn3r", version, about, long_about = None)]
struct Cli {
#[command(subcommand)]
command: Commands
}
#[derive(Subcommand)]
enum Commands {
/// Create a .csv dataset for use with train-model
BuildDataset {
#[arg(short, long, value_name = "FILE")]
/// The .csv file to output the dataset to. This file will be **VERY LARGE**, so make sure it is in a place that can handle upwards of 10 GB of data
output_file: PathBuf,
#[arg(short, long, value_name = "ENGINE_BINARY")]
/// The path to a UCI-compatible chess engine, for example /usr/bin/stockfish
uci_engine_binary: PathBuf,
#[arg(short, long, default_value = "500000")]
/// The amount of dataset entries to generate. By default, set to 500,000
dataset_size: usize,
#[arg(short, long, default_value = "20")]
/// The search depth to be used to evaluate positions, sent directly to the UCI engine, set to 20 by default
search_depth: i32,
#[arg(short, long, default_value = "4")]
/// The amount of threads to be used to search each position, set to 4 by default
threads: i32,
#[arg(short, long, default_value = "128")]
/// The amount of memory to be allocated by the UCI engine, in MiB, set to 128 by default
allocate: i32
},
/// Given a .csv dataset, train the model and output a trained BNNF file.
TrainModel {
#[arg(short, long, value_name = "DATA_FILE")]
/// The path to the .csv dataset file, as created by build-dataset
data_file: PathBuf,
#[arg(short, long, default_value = "0.01")]
/// The rate to perform training at. By default, set to 0.01.
/// Larger values will result in faster training but less accurate results.
training_rate: f32,
#[arg(short, long, default_value = "50000")]
/// The amount of training iterations to perform. By default, set to 50,000.
/// Larger values will result in more accurate training but will eventually degrade model performance. Fine-tune to get best performance.
iterations: usize,
#[arg(short, long, value_name = "MODEL_FILE")]
/// The .bnnf file to output the trained model to. This file *may* become large, but will not always be large.
output_file: PathBuf
}
}
#[tokio::main]
async fn main() {
let cli = Cli::parse();
match cli.command {
Commands::BuildDataset { output_file, uci_engine_binary, dataset_size, search_depth, threads, allocate } => {
},
Commands::TrainModel { data_file, training_rate, iterations, output_file } => {
}
}
}

1
positions.csv Normal file
View File

@ -0,0 +1 @@
1,1,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,1,1,1,0,1,1,0,1,0,0,0,0,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,1,1,0,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,1,0,0,1,0,0,0,1,0,0,1,0,0,0,1,1,0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,0,0,1,0,1,0,1,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,-,0,-2801
1 1 1 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 1 1 1 0 1 1 0 1 0 0 0 0 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 1 1 0 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 0 1 1 0 0 0 0 0 1 1 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 - 0 -2801

View File

@ -1,178 +0,0 @@
// Bitpacked board:
// One piece can be represented with 4 bits. Therefore, we can fit two pieces in one byte:
// 0b0110_1110 -
// | \
// Black king \- White king
// As there are 64 spaces on the board, we can pack the board into a 256-bit integer, and we use that as the index for transposition tables and such.
// Boards are stored as two 128-bit bitfields, to make accessing them as efficient as possible.
/*
a b c d e f g h
8 56 57 58 59 60 61 62 63 8 -+
7 48 49 50 51 52 53 54 55 7 |- bf2
6 40 41 42 43 44 45 46 47 6 |
5 32 33 34 35 36 37 38 39 5 -+
4 24 25 26 27 28 29 30 31 4 -+
3 16 17 18 19 20 21 22 23 3 |
2 8 9 10 11 12 13 14 15 2 |- bf1
1 0 1 2 3 4 5 6 7 1 -+
a b c d e f g h
*/
use crate::piece::{PieceColor, PieceType};
type Boardfield = [u8; 32];
pub trait BoardfieldOps {
fn new() -> Self where Self: Sized;
fn startpos() -> Self where Self: Sized;
fn get_pos(&self, boardloc: usize) -> u8;
fn set_pos(&mut self, boardloc: usize, piece: u8);
}
impl BoardfieldOps for Boardfield {
fn new() -> Self where Self: Sized {
[0u8; 32]
}
fn startpos() -> Self where Self: Sized {
let mut field = Self::new();
// a1-h1 (RNBQKBNR)
field.set_pos(0, PieceColor::White as u8 | PieceType::Rook as u8);
field.set_pos(1, PieceColor::White as u8 | PieceType::Knight as u8);
field.set_pos(2, PieceColor::White as u8 | PieceType::Bishop as u8);
field.set_pos(3, PieceColor::White as u8 | PieceType::Queen as u8);
field.set_pos(4, PieceColor::White as u8 | PieceType::King as u8);
field.set_pos(5, PieceColor::White as u8 | PieceType::Bishop as u8);
field.set_pos(6, PieceColor::White as u8 | PieceType::Knight as u8);
field.set_pos(7, PieceColor::White as u8 | PieceType::Rook as u8);
// a2-h2 (PPPPPPPP)
field.set_pos(8, PieceColor::White as u8 | PieceType::Pawn as u8);
field.set_pos(9, PieceColor::White as u8 | PieceType::Pawn as u8);
field.set_pos(10, PieceColor::White as u8 | PieceType::Pawn as u8);
field.set_pos(11, PieceColor::White as u8 | PieceType::Pawn as u8);
field.set_pos(12, PieceColor::White as u8 | PieceType::Pawn as u8);
field.set_pos(13, PieceColor::White as u8 | PieceType::Pawn as u8);
field.set_pos(14, PieceColor::White as u8 | PieceType::Pawn as u8);
field.set_pos(15, PieceColor::White as u8 | PieceType::Pawn as u8);
// a7-h7 (pppppppp)
field.set_pos(48, PieceColor::Black as u8 | PieceType::Pawn as u8);
field.set_pos(49, PieceColor::Black as u8 | PieceType::Pawn as u8);
field.set_pos(50, PieceColor::Black as u8 | PieceType::Pawn as u8);
field.set_pos(51, PieceColor::Black as u8 | PieceType::Pawn as u8);
field.set_pos(52, PieceColor::Black as u8 | PieceType::Pawn as u8);
field.set_pos(53, PieceColor::Black as u8 | PieceType::Pawn as u8);
field.set_pos(54, PieceColor::Black as u8 | PieceType::Pawn as u8);
field.set_pos(55, PieceColor::Black as u8 | PieceType::Pawn as u8);
// a8-h8 (RNBQKBNR)
field.set_pos(56, PieceColor::Black as u8 | PieceType::Rook as u8);
field.set_pos(57, PieceColor::Black as u8 | PieceType::Knight as u8);
field.set_pos(58, PieceColor::Black as u8 | PieceType::Bishop as u8);
field.set_pos(59, PieceColor::Black as u8 | PieceType::Queen as u8);
field.set_pos(60, PieceColor::Black as u8 | PieceType::King as u8);
field.set_pos(61, PieceColor::Black as u8 | PieceType::Bishop as u8);
field.set_pos(62, PieceColor::Black as u8 | PieceType::Knight as u8);
field.set_pos(63, PieceColor::Black as u8 | PieceType::Rook as u8);
field
}
fn get_pos(&self, boardloc: usize) -> u8 {
// bf1: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
// bf2: 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
if boardloc > 63 {
panic!("boardloc out of range");
}
let field = self[boardloc / 2];
let shift = 4 * (boardloc % 2);
(field & (0b1111 << shift)) >> shift
}
fn set_pos(&mut self, boardloc: usize, piece: u8) {
if boardloc > 63 {
panic!("boardloc out of range");
}
let field = self[boardloc / 2];
let shift = 4 * (boardloc % 2);
// clear out the field
let bf_cleared = field & !(0b1111 << shift);
// then shift over the actual piece data
let piece_shifted = piece << shift;
// then OR them together
let bf_new = bf_cleared | piece_shifted;
self[boardloc / 2] = bf_new;
}
}
#[cfg(test)]
mod tests {
use crate::board::{Boardfield, BoardfieldOps};
use crate::piece::{PieceColor, PieceType};
#[test]
#[should_panic]
fn get_out_of_bounds() {
let field = Boardfield::startpos();
field.get_pos(64);
}
#[test]
#[should_panic]
fn set_out_of_bounds() {
let mut field = Boardfield::startpos();
field.set_pos(64, 0u8);
}
#[test]
fn bitfield_board() {
let field = Boardfield::startpos();
assert_eq!(field.get_pos(0), PieceType::Rook as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(1), PieceType::Knight as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(2), PieceType::Bishop as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(3), PieceType::Queen as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(4), PieceType::King as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(5), PieceType::Bishop as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(6), PieceType::Knight as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(7), PieceType::Rook as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(8), PieceType::Pawn as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(9), PieceType::Pawn as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(10), PieceType::Pawn as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(11), PieceType::Pawn as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(12), PieceType::Pawn as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(13), PieceType::Pawn as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(14), PieceType::Pawn as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(15), PieceType::Pawn as u8 | PieceColor::White as u8);
assert_eq!(field.get_pos(48), PieceType::Pawn as u8 | PieceColor::Black as u8);
assert_eq!(field.get_pos(49), PieceType::Pawn as u8 | PieceColor::Black as u8);
assert_eq!(field.get_pos(50), PieceType::Pawn as u8 | PieceColor::Black as u8);
assert_eq!(field.get_pos(51), PieceType::Pawn as u8 | PieceColor::Black as u8);
assert_eq!(field.get_pos(52), PieceType::Pawn as u8 | PieceColor::Black as u8);
assert_eq!(field.get_pos(53), PieceType::Pawn as u8 | PieceColor::Black as u8);
assert_eq!(field.get_pos(54), PieceType::Pawn as u8 | PieceColor::Black as u8);
assert_eq!(field.get_pos(55), PieceType::Pawn as u8 | PieceColor::Black as u8);
assert_eq!(field.get_pos(56), PieceType::Rook as u8 | PieceColor::Black as u8);
assert_eq!(field.get_pos(57), PieceType::Knight as u8 | PieceColor::Black as u8);
assert_eq!(field.get_pos(58), PieceType::Bishop as u8 | PieceColor::Black as u8);
assert_eq!(field.get_pos(59), PieceType::Queen as u8 | PieceColor::Black as u8);
assert_eq!(field.get_pos(60), PieceType::King as u8 | PieceColor::Black as u8);
assert_eq!(field.get_pos(61), PieceType::Bishop as u8 | PieceColor::Black as u8);
assert_eq!(field.get_pos(62), PieceType::Knight as u8 | PieceColor::Black as u8);
assert_eq!(field.get_pos(63), PieceType::Rook as u8 | PieceColor::Black as u8);
}
}

View File

@ -1,43 +0,0 @@
use std::{fs, io};
use std::path::Path;
use std::sync::{Arc};
use crate::uci::{uci_handle_command, UCIState};
use spin::Mutex;
#[cfg(not(tarpaulin_include))] // UCI parse engine is not tested with tarpaulin, outer test harness is planned
pub mod uci;
pub mod board;
pub mod piece;
pub const ENGINE_NAME: &str = "Bamboo";
pub const ENGINE_VERSION: &str = "1.0";
pub const ENGINE_AUTHOR: &str = "c0repwn3r";
#[cfg(not(tarpaulin_include))]
fn main() {
println!("{} {} by {}", ENGINE_NAME, ENGINE_VERSION, ENGINE_AUTHOR);
let mut uci_state = UCIState::new();
let mut uci_lock = Arc::new(Mutex::new(uci_state));
loop {
let mut cmdbuf = String::new();
match io::stdin().read_line(&mut cmdbuf) {
Ok(_) => (),
Err(e) => {
println!("fatal error reading standard input: {}", e);
return;
}
}
let resp = match uci_handle_command(uci_lock.clone(), cmdbuf.clone()) {
Ok(response) => response,
Err(e) => {
format!("error handling uci command: {}", e)
}
};
print!("{}", resp);
}
}

View File

@ -1,94 +0,0 @@
#[repr(u8)]
pub enum PieceType {
Pawn = 1,
Knight = 2,
Bishop = 3,
Rook = 4,
Queen = 5,
King = 6
}
#[repr(u8)]
pub enum PieceColor {
White = 8,
Black = 0
}
pub type Piece = u8;
pub trait PieceOps {
fn is_white(value: u8) -> bool;
fn is_black(value: u8) -> bool;
}
impl PieceOps for Piece {
fn is_white(value: u8) -> bool {
if value < 8 {
false
} else {
value & PieceColor::White as u8 != 0
}
}
fn is_black(value: u8) -> bool {
!Self::is_white(value)
}
}
#[cfg(test)]
mod piece_tests {
use crate::piece::{Piece, PieceColor, PieceOps, PieceType};
#[test]
fn piece_serialization() {
assert_eq!(PieceType::Pawn as u8 | PieceColor::White as u8, 0b1001);
assert_eq!(PieceType::Pawn as u8 | PieceColor::Black as u8, 0b0001);
assert_eq!(PieceType::Knight as u8 | PieceColor::White as u8, 0b1010);
assert_eq!(PieceType::Knight as u8 | PieceColor::Black as u8, 0b0010);
assert_eq!(PieceType::Bishop as u8 | PieceColor::White as u8, 0b1011);
assert_eq!(PieceType::Bishop as u8 | PieceColor::Black as u8, 0b0011);
assert_eq!(PieceType::Rook as u8 | PieceColor::White as u8, 0b1100);
assert_eq!(PieceType::Rook as u8 | PieceColor::Black as u8, 0b0100);
assert_eq!(PieceType::Queen as u8 | PieceColor::White as u8, 0b1101);
assert_eq!(PieceType::Queen as u8 | PieceColor::Black as u8, 0b0101);
assert_eq!(PieceType::King as u8 | PieceColor::White as u8, 0b1110);
assert_eq!(PieceType::King as u8 | PieceColor::Black as u8, 0b0110);
}
#[test]
fn piece_color_checks() {
assert!(!Piece::is_white(PieceType::Pawn as u8 | PieceColor::Black as u8));
assert!(Piece::is_white(PieceType::Pawn as u8 | PieceColor::White as u8));
assert!(Piece::is_black(PieceType::Pawn as u8 | PieceColor::Black as u8));
assert!(!Piece::is_black(PieceType::Pawn as u8 | PieceColor::White as u8));
assert!(!Piece::is_white(PieceType::Knight as u8 | PieceColor::Black as u8));
assert!(Piece::is_white(PieceType::Knight as u8 | PieceColor::White as u8));
assert!(Piece::is_black(PieceType::Knight as u8 | PieceColor::Black as u8));
assert!(!Piece::is_black(PieceType::Knight as u8 | PieceColor::White as u8));
assert!(!Piece::is_white(PieceType::Bishop as u8 | PieceColor::Black as u8));
assert!(Piece::is_white(PieceType::Bishop as u8 | PieceColor::White as u8));
assert!(Piece::is_black(PieceType::Bishop as u8 | PieceColor::Black as u8));
assert!(!Piece::is_black(PieceType::Bishop as u8 | PieceColor::White as u8));
assert!(!Piece::is_white(PieceType::Rook as u8 | PieceColor::Black as u8));
assert!(Piece::is_white(PieceType::Rook as u8 | PieceColor::White as u8));
assert!(Piece::is_black(PieceType::Rook as u8 | PieceColor::Black as u8));
assert!(!Piece::is_black(PieceType::Rook as u8 | PieceColor::White as u8));
assert!(!Piece::is_white(PieceType::Queen as u8 | PieceColor::Black as u8));
assert!(Piece::is_white(PieceType::Queen as u8 | PieceColor::White as u8));
assert!(Piece::is_black(PieceType::Queen as u8 | PieceColor::Black as u8));
assert!(!Piece::is_black(PieceType::Queen as u8 | PieceColor::White as u8));
assert!(!Piece::is_white(PieceType::King as u8 | PieceColor::Black as u8));
assert!(Piece::is_white(PieceType::King as u8 | PieceColor::White as u8));
assert!(Piece::is_black(PieceType::King as u8 | PieceColor::Black as u8));
assert!(!Piece::is_black(PieceType::King as u8 | PieceColor::White as u8));
}
}