commit a3e500ffc490bb890ff53ebcb13da8efb9f6ee20 Author: mehbark Date: Sun Mar 26 23:33:41 2023 -0400 i am a git main diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..94a9ed0 --- /dev/null +++ b/COPYING @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + 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. + + + Copyright (C) + + 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 . + +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: + + Copyright (C) + 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 +. + + 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 +. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d7ece2d --- /dev/null +++ b/Makefile @@ -0,0 +1,22 @@ +.PHONY: build serve clean scp + +build: chess.js main.js Makefile + +serve: build + python -m http.server + +upload: build + scp *.js *.html root@pyrope.net:/var/www/mysite/elo-worldle/ + +# i'm so generous for putting random crap for you to see :] +full-upload: build + scp * root@pyrope.net:/var/www/mysite/elo-worldle/ + +clean: + rm *.js + +# main.js: main.ts +# tsc main.ts + +%.js: %.ts tsconfig.json + tsc diff --git a/all-fate-data.cc b/all-fate-data.cc new file mode 100644 index 0000000..9dafd1e --- /dev/null +++ b/all-fate-data.cc @@ -0,0 +1,2148 @@ +// Generated by maketable.cc over all games. + +LivedDied all_fate_data[32][64] = { + // a8 rook + { + { 0.23403837280639705, 0.054471297114506718 }, + { 0.022867206496525884, 0.012780469729890498 }, + { 0.028254939221235738, 0.02063579528756751 }, + { 0.046768702656560662, 0.036450618254037163 }, + { 0.022837204544906935, 0.021476950722506917 }, + { 0.016616199777985952, 0.011374945193720948 }, + { 0.0080396218488484397, 0.0042305815021306224 }, + { 0.0044164133651621341, 0.0023427490620877276 }, + { 0.0037934119010684768, 0.0041468562745213241 }, + { 0.002897602360864462, 0.0041774649450090568 }, + { 0.004127304907195966, 0.0063683366616046422 }, + { 0.005982129469237432, 0.0099587823263765848 }, + { 0.0039989552103451235, 0.0064225816762964877 }, + { 0.0031174618639048706, 0.004762203594710088 }, + { 0.0020075497329235395, 0.0022634941865344238 }, + { 0.0009027937241853967, 0.0010008964103302238 }, + { 0.0023145949350365752, 0.0033592600840865712 }, + { 0.0023863438879070014, 0.0028895509840845663 }, + { 0.0026703179627425443, 0.0050382369646115076 }, + { 0.0034116434402298988, 0.0074237488373922605 }, + { 0.0027061420439622721, 0.0054064105749668002 }, + { 0.0022838795452689905, 0.0031599835680767505 }, + { 0.0020787176586036641, 0.001968423282877301 }, + { 0.0011127164765018691, 0.00083262777396609885 }, + { 0.0019162217447663127, 0.0026352290587840148 }, + { 0.0017760380655497327, 0.0029351359268447717 }, + { 0.0022821147245855227, 0.0042446170637140349 }, + { 0.0030270548236071017, 0.0072695256440263476 }, + { 0.0022794309323255577, 0.005016691527779297 }, + { 0.0019391031488796247, 0.0027644206521759067 }, + { 0.0017311467981085613, 0.0018842435101871537 }, + { 0.0013464336756592707, 0.00089427001577801069 }, + { 0.0023522569594092982, 0.0028005135078782227 }, + { 0.0023417708020224237, 0.0026187231435003404 }, + { 0.0029790074322784748, 0.0049020750212189551 }, + { 0.0031353195567333288, 0.0071076344727748209 }, + { 0.0025241599801372494, 0.0049726895876702204 }, + { 0.0020557552268889836, 0.0029629995403007733 }, + { 0.0018615735683505841, 0.0019331051300953872 }, + { 0.0016198208026769686, 0.0010156711017407544 }, + { 0.0032630012699436202, 0.0027735194589247137 }, + { 0.0027522072234818082, 0.0033278747343954752 }, + { 0.0034816196672850168, 0.006529026252816361 }, + { 0.0034691414166742505, 0.0065930637495760476 }, + { 0.0025681105368893608, 0.0052477387686574554 }, + { 0.0022428084327899053, 0.0041600934177888106 }, + { 0.0019480932600656202, 0.0026550669871386033 }, + { 0.0020674054149394218, 0.0012883487431757368 }, + { 0.0070037808032157823, 0.0033534755038620362 }, + { 0.0074476994105870456, 0.0048315059092757743 }, + { 0.0069622294539773656, 0.0066016151259448768 }, + { 0.0062097735508581083, 0.0091673600521308667 }, + { 0.0048335632198373531, 0.0069314271077595318 }, + { 0.0043562849560977437, 0.0063357003247997328 }, + { 0.0038858742756448642, 0.0037776332579141595 }, + { 0.0038295442824299972, 0.0014512715341324937 }, + { 0.0037729791115428649, 0.008569079911586475 }, + { 0.0031375665904590875, 0.0058207303924429979 }, + { 0.0037557933549208782, 0.013329789436378645 }, + { 0.0051657487174872202, 0.024252812076739478 }, + { 0.0046001543208217446, 0.013181844893977321 }, + { 0.0029401477804318643, 0.0081233391713258982 }, + { 0.0019807691225297332, 0.0022464072440604474 }, + { 0.0025709880048794269, 0.0015087477714642828 }, + }, + // b8 knight + { + { 0.00019847612141093575, 0.00018015400208682832 }, + { 0.053370284185695213, 0.0053359600400012322 }, + { 0.00069249943067240481, 0.00056343827195588704 }, + { 0.0018426368250258514, 0.0012011808306497519 }, + { 0.00058725445790937844, 0.00055478808143904763 }, + { 0.0022577056537439683, 0.001375368434479706 }, + { 0.00050040275065702715, 0.00037979020159540738 }, + { 0.00017676665309302827, 0.00011772717593971307 }, + { 0.0011384338466630826, 0.0010407778004672629 }, + { 0.00097692607430583615, 0.0010006493749601976 }, + { 0.0016891982159951426, 0.0020149370786288049 }, + { 0.019436928684264165, 0.026266227417488922 }, + { 0.0059641097212062375, 0.0074473298456734869 }, + { 0.0012204159927014764, 0.0018097159034746722 }, + { 0.00057252126844101246, 0.00053284145916591497 }, + { 0.00059249358403689538, 0.00067137494211071949 }, + { 0.0056167681095345189, 0.0072933042806035955 }, + { 0.0048027924941468824, 0.0048917034882437725 }, + { 0.0461927169640904, 0.14161850610020052 }, + { 0.0016500579319681824, 0.0031612918673964096 }, + { 0.0029369343443385629, 0.0067853580578874466 }, + { 0.0067611189473804701, 0.013527728008824404 }, + { 0.0045490753114321549, 0.0070396799831879981 }, + { 0.00061444020631002804, 0.00081822067118616755 }, + { 0.00524976248240871, 0.0061234712502686956 }, + { 0.0012473962076742641, 0.0044792492818820136 }, + { 0.0055348808250782148, 0.01524151711369344 }, + { 0.0043934746488429764, 0.01957781394393162 }, + { 0.0096412213226322718, 0.10605214205989902 }, + { 0.0032639340755008391, 0.0084078606765414197 }, + { 0.0013749277233795793, 0.0035400702121161894 }, + { 0.0011035643101131364, 0.0017597969721827264 }, + { 0.0010907461388332139, 0.0022756957575307607 }, + { 0.0060516491749287417, 0.013025983362037395 }, + { 0.0053374323708065882, 0.026577887240314048 }, + { 0.0096990275992184169, 0.094606127754645955 }, + { 0.0039515718500911269, 0.018418409758777749 }, + { 0.0039598564282603277, 0.010584536752633817 }, + { 0.0034121177481403493, 0.006787723668590818 }, + { 0.0014517814151362278, 0.0023271621183805508 }, + { 0.00077520884884015593, 0.0013372656990068561 }, + { 0.0018187850659790762, 0.014280093002927492 }, + { 0.0020222038710734974, 0.0067606782362803434 }, + { 0.0048566817779058897, 0.026246656287333962 }, + { 0.0031115152284775988, 0.01163718608484306 }, + { 0.0042627573650058023, 0.038688543291632391 }, + { 0.0010830129436099119, 0.0038576707415197064 }, + { 0.0007674519382213314, 0.0013363170831859554 }, + { 0.0007855270221754126, 0.001498532364842957 }, + { 0.0011998073139924059, 0.002510596750181328 }, + { 0.0037298783564636436, 0.0066545893906933074 }, + { 0.0015398939909171932, 0.0057216889718920702 }, + { 0.0026634187589284512, 0.011261666630724667 }, + { 0.0014525897148669538, 0.0035473508385416032 }, + { 0.00050846005628580357, 0.0017889510984117451 }, + { 0.00037812617134291051, 0.00066438482928045655 }, + { 0.0019350893181874381, 0.0044254034763481298 }, + { 0.00021053342375117732, 0.00080952502616124327 }, + { 0.00057783154075509695, 0.0040339709918341257 }, + { 0.00054125251944456894, 0.0023349210052823356 }, + { 0.00074056263226471341, 0.0034748469455803768 }, + { 0.00043758264420083005, 0.0034052185443262562 }, + { 0.00021321128716226195, 0.00082680762064828021 }, + { 0.00018156309183745809, 0.00058638686968984623 }, + }, + // c8 bishop + { + { 0.0024807351146525539, 0.0013519850544945007 }, + { 0, 0 }, + { 0.088576278957051294, 0.013981674275935774 }, + { 0, 0 }, + { 0.0031883491574046454, 0.002495310201484103 }, + { 0, 0 }, + { 0.0008221218537496222, 0.00059953508022412378 }, + { 0, 0 }, + { 0, 0 }, + { 0.037234180850950128, 0.023911790617974511 }, + { 0, 0 }, + { 0.024388564929559268, 0.042627798946315493 }, + { 0, 0 }, + { 0.0037634494751087317, 0.0046348756361496747 }, + { 0, 0 }, + { 0.0023295277290839222, 0.0014595482071698533 }, + { 0.0093551761032544291, 0.011568389698715188 }, + { 0, 0 }, + { 0.013309740045747314, 0.021853543298272705 }, + { 0, 0 }, + { 0.0213114133091938, 0.062618246938358255 }, + { 0, 0 }, + { 0.0089216013608969056, 0.020159325323558627 }, + { 0, 0 }, + { 0, 0 }, + { 0.0057727679812816599, 0.018814952911026857 }, + { 0, 0 }, + { 0.010430438065094397, 0.039688481204726914 }, + { 0, 0 }, + { 0.016564518002293499, 0.042666364132001026 }, + { 0, 0 }, + { 0.0039058880931829116, 0.0049275591899908639 }, + { 0.0026194148425364139, 0.0040230045976879193 }, + { 0, 0 }, + { 0.0066917217712326943, 0.021103561701419631 }, + { 0, 0 }, + { 0.0096723556843874223, 0.038958141884215369 }, + { 0, 0 }, + { 0.013239657099412345, 0.029132620317845748 }, + { 0, 0 }, + { 0, 0 }, + { 0.0026355077146814044, 0.0096143063249971711 }, + { 0, 0 }, + { 0.0055714578701057827, 0.032754022478906422 }, + { 0, 0 }, + { 0.0075266222706030341, 0.12157095934087137 }, + { 0, 0 }, + { 0.007601634066640767, 0.018307081787063195 }, + { 0.001780293002763065, 0.0024996244271862419 }, + { 0, 0 }, + { 0.0029439778168087512, 0.0055154085090712655 }, + { 0, 0 }, + { 0.0025867528140530224, 0.029806795652911083 }, + { 0, 0 }, + { 0.0025983535950294553, 0.018879241395722487 }, + { 0, 0 }, + { 0, 0 }, + { 0.0010605386537864032, 0.0044279825256112043 }, + { 0, 0 }, + { 0.002076844142357385, 0.0092291030843737482 }, + { 0, 0 }, + { 0.0016214769277976245, 0.014739541241800085 }, + { 0, 0 }, + { 0.0013168546485938066, 0.0021810100646241365 }, + }, + // d8 queen + { + { 0.0016472199896373208, 0.001316621447204502 }, + { 0.0023672648522091336, 0.0018335380182770442 }, + { 0.0040061113309440444, 0.0035895602900057693 }, + { 0.070329048899438057, 0.048383592633251905 }, + { 0.004607606883864696, 0.0052513810581531224 }, + { 0.0031187563292438083, 0.0042629787086973462 }, + { 0.0011141611393457828, 0.0013273823079228456 }, + { 0.00075274444043144822, 0.00063157260329208898 }, + { 0.0016101923520948252, 0.0011207579718669639 }, + { 0.0037970205937538203, 0.0035205603467329954 }, + { 0.015484475411972783, 0.010708534674406276 }, + { 0.01354943154829343, 0.017457882880475735 }, + { 0.015528599881625393, 0.020147208732729578 }, + { 0.0045316425194401417, 0.0097843378057618034 }, + { 0.0034799457556177189, 0.0059650286927827346 }, + { 0.0011938290580377705, 0.0017160598539903177 }, + { 0.0021496069283863987, 0.0020283678976263926 }, + { 0.011360055877898725, 0.010140825654973375 }, + { 0.0069512116764741949, 0.0094952945651333217 }, + { 0.0093196840375720166, 0.015192396600717419 }, + { 0.0064855598853895014, 0.013782419499038514 }, + { 0.011641047741747311, 0.022997336824323877 }, + { 0.0067271861689536631, 0.010089827673185154 }, + { 0.0033474478408333959, 0.0033398608905491492 }, + { 0.0068184311532265614, 0.0045913875296102521 }, + { 0.0035251729911621259, 0.0065591368999981222 }, + { 0.0060178290446306669, 0.0076823553441505467 }, + { 0.0068160714713720707, 0.020013823466896122 }, + { 0.0070154803983402255, 0.015505287647826755 }, + { 0.0056269380616477595, 0.010508916261444338 }, + { 0.0087649374580751338, 0.015093912491961271 }, + { 0.0047978577155952376, 0.0044508995028177999 }, + { 0.002746594579874812, 0.0028725233300993967 }, + { 0.0041789530860780952, 0.0051818336845003699 }, + { 0.0042375637098290451, 0.0070407412471376312 }, + { 0.0072392094634167259, 0.019871195125657763 }, + { 0.0064338860148288888, 0.013270461421913139 }, + { 0.0062694078891824467, 0.010530366836694458 }, + { 0.0058803904224458189, 0.010073920571638422 }, + { 0.007873604198775995, 0.0052564363899653393 }, + { 0.0032403174941263288, 0.002024288849596519 }, + { 0.0026954009460735304, 0.0068431524767758297 }, + { 0.0056423273770589153, 0.0087400738421527305 }, + { 0.0049286481219019389, 0.0099670748096776264 }, + { 0.0063303999339004496, 0.010878081965845656 }, + { 0.0068937097474639228, 0.017234948281149239 }, + { 0.0059413627043342189, 0.0084129061269388357 }, + { 0.0063217457908176901, 0.003394321320083658 }, + { 0.0047701858015863768, 0.0014718624262949223 }, + { 0.0087988089717301737, 0.0037137716503379318 }, + { 0.0070749981359699123, 0.0052531063531773853 }, + { 0.0062215877703942438, 0.012320165760496134 }, + { 0.0064496883733787284, 0.013691826688142486 }, + { 0.012004179854271107, 0.0076299067706695322 }, + { 0.016568784797204594, 0.0053697544786208235 }, + { 0.0096776659567015064, 0.0019513897000432506 }, + { 0.0043533995829758369, 0.0020476860635624456 }, + { 0.002498928775584248, 0.0020066623818744056 }, + { 0.0037622498713518844, 0.0035707243371120075 }, + { 0.0052811320218361241, 0.029992621587093714 }, + { 0.0063102892784973521, 0.0057486711631478185 }, + { 0.0048913536861598149, 0.0042183186663625194 }, + { 0.0028302466850145831, 0.0018711881849520059 }, + { 0.0049728615242877585, 0.0012585187281743263 }, + }, + // e8 king + { + { 0.0021904744837205827, 0.0049105789667967387 }, + { 0.010136875065335914, 0.011449016279069621 }, + { 0.021588907152202817, 0.018284046232878985 }, + { 0.0052344561708818835, 0.01265855085779218 }, + { 0.049724469001227067, 0.051534157236740298 }, + { 0.011685527942332758, 0.023117733958542833 }, + { 0.14823462911935631, 0.10958049489034412 }, + { 0.026633140159315602, 0.03933825421993329 }, + { 0.0024964426116203036, 0.0035674812567743027 }, + { 0.0049000868805609832, 0.0044513085933905634 }, + { 0.0066595557897723154, 0.006779790868788535 }, + { 0.0093216109134582215, 0.010639522873435741 }, + { 0.012280157888249642, 0.014353069227516209 }, + { 0.016479642578001358, 0.013965377846645881 }, + { 0.027994065917922091, 0.021506695757341036 }, + { 0.020729255685038805, 0.021106974742091913 }, + { 0.0016329294875520419, 0.0035074259701794396 }, + { 0.0035339259483928962, 0.0040111370185118584 }, + { 0.0047878320321380922, 0.0050751124283660671 }, + { 0.0057679379457269064, 0.006671026136073374 }, + { 0.0071101957354912527, 0.0076072980936047292 }, + { 0.0098180472642141071, 0.009330104977621205 }, + { 0.0093125575612174986, 0.0091509608561270439 }, + { 0.0063942338735152341, 0.01023355285146643 }, + { 0.001182044482746038, 0.0028812861687449679 }, + { 0.0021486227394722141, 0.0022484111949821004 }, + { 0.0031483768582514365, 0.0029953176955490883 }, + { 0.0035010307185202, 0.0032630961315257101 }, + { 0.004294385797501004, 0.0039945777435882578 }, + { 0.0050980195241578617, 0.0046997688634311321 }, + { 0.004468664310347128, 0.0045898677680138505 }, + { 0.0026586440592965836, 0.0056277977447354507 }, + { 0.0010557876695500583, 0.0022965811158542604 }, + { 0.0021034864129439767, 0.001831399680114097 }, + { 0.0026144899453995705, 0.0020502473262788779 }, + { 0.0025386026560104647, 0.0021405002165057509 }, + { 0.0028111597441848745, 0.0024145632322958408 }, + { 0.0036836550743072909, 0.0027491400323275622 }, + { 0.0032649103592831828, 0.002884466008027946 }, + { 0.0018030360670691623, 0.0036422163731976063 }, + { 0.00097807034213979777, 0.0016078801010313793 }, + { 0.0023181384103842318, 0.0011664535864729408 }, + { 0.0025204504970209353, 0.0012708507338460369 }, + { 0.0021788440584997464, 0.001334526570824005 }, + { 0.0023843636523808707, 0.0012958981440837393 }, + { 0.0034494754249372, 0.0014317004039775334 }, + { 0.0034073193331129593, 0.0013730087526252152 }, + { 0.0014390502003065546, 0.0019215399222122379 }, + { 0.00077387090527609363, 0.0012286491875137114 }, + { 0.0012843092208050676, 0.00084730760379453916 }, + { 0.001450935566029258, 0.00084670483749167507 }, + { 0.0010958864508127202, 0.0007367523587174284 }, + { 0.0011892539629848843, 0.00082125624181305019 }, + { 0.0017354373084151773, 0.00072505473987594506 }, + { 0.0013071313364295732, 0.00066329392108642059 }, + { 0.00082060604471914113, 0.00095224230013281255 }, + { 0.00039844038389090969, 0.001027145400607734 }, + { 0.0004669719481021138, 0.0007918570564969654 }, + { 0.00043263600795142432, 0.0007329262749064617 }, + { 0.00036340681585526603, 0.00069446187965189338 }, + { 0.00038134751256805292, 0.00072742035057931655 }, + { 0.00044768342641046368, 0.00063465955727593708 }, + { 0.0004420688065205069, 0.00060094021740883313 }, + { 0.00037292657087459785, 0.00076806260965603629 }, + }, + // f8 bishop + { + { 0, 0 }, + { 0.0022563123742570202, 0.0011786077266782327 }, + { 0, 0 }, + { 0.0033174043872722823, 0.0030945626732449168 }, + { 0, 0 }, + { 0.062548187707418795, 0.012964242306077471 }, + { 0, 0 }, + { 0.0018097791445293989, 0.00084640839504764357 }, + { 0.0033132067622647964, 0.002191183969303298 }, + { 0, 0 }, + { 0.0058381868998305326, 0.0048173695572613917 }, + { 0, 0 }, + { 0.033090514297126589, 0.058861289552773803 }, + { 0, 0 }, + { 0.03935414551121634, 0.03784814872563267 }, + { 0, 0 }, + { 0, 0 }, + { 0.010686509000814734, 0.012040938717331015 }, + { 0, 0 }, + { 0.02414745643213068, 0.056609720257621288 }, + { 0, 0 }, + { 0.016286245503798164, 0.034553210723052057 }, + { 0, 0 }, + { 0.0064878662076040669, 0.010308957927813245 }, + { 0.0029723750266640097, 0.003016297915454678 }, + { 0, 0 }, + { 0.022824670958373282, 0.040045866286402422 }, + { 0, 0 }, + { 0.011130226027324056, 0.050939979859621301 }, + { 0, 0 }, + { 0.0065681862996729238, 0.028365765217078398 }, + { 0, 0 }, + { 0, 0 }, + { 0.01037128396352939, 0.01932728252934875 }, + { 0, 0 }, + { 0.011944332077387067, 0.040047512530108277 }, + { 0, 0 }, + { 0.0066582712058481782, 0.023548184197540265 }, + { 0, 0 }, + { 0.0044094489440103541, 0.0075733376472164795 }, + { 0.0031319994013601759, 0.010288851224976067 }, + { 0, 0 }, + { 0.0061061866794986982, 0.09064822784651623 }, + { 0, 0 }, + { 0.005757669179465655, 0.030907039807651068 }, + { 0, 0 }, + { 0.0042387257642096483, 0.017708797693952883 }, + { 0, 0 }, + { 0, 0 }, + { 0.0032580447522794131, 0.0090054827148600605 }, + { 0, 0 }, + { 0.002150927085403819, 0.02857935792685198 }, + { 0, 0 }, + { 0.0037267380428398699, 0.016890191647589474 }, + { 0, 0 }, + { 0.001721520323809378, 0.0058687224478487388 }, + { 0.0020783144968797812, 0.0074059069548274839 }, + { 0, 0 }, + { 0.0012035484176360835, 0.0061939889788549104 }, + { 0, 0 }, + { 0.0013717360263988401, 0.0045301998328791887 }, + { 0, 0 }, + { 0.00081394794742619347, 0.0022203993603040831 }, + { 0, 0 }, + }, + // g8 knight + { + { 0.00015552358755373038, 0.00016205520273722464 }, + { 0.00041788503193641646, 0.00036098982179492913 }, + { 0.00082304477789204027, 0.00070254290067619228 }, + { 0.00034909457465742477, 0.00034771710543415836 }, + { 0.0027670095828537817, 0.0015881805124840056 }, + { 0.0012975028858474298, 0.0008983787080522874 }, + { 0.041520289975413772, 0.0058457145616259733 }, + { 0.00024114011795595047, 0.00013225483198021719 }, + { 0.00022353934191231969, 0.00034326651620776534 }, + { 0.00032495032573253855, 0.00043367355650553456 }, + { 0.0011853508041384693, 0.001440925692835794 }, + { 0.0070807115700078794, 0.0089430104342048608 }, + { 0.012464398843498184, 0.016623379613980395 }, + { 0.001613107369461135, 0.0027301262139673814 }, + { 0.0016059907745214186, 0.0014108110930881133 }, + { 0.0029127169729441485, 0.0026111618848945767 }, + { 0.0004621932959043259, 0.00056915170599385436 }, + { 0.003398989300435674, 0.0036102025655251634 }, + { 0.0030782781016527858, 0.0053741260165288086 }, + { 0.0024364564949290474, 0.0061126036702705 }, + { 0.001931091297758933, 0.0036296096641944262 }, + { 0.047192769501596614, 0.15359096463667729 }, + { 0.0048277806158957782, 0.0078792484629103543 }, + { 0.0049554662816719899, 0.012494335577779446 }, + { 0.00047936719482855126, 0.00056251337153050878 }, + { 0.00088000125280529411, 0.0021455002123950823 }, + { 0.0030081714399222944, 0.0074686519625311925 }, + { 0.0092690753835269566, 0.091751867255381855 }, + { 0.0039777753858605521, 0.024429511536211861 }, + { 0.0056763273491063689, 0.017612564571488416 }, + { 0.0021638658099443144, 0.0099013930454950449 }, + { 0.0057112937235213653, 0.013096588047073858 }, + { 0.00081877007784910598, 0.0013005582193039145 }, + { 0.0018834490444371492, 0.0033294241402362802 }, + { 0.0027533593964476108, 0.0080783905916788808 }, + { 0.0026444760867548379, 0.01129179704073603 }, + { 0.011950363692981627, 0.10531599049120149 }, + { 0.0058027620277687677, 0.023033342723575944 }, + { 0.0099516420160413472, 0.025533783355624753 }, + { 0.0015857081825007828, 0.00411012705570582 }, + { 0.00042800557697565212, 0.00057993232954180022 }, + { 0.00077029976196699406, 0.0024266462263145649 }, + { 0.0032948648801110867, 0.035803563450034791 }, + { 0.0028986537433992941, 0.010226054833915393 }, + { 0.0040866666006851666, 0.02727864951004309 }, + { 0.0022597432014759451, 0.011823166169096589 }, + { 0.0022811819190283037, 0.016655223461318262 }, + { 0.0012256472136971523, 0.0024925928124138142 }, + { 0.00045512808432157496, 0.00057874853604863443 }, + { 0.00072718517290705151, 0.0012638764312794557 }, + { 0.0012067638300123453, 0.0017345578624978837 }, + { 0.0016674927002431556, 0.014820124179502651 }, + { 0.0021583262888068455, 0.0069214290922638292 }, + { 0.0028903079004583268, 0.011990952592418423 }, + { 0.00069292630779181023, 0.0026092666295357354 }, + { 0.00057156277120531062, 0.0019530280386172647 }, + { 0.00036974870787458006, 0.0010270287999130814 }, + { 0.00024438517457661538, 0.0010721335059139555 }, + { 0.00041643641652658244, 0.0021324587211406561 }, + { 0.00087412576356458961, 0.0045745851718825463 }, + { 0.00046005298145841841, 0.002037460775526319 }, + { 0.00061274850809608819, 0.007110946723016133 }, + { 0.00015914809050275564, 0.00059345208127259722 }, + { 0.00076931952561872994, 0.0021552768841992414 }, + }, + // h8 rook + { + { 0.0046086404798528864, 0.0033582640374746255 }, + { 0.0063455105934142157, 0.0048186284495070454 }, + { 0.011506026113622799, 0.010469141590587152 }, + { 0.021257381733061659, 0.023112119338652877 }, + { 0.041533606169999668, 0.034927601719600167 }, + { 0.12161135654086103, 0.044273801545649319 }, + { 0.018020014829394922, 0.0096603141923108614 }, + { 0.13993885135462023, 0.036071416984763904 }, + { 0.0010599773894257036, 0.0013998822483181515 }, + { 0.0015041963918069189, 0.0021364626704180418 }, + { 0.002390770761737872, 0.003749271621152185 }, + { 0.0037981233596456176, 0.0066195242021303002 }, + { 0.0056778471107027705, 0.009426413198838161 }, + { 0.0087185501444330821, 0.018578188283544812 }, + { 0.0042726980682956592, 0.0051530115738086663 }, + { 0.0029769422165850552, 0.0034657738305100523 }, + { 0.00092646366519983259, 0.00087948346666971906 }, + { 0.001250078023651269, 0.0014288565327977912 }, + { 0.0016467575394246317, 0.0027284404446023224 }, + { 0.0024149347734923601, 0.0052124443312710636 }, + { 0.0038500857675184204, 0.0078934065540372991 }, + { 0.0053366379050565843, 0.0089220045226207877 }, + { 0.0042654648726612905, 0.0045060239634269394 }, + { 0.0030662227755955044, 0.0031627661744847262 }, + { 0.0010646631563243616, 0.00080752700408847093 }, + { 0.0012126136275745672, 0.0014752873246649664 }, + { 0.0015342279876702711, 0.0024167746929283159 }, + { 0.0022242096338513681, 0.0050021737531535946 }, + { 0.0031532582771631556, 0.0080679558176489728 }, + { 0.0035288310909214748, 0.00661133646182615 }, + { 0.0026594859558376331, 0.0037028269953042884 }, + { 0.0025501382196492107, 0.0027458732365943351 }, + { 0.0016375618948107741, 0.00092178975599893577 }, + { 0.0016975025569939451, 0.0014979829581800185 }, + { 0.0021054626959041869, 0.0027091835434380354 }, + { 0.0024379169680366431, 0.0049443180694934445 }, + { 0.0031513155910132692, 0.0074371954666535298 }, + { 0.0031412997889709244, 0.0061795759472260984 }, + { 0.002482936693870228, 0.0030800883768443382 }, + { 0.0024592292034795482, 0.0028994837822425823 }, + { 0.0023819446820375735, 0.0010429161386302102 }, + { 0.0022031207183829666, 0.001853745511545192 }, + { 0.0026013358060164127, 0.0033181059677231568 }, + { 0.0027298653446166336, 0.0046273499506371951 }, + { 0.0029715034858785569, 0.0071538281106867706 }, + { 0.0031873392768119778, 0.0084590641917575028 }, + { 0.0023445929340896038, 0.0042067317193668075 }, + { 0.0029339896827278496, 0.0028585351993070298 }, + { 0.0049030789729627416, 0.0015341845094451463 }, + { 0.0049762765412430018, 0.0025355987059109452 }, + { 0.0048808813627536623, 0.0038856628133681218 }, + { 0.0048575137930321382, 0.0066596210071100019 }, + { 0.0054399065948594, 0.0088197555948254392 }, + { 0.0057429518002609708, 0.0083874397447135703 }, + { 0.0047653676237293845, 0.0052352111109726833 }, + { 0.0052365727699322682, 0.0029733453815974729 }, + { 0.0028378000384885059, 0.001592767465234653 }, + { 0.0025178338983816171, 0.002373395281951705 }, + { 0.0030033908114415462, 0.0059053093742911077 }, + { 0.0041765479497155198, 0.015345732443034197 }, + { 0.0050944503571317221, 0.020990891833575092 }, + { 0.0035855484355965432, 0.015775093750120553 }, + { 0.0023036206357585289, 0.003666376432386174 }, + { 0.0034930643219075932, 0.0041604333384579672 }, + }, + // a7 pawn + { + { 0.00011726077316110348, 5.2727229378404303e-06 }, + { 5.8126434425698179e-05, 9.6580948265465459e-06 }, + { 4.9746994674407538e-05, 1.7298404750718624e-05 }, + { 5.6501929832405516e-05, 1.5559275745733773e-05 }, + { 5.183197319742915e-05, 1.8272712250102183e-05 }, + { 6.0458448318746049e-05, 3.3156099223444117e-05 }, + { 6.4851725339293002e-05, 3.9616568220370788e-05 }, + { 0.00012369752676250764, 3.9986133133930075e-05 }, + { 0.38416810511080685, 0.079508033447940885 }, + { 0.00012730819573081141, 1.2154140205291847e-05 }, + { 9.9594779779785795e-05, 1.7626467722113495e-05 }, + { 9.7063161307756705e-05, 1.6494057585913131e-05 }, + { 0.0001100710557518593, 1.9936742502599051e-05 }, + { 0.00011193271430037717, 2.9833967567331012e-05 }, + { 0.00027765392192879144, 5.837939864460507e-05 }, + { 8.7474236384817519e-05, 2.7462428015078945e-05 }, + { 0.16319392709748287, 0.051301625807359023 }, + { 0.0083606156560946387, 0.0074400037647399881 }, + { 8.3359615261660182e-05, 1.5011845365755588e-05 }, + { 9.295249275051979e-05, 1.7592870911789921e-05 }, + { 9.8924819856274589e-05, 2.0582987030587739e-05 }, + { 0.00023589901554547338, 4.7470316704245556e-05 }, + { 0.00017970340957190043, 3.0691674372062175e-05 }, + { 7.9250922987383478e-05, 1.432805146152291e-05 }, + { 0.077450746601757728, 0.041207373236625953 }, + { 0.009257654444299903, 0.028917592826643052 }, + { 0.00043701545099124979, 0.0006982563429354967 }, + { 0.00010190703084323156, 2.1958479970893937e-05 }, + { 0.00026821124194490782, 5.2312209956760192e-05 }, + { 0.00017170341614897012, 3.5966373592862817e-05 }, + { 0.0001844109155831208, 3.0290488931139536e-05 }, + { 8.3223251737405687e-05, 1.2167974186013317e-05 }, + { 0.023919201679075301, 0.019516778420988493 }, + { 0.0069045140864073913, 0.02715333736010209 }, + { 0.00072931758222111816, 0.0020135556568396181 }, + { 0.00028704521855570965, 9.3132334499898905e-05 }, + { 0.00017286151796365321, 3.4681789668726278e-05 }, + { 0.00018409273402652696, 3.6474278313636802e-05 }, + { 0.00018989707708066392, 2.8164008465953514e-05 }, + { 9.6227193615587862e-05, 1.2063231189122184e-05 }, + { 0.0094167709142752958, 0.0091167454692369261 }, + { 0.0028400826453075486, 0.012708434215990843 }, + { 0.00067090656304914971, 0.0025088675025911442 }, + { 0.00016624294632990974, 0.0001048240244925016 }, + { 0.00015599789546418081, 2.6114603036215687e-05 }, + { 0.00017631408429514018, 3.116598228251259e-05 }, + { 0.00021982195366416457, 2.6195630637584297e-05 }, + { 9.4333914539706626e-05, 8.8537476617410526e-06 }, + { 0.0051833909954730152, 0.0049946085419819101 }, + { 0.0017746823354390286, 0.0023783755150114344 }, + { 0.00041540874938727324, 0.00052631577283130141 }, + { 0.00019961446039601675, 6.3039473864780386e-05 }, + { 0.00016555717614271685, 1.6371528042380108e-05 }, + { 0.00021870140122572549, 2.061658384091131e-05 }, + { 0.00031555902910562034, 1.6604729431684893e-05 }, + { 0.00013516984934652701, 5.8715366747840775e-06 }, + { 0.0024160770650433617, 0.0025748634957643989 }, + { 0.00076786893392593572, 0.00077567327533580521 }, + { 0.00030601753497372619, 0.00016051765459418121 }, + { 0.00020406702590536999, 3.9980204285049441e-05 }, + { 0.00021181603139235365, 1.9604726965283761e-05 }, + { 0.00019414608544511552, 3.2258866759508752e-05 }, + { 0.00028188712002956141, 1.4446628439135512e-05 }, + { 0.0002458258848546085, 8.8952496039054634e-06 }, + }, + // b7 pawn + { + { 2.9610647592827276e-05, 6.4426824502847842e-06 }, + { 8.7128386866780754e-05, 7.1660020137216645e-06 }, + { 4.0444630780698807e-05, 7.8300330883522431e-06 }, + { 3.5476255418730725e-05, 9.1719292183348721e-06 }, + { 3.432605873588847e-05, 1.1490109130661268e-05 }, + { 3.747427749150309e-05, 2.1416978439796381e-05 }, + { 4.5035536097266763e-05, 2.9446616107129841e-05 }, + { 4.7413004498399464e-05, 2.6077053659971694e-05 }, + { 3.2446613640728706e-05, 6.1679791188155859e-06 }, + { 0.29407656850622038, 0.095497542041546465 }, + { 7.1723261191943363e-05, 9.9169878943340634e-06 }, + { 6.5683740465541436e-05, 1.0373509258142585e-05 }, + { 6.640903631193853e-05, 1.2810266148081585e-05 }, + { 7.5739068167090205e-05, 1.9899193126355057e-05 }, + { 0.00013309870480422687, 2.9041478100286779e-05 }, + { 7.7691635731777739e-05, 2.7096815667440084e-05 }, + { 0.0029566517194325784, 0.0035201868292535159 }, + { 0.11437869055032555, 0.041697833307710166 }, + { 0.025621028343186185, 0.028369010273699063 }, + { 5.9197579790132032e-05, 1.1565207883149249e-05 }, + { 6.505725876715485e-05, 1.3513822881916366e-05 }, + { 8.7086884924616345e-05, 2.0604726143150049e-05 }, + { 0.00016091291118622321, 2.8620529829762038e-05 }, + { 6.0460424601706253e-05, 1.3126471421715195e-05 }, + { 0.0022688341030929113, 0.0046354013274170908 }, + { 0.085234433878410093, 0.082492698978334431 }, + { 0.013911111092841473, 0.025726662643692371 }, + { 0.0026329484282479323, 0.0048713892756957729 }, + { 9.2219291772281865e-05, 2.1984171649376667e-05 }, + { 0.00016038326735288693, 3.1264796430523091e-05 }, + { 0.00012869159380295844, 2.2968360563561275e-05 }, + { 6.2436707561916308e-05, 8.9782534882342867e-06 }, + { 0.0022482274006668012, 0.0090258542396139049 }, + { 0.024545987725037761, 0.033346108948653509 }, + { 0.0081039577643351179, 0.026803092588761825 }, + { 0.001585202254062969, 0.0055822780193129327 }, + { 0.00030249579873863189, 0.00040233959017140414 }, + { 0.00013777459028808386, 2.8505905418069853e-05 }, + { 0.00013493862424018244, 2.0450576072253663e-05 }, + { 6.1015760113525282e-05, 7.9268709534025366e-06 }, + { 0.0012056452538568665, 0.0045545654254956188 }, + { 0.0046309507381906978, 0.0092869093609598934 }, + { 0.0026210551573933884, 0.012988299598552109 }, + { 0.00073316540514464714, 0.0017233562906794132 }, + { 0.00017720538791019493, 0.00026938515402327257 }, + { 0.00013439119386020426, 5.4140271694954498e-05 }, + { 0.00013802557822403054, 1.817587438505189e-05 }, + { 6.6932751296394186e-05, 6.4169907718020532e-06 }, + { 0.00084056650261726264, 0.0010162442237992152 }, + { 0.0028373632799542996, 0.0031337958425710069 }, + { 0.0013344712349011192, 0.0019845754435110978 }, + { 0.00042052929853717751, 0.00063388485435553481 }, + { 0.00015404335161653307, 9.9814147188369108e-05 }, + { 0.00014618762684969809, 4.2622494602850287e-05 }, + { 0.00021873697431900926, 1.5165995436651972e-05 }, + { 8.9507831550873659e-05, 4.1422890846002786e-06 }, + { 0.00041695617894511769, 0.00039053722833302967 }, + { 0.0014452517762356938, 0.0013189317219849874 }, + { 0.00056291060440551101, 0.00067068324307464596 }, + { 0.00024908675173895508, 0.00020386544504342858 }, + { 0.00015453149350770493, 4.4296406270148204e-05 }, + { 0.00014175284788698673, 3.154740489383313e-05 }, + { 0.00019253343854958412, 1.1241097477674801e-05 }, + { 0.00018843462769010846, 6.899203814093307e-06 }, + }, + // c7 pawn + { + { 2.4679821607103185e-05, 1.0296434222694394e-05 }, + { 3.0292465214099744e-05, 7.5494009080024153e-06 }, + { 5.9950543597972063e-05, 7.0513776020294816e-06 }, + { 3.2065191029408165e-05, 7.0829981293928421e-06 }, + { 2.5575077788078342e-05, 8.9861586200751266e-06 }, + { 2.8294443141327378e-05, 1.5612635385659447e-05 }, + { 3.406321310218053e-05, 2.3219348499507954e-05 }, + { 3.1956495466596614e-05, 2.1733183713429991e-05 }, + { 2.6501954496416858e-05, 7.6225233775301874e-06 }, + { 7.7244995782770268e-05, 8.5810206132320648e-06 }, + { 0.18305863606246522, 0.067110302533822427 }, + { 5.6191653407652533e-05, 8.6936687419640381e-06 }, + { 5.0875452244687483e-05, 1.0106711058514228e-05 }, + { 5.3999955604779581e-05, 1.5181805700333654e-05 }, + { 9.757501859445112e-05, 2.1901167765047845e-05 }, + { 3.7863605234664469e-05, 1.8328048172988064e-05 }, + { 2.1015792998873741e-05, 4.0909057276348167e-06 }, + { 0.0030825943036378849, 0.0028059206180573574 }, + { 0.096058049485872363, 0.062777189495433136 }, + { 0.0070347985642762794, 0.010336853161796611 }, + { 4.8219327946165165e-05, 1.0395248370704897e-05 }, + { 5.8312205023957928e-05, 1.4638327886275888e-05 }, + { 7.9962384853059094e-05, 1.5254928169861426e-05 }, + { 6.4620500232948422e-05, 1.4970343423591177e-05 }, + { 8.6731153991778537e-05, 0.00015149394659786207 }, + { 0.004040816836008293, 0.011846401327859779 }, + { 0.08129314265227798, 0.10258941565771361 }, + { 0.019773122083757338, 0.044192572363418767 }, + { 0.00050582171853392306, 0.0010681512957491323 }, + { 7.5082942224300464e-05, 1.6237140801085825e-05 }, + { 0.00013109475388257388, 2.2545436010076322e-05 }, + { 5.5752918590485901e-05, 8.4051314297733705e-06 }, + { 0.00014657102574397882, 0.00035056295289686087 }, + { 0.0034387718764247025, 0.012229319985381197 }, + { 0.021971410790302591, 0.031229057329470653 }, + { 0.011136787286751954, 0.1526189338152639 }, + { 0.0016615263019862814, 0.0055913511343832567 }, + { 0.00016432990442442642, 9.3128381933978483e-05 }, + { 0.00011409476785884698, 1.8077060237041385e-05 }, + { 5.0831974019562862e-05, 6.5948562382209579e-06 }, + { 0.00020595832869829103, 0.00089122456373632707 }, + { 0.0011855602901322516, 0.0065810815459882944 }, + { 0.0042413226000193645, 0.013486143062775664 }, + { 0.0026061658415711658, 0.0086740442521691524 }, + { 0.00063313386683065491, 0.0025531283357680084 }, + { 0.00017435361159861182, 0.00049881184287405803 }, + { 0.00011839713586322427, 2.0436742091532195e-05 }, + { 4.8938694943681626e-05, 4.8715374969177893e-06 }, + { 0.00016689314342381884, 0.00020599785435749523 }, + { 0.00079661396958219106, 0.0014718505685971609 }, + { 0.0023224486835204498, 0.0029758256167125366 }, + { 0.0012506471931438097, 0.0019929272153009457 }, + { 0.00031496812050051755, 0.00058007659819789552 }, + { 0.00015237339251515555, 0.00024541481799888483 }, + { 0.00017701961731193518, 4.1679807630830091e-05 }, + { 7.0292432328751287e-05, 3.4920919906911695e-06 }, + { 0.00015137141705432906, 8.9397159705101897e-05 }, + { 0.00031735942288237172, 0.00032420329077357911 }, + { 0.0010759022775190762, 0.0012479890925623271 }, + { 0.00049099959633234764, 0.00062068130789837139 }, + { 0.00019199193701848656, 0.00014521924819919514 }, + { 0.00012238922744284858, 7.1084921795795523e-05 }, + { 0.0001616362307496601, 1.3254929814128848e-05 }, + { 0.00014553940603874918, 5.8497975622217673e-06 }, + }, + // d7 pawn + { + { 1.8772711839035327e-05, 8.4189654104948408e-06 }, + { 2.2219349321641666e-05, 8.2766730373597156e-06 }, + { 2.1476266928602684e-05, 6.4308247525235234e-06 }, + { 3.9701548387659825e-05, 6.0434732923223527e-06 }, + { 2.169958690310642e-05, 6.9169903607351973e-06 }, + { 1.892686190993171e-05, 8.3458429409670686e-06 }, + { 2.1776661938554611e-05, 1.1934772796708531e-05 }, + { 2.0116584251978166e-05, 1.1990108719594412e-05 }, + { 2.0438718374492403e-05, 6.8418916082472156e-06 }, + { 5.6474261870962572e-05, 8.0790447413387112e-06 }, + { 4.0116567809303936e-05, 7.454539325912333e-06 }, + { 0.043939742531753173, 0.0080143649526169553 }, + { 4.0634353944878971e-05, 7.924894670442327e-06 }, + { 3.7353724230930279e-05, 8.9486092438311349e-06 }, + { 6.2604691613534169e-05, 1.1662045748199543e-05 }, + { 2.3043459316049258e-05, 9.4940633408491106e-06 }, + { 1.8270735967141972e-05, 3.7727241710409977e-06 }, + { 3.9294434097856552e-05, 5.2845806356016911e-06 }, + { 0.0052296874000988961, 0.0023081008692293248 }, + { 0.10408428794651425, 0.071089502819697281 }, + { 0.0018980261075516587, 0.0015434117745863672 }, + { 3.9401153377707898e-05, 9.5612569614962523e-06 }, + { 5.1913000798797764e-05, 8.7569097966907608e-06 }, + { 3.0300370345940585e-05, 6.4169907718020532e-06 }, + { 2.4110652114562688e-05, 3.4466374826063383e-06 }, + { 0.00016314018208237995, 0.00027596815256373229 }, + { 0.0073795670555338042, 0.010066572751592362 }, + { 0.08536334483962163, 0.28891535140556091 }, + { 0.016579782811878163, 0.063745453521524373 }, + { 0.00012664416465618084, 0.00011524298825872902 }, + { 6.8118521072520229e-05, 1.1918962533026851e-05 }, + { 5.6450546475440051e-05, 7.9327998022831669e-06 }, + { 4.0434749365897757e-05, 1.574702262695373e-05 }, + { 0.00030551753538479303, 0.00087128189238484734 }, + { 0.0081564596974560595, 0.058893479249629704 }, + { 0.019168776730808062, 0.034716147347989529 }, + { 0.012601242604512009, 0.079552626296655063 }, + { 0.00097362765804524559, 0.0035125643058759857 }, + { 0.0001172429866144616, 2.2426859032463722e-05 }, + { 4.4875457177489754e-05, 5.6837897935641225e-06 }, + { 4.0612614832316661e-05, 3.3209458863369786e-05 }, + { 0.00028367960867447194, 0.0020957097394955502 }, + { 0.0018064293449118428, 0.0098541164045209007 }, + { 0.0042351427632027873, 0.011660933100892945 }, + { 0.0023904051493902328, 0.0095849980486972571 }, + { 0.0007603985843363417, 0.0079021318433066274 }, + { 0.00012839119879300652, 0.00019074292618763381 }, + { 4.0780598883934515e-05, 4.4703520559951475e-06 }, + { 5.9015761757792705e-05, 5.7011810836139706e-05 }, + { 0.00029994441743700067, 0.00061309238133116476 }, + { 0.00089431547028609557, 0.0014614019605865304 }, + { 0.0020349153230735683, 0.0033585545510697763 }, + { 0.001008018934118821, 0.001810241594742088 }, + { 0.00031909262303847594, 0.0010174754480834262 }, + { 0.00021024883900490706, 0.00035594239511455261 }, + { 5.5606673651430356e-05, 1.0638331174810733e-05 }, + { 8.2822066296483048e-05, 4.0082970998980365e-05 }, + { 0.00013777261400512366, 9.5592806785360431e-05 }, + { 0.00033067957003418751, 0.00046552333269227983 }, + { 0.00085314751994195988, 0.0010526117828330006 }, + { 0.00040908859648052149, 0.00046195416566614046 }, + { 0.00016473701871422966, 0.00020248007068832133 }, + { 0.00012248408902493867, 4.9355690648285948e-05 }, + { 0.0001272093815828009, 1.1395247548571186e-05 }, + }, + // e7 pawn + { + { 2.4622509401257093e-05, 1.3537538277438887e-05 }, + { 2.7725273648786881e-05, 1.2575088475816589e-05 }, + { 2.3782589143167818e-05, 9.1837869160961328e-06 }, + { 2.732606449082445e-05, 6.9604685858598185e-06 }, + { 4.2719332467900577e-05, 6.0434732923223527e-06 }, + { 2.1992076781217508e-05, 7.5276617954401051e-06 }, + { 2.3592865978987653e-05, 1.1853745195339919e-05 }, + { 2.1312235442905249e-05, 1.295848737009734e-05 }, + { 2.6414998046167614e-05, 1.0780623547945859e-05 }, + { 7.0320100290194231e-05, 1.1812243253175508e-05 }, + { 4.476280904875778e-05, 9.6422845628648661e-06 }, + { 4.9492054172540443e-05, 8.1422857960654321e-06 }, + { 0.038906039160252391, 0.01175139152454768 }, + { 4.2521704171879574e-05, 9.5829960740585642e-06 }, + { 7.3513773553893682e-05, 1.159880469347282e-05 }, + { 2.281025792674447e-05, 9.8221263122439812e-06 }, + { 2.732606449082445e-05, 6.2391253053831485e-06 }, + { 5.0984147807499033e-05, 7.7094798277794298e-06 }, + { 4.2175854653842816e-05, 9.0671862214437386e-06 }, + { 0.0014967794018572505, 0.0018746071544731694 }, + { 0.1424677188407687, 0.074729088760274856 }, + { 0.0032779063960295244, 0.0019391071014455451 }, + { 5.288730829818132e-05, 8.5553289347493338e-06 }, + { 2.4507884989564908e-05, 5.7509834142112643e-06 }, + { 4.0312219822364734e-05, 5.7391257164500035e-06 }, + { 5.6503906115365721e-05, 8.4426808060173605e-06 }, + { 0.00012071926834147108, 0.00013390107568607217 }, + { 0.022538669217220565, 0.058456278028040196 }, + { 0.088276609242945767, 0.19703629650770879 }, + { 0.010585111850975238, 0.017752153389533971 }, + { 0.0001834879914407027, 0.00027707289473848968 }, + { 4.0335935217887249e-05, 6.0909040833673939e-06 }, + { 3.5737124769478447e-05, 4.0612614832316658e-06 }, + { 8.8262773285941332e-05, 1.6221330537404142e-05 }, + { 0.0010870386319998598, 0.004572836161462761 }, + { 0.014178919173062498, 0.11111415766108777 }, + { 0.021197186130376619, 0.049954933238631961 }, + { 0.007605529320355341, 0.038979013408558146 }, + { 0.00045354705795340688, 0.0011777836166838251 }, + { 6.300785333741702e-05, 1.613832665307532e-05 }, + { 3.6268744885774954e-05, 2.8656102923045818e-06 }, + { 9.0391230034087558e-05, 0.00017734965656629025 }, + { 0.00083111394121857798, 0.0091825003558890349 }, + { 0.0029010786425914719, 0.010299689160729861 }, + { 0.0042229431684894106, 0.010203669476825094 }, + { 0.0024424466085814444, 0.012618829546574919 }, + { 0.00047847589121349657, 0.0020237552531972621 }, + { 5.9689674247224334e-05, 4.6662016973519644e-05 }, + { 5.0794424643318869e-05, 6.770745421679653e-06 }, + { 0.00021098401626610521, 0.0018905359951324626 }, + { 0.00039301746344809328, 0.00083480959035417076 }, + { 0.0012928210715146922, 0.0022745850865071226 }, + { 0.0020035398547972737, 0.0029676556629550281 }, + { 0.00078986298699011345, 0.0017729688981125264 }, + { 0.00038625659944121468, 0.00091573837757477259 }, + { 0.00014157893498648822, 0.00019163422980268853 }, + { 0.00010930821052921822, 3.6150167908162354e-05 }, + { 0.00011003350637561532, 4.7122490903248587e-05 }, + { 0.00015736548327264615, 0.00018170340792763302 }, + { 0.00048725849268867004, 0.00068383342989188371 }, + { 0.00091141624674079323, 0.00091449924815872094 }, + { 0.00033387126701492673, 0.00043939291939238247 }, + { 0.00016899393221052214, 7.7638276091852062e-05 }, + { 0.00013519158845908932, 3.0069145239596008e-05 }, + }, + // f7 pawn + { + { 3.7288506893243342e-05, 2.3739110918043197e-05 }, + { 4.0703523848486324e-05, 2.314820231294039e-05 }, + { 3.2501949563614587e-05, 1.5895243848969482e-05 }, + { 2.7622506934855957e-05, 8.6284514042771059e-06 }, + { 3.0786535954152261e-05, 6.0375444434417224e-06 }, + { 6.0073073141505086e-05, 6.9999942450640197e-06 }, + { 2.9185746756382112e-05, 9.8774622351298622e-06 }, + { 2.595847668235909e-05, 1.3897221776197117e-05 }, + { 4.2822099181831501e-05, 1.9748995621379094e-05 }, + { 0.00011190109377301382, 2.0401168998248413e-05 }, + { 5.8675841088636574e-05, 1.4529632323464335e-05 }, + { 5.4094817186869667e-05, 9.3181741573904163e-06 }, + { 5.5796396815610521e-05, 7.535566927280945e-06 }, + { 0.33099389586272593, 0.12262346440442452 }, + { 0.00010391098176488456, 1.0946631316603503e-05 }, + { 2.7401163243312433e-05, 9.1600715205736113e-06 }, + { 5.7529596971714742e-05, 1.3940700001321738e-05 }, + { 7.7381359307024763e-05, 1.223912037258088e-05 }, + { 5.6490072134644255e-05, 1.2725285980792554e-05 }, + { 4.4165971594774343e-05, 9.0138265815180671e-06 }, + { 0.014060834289906987, 0.026107203832812658 }, + { 0.0687875837635675, 0.056087121873038145 }, + { 0.012796169321726407, 0.011595895604955391 }, + { 2.304543559900947e-05, 4.6620515031355233e-06 }, + { 3.9061232708551767e-05, 5.928848880630169e-06 }, + { 0.00010540702796576356, 1.4883386973341935e-05 }, + { 6.0723270235414193e-05, 1.1867579176061389e-05 }, + { 0.00086463565278966097, 0.0019565734902478814 }, + { 0.0099028456134708006, 0.033723276622760721 }, + { 0.063233641689338052, 0.081543778809857734 }, + { 0.0053140766587828261, 0.011069562045577448 }, + { 0.00027981399920430107, 0.00058786315306112312 }, + { 3.9600757956689112e-05, 4.416992416069476e-06 }, + { 8.4165938709425883e-05, 1.0094853360752969e-05 }, + { 0.00012789515176999381, 0.00012050978234768882 }, + { 0.00084744989616767426, 0.0022148104320926093 }, + { 0.0085016866863603519, 0.031959436175641405 }, + { 0.0158199415393366, 0.023426587459564462 }, + { 0.0035560958906405327, 0.011780164228165378 }, + { 0.00026434958504065734, 0.0005014956351340233 }, + { 3.9616568220370788e-05, 2.9940686847182354e-06 }, + { 8.9689649583212986e-05, 1.2351768501312853e-05 }, + { 0.00011020346671019338, 0.00022424882749503511 }, + { 0.00045788302276810779, 0.0013158388391522587 }, + { 0.0019549272465420263, 0.0055929855203913506 }, + { 0.0051821459372080828, 0.0090120222351753963 }, + { 0.001508139076312538, 0.006978442879382929 }, + { 0.0002816736814698587, 0.00055110231371825595 }, + { 6.05473810519555e-05, 2.6106697904374846e-06 }, + { 0.00013730225866059366, 1.9513817949114098e-05 }, + { 0.00010084379061063854, 6.8324054500382077e-05 }, + { 0.00023225079720092561, 0.0003677111601426035 }, + { 0.00095622451029763584, 0.0013960759273367871 }, + { 0.0019367434670251337, 0.0023525810698147727 }, + { 0.0008055270057327384, 0.0013764652715226226 }, + { 0.00018957889552407008, 0.00030539698212422021 }, + { 0.00011171927574067449, 3.5375464987760011e-06 }, + { 0.00015598208520049912, 6.0553309900836126e-06 }, + { 8.9744985506098874e-05, 2.0873500625738616e-05 }, + { 0.00014648011672780916, 0.00011227856381841394 }, + { 0.0004097407698573908, 0.00044634745912936169 }, + { 0.00098650511781397422, 0.0008493036495843513 }, + { 0.00032622700452483423, 0.00022521127729665741 }, + { 0.00016212042007491157, 5.1322092193694954e-05 }, + }, + // g7 pawn + { + { 4.8422885091066802e-05, 2.4865592205362931e-05 }, + { 4.8049367611587099e-05, 2.631223133223669e-05 }, + { 3.7233170970357461e-05, 1.9741090489538252e-05 }, + { 3.3075071622075503e-05, 1.0484181103914349e-05 }, + { 2.9679817496434626e-05, 8.2094794167125739e-06 }, + { 3.2598787428664884e-05, 6.822128778645115e-06 }, + { 6.1523664834299267e-05, 5.762841111972525e-06 }, + { 2.347033643545463e-05, 7.1600731648410342e-06 }, + { 7.8055271796456392e-05, 2.4339900937947054e-05 }, + { 0.00013196234210210609, 2.4654129928620453e-05 }, + { 7.4403100885988202e-05, 1.7440697123853749e-05 }, + { 6.1399159007806026e-05, 1.0832006904911319e-05 }, + { 5.6907067839248578e-05, 8.6877398930834078e-06 }, + { 5.698611915765698e-05, 8.256910207757615e-06 }, + { 0.33473968922586816, 0.069544087094189272 }, + { 2.5930808720916149e-05, 6.4387298843643642e-06 }, + { 4.8152134325518023e-05, 1.0958489014364762e-05 }, + { 0.00013097024805608064, 1.9124490205952716e-05 }, + { 7.4869503664597772e-05, 1.5701568118868899e-05 }, + { 5.3754896517713536e-05, 1.0553351007521701e-05 }, + { 4.8160039457358868e-05, 9.1067118806479399e-06 }, + { 0.01752537887241579, 0.019324488065243013 }, + { 0.17655079753926525, 0.07299862180350461 }, + { 0.0070715791664487486, 0.0095766166326630049 }, + { 4.175293010035786e-05, 6.3359631704334412e-06 }, + { 9.0723245571402845e-05, 1.3907103190998167e-05 }, + { 0.0001091678944390433, 1.8245044288659239e-05 }, + { 6.8760813034588492e-05, 1.4454533570976354e-05 }, + { 0.0010648133538293375, 0.0019684153777454602 }, + { 0.011493632843179323, 0.02135268995510075 }, + { 0.055416430724831656, 0.062076844221408703 }, + { 0.0044365378545459539, 0.0094152827732062582 }, + { 4.2559253548123567e-05, 5.0948574714215256e-06 }, + { 9.1604667771656533e-05, 1.0768765850184598e-05 }, + { 7.9997957946342869e-05, 1.4592873378191056e-05 }, + { 0.00014342478327132442, 0.00010465011159200312 }, + { 0.00083541828550591545, 0.002509733114527716 }, + { 0.0053131280429619251, 0.01641192524236976 }, + { 0.016858160053370392, 0.029202819864875367 }, + { 0.0026527389258114761, 0.0074247270974575645 }, + { 5.2695608851040944e-05, 3.5790484409404123e-06 }, + { 8.8628385633580196e-05, 8.094855005020391e-06 }, + { 7.8272662922079493e-05, 1.7160064943503918e-05 }, + { 9.5624427312723784e-05, 9.5326008585732076e-05 }, + { 0.00041200559012979151, 0.00089742613966546625 }, + { 0.0021014429363631197, 0.0073536500807936094 }, + { 0.0041570044875220025, 0.0076965924865959002 }, + { 0.0015592852793227742, 0.004272887791459839 }, + { 7.087148323609283e-05, 2.7865589738961794e-06 }, + { 0.00015514018865944964, 5.9881373694364708e-06 }, + { 8.477265757821037e-05, 1.0140307868837799e-05 }, + { 9.0331941545281262e-05, 4.0660045623361704e-05 }, + { 0.00022489111945710337, 0.00030899381711180251 }, + { 0.00078570093507591109, 0.001263032558455446 }, + { 0.0020208165204354299, 0.0022154705106013192 }, + { 0.00075465550605397131, 0.0010701157210115811 }, + { 0.00014188525884532079, 2.697626240686727e-06 }, + { 0.00015874888134479321, 3.6798388719111249e-06 }, + { 0.00010202758410380438, 6.1976233632187368e-06 }, + { 0.00010297619992470521, 2.1235160407457058e-05 }, + { 0.00015701963375460942, 9.3442610924651881e-05 }, + { 0.00037232380457173381, 0.00034427639680043265 }, + { 0.0011237362302880004, 0.00072859031009176085 }, + { 0.0003514008968719899, 0.00024406501673706135 }, + }, + // h7 pawn + { + { 0.00012482005548390695, 3.7521708282548133e-05 }, + { 6.8231169201252203e-05, 3.493673017059338e-05 }, + { 5.6972285176935509e-05, 3.0160054255765671e-05 }, + { 4.7972292576138908e-05, 1.6903148158676612e-05 }, + { 4.3818145793777373e-05, 1.3873506380674596e-05 }, + { 3.8739098586037523e-05, 1.4764809995729331e-05 }, + { 3.6126452512639833e-05, 7.6640253196945982e-06 }, + { 6.6984134653359651e-05, 3.3280605049937351e-06 }, + { 8.3656057705691693e-05, 2.5286540475887672e-05 }, + { 0.00025481006719172344, 4.4322097948630936e-05 }, + { 0.00010349200977732003, 2.5792468913701447e-05 }, + { 9.6624426490590079e-05, 1.6693662164894345e-05 }, + { 7.8169896208148576e-05, 1.3395245904303762e-05 }, + { 7.5561202700671302e-05, 1.3586945351444138e-05 }, + { 0.00010977461330782779, 9.7292410131141084e-06 }, + { 0.38425866234860961, 0.070409201007455305 }, + { 6.5994016890294412e-05, 1.2581017324697219e-05 }, + { 0.00014394454568985966, 2.2488123804230233e-05 }, + { 0.00017793463632251243, 3.2934755531900592e-05 }, + { 7.5173851240470128e-05, 1.5859670755685704e-05 }, + { 7.2424841642817936e-05, 1.397627309460552e-05 }, + { 6.1863585503455398e-05, 1.2754930225195704e-05 }, + { 0.015341226517884918, 0.011791486353244422 }, + { 0.17049132821266297, 0.059575676317230535 }, + { 5.6743036353551139e-05, 9.021731713358907e-06 }, + { 0.00013223309286765488, 1.9221328071003009e-05 }, + { 0.00011241295105970822, 2.2634368743285777e-05 }, + { 0.00017673898513158534, 3.115610086771154e-05 }, + { 7.3820097412726236e-05, 1.6466389624470191e-05 }, + { 0.00064628010108197227, 0.0011139556059179209 }, + { 0.010651040650527844, 0.031655746701994808 }, + { 0.068582178794098073, 0.041805981440141742 }, + { 6.7403106640924178e-05, 7.8794401623574954e-06 }, + { 0.00012714021167919355, 1.5940698357054314e-05 }, + { 0.00011261650820460986, 1.991895595595716e-05 }, + { 0.00010929832911441717, 2.09485993782266e-05 }, + { 0.00020984172471510379, 7.7450529210632116e-05 }, + { 0.00067402118499444079, 0.0020864666640906479 }, + { 0.0068450655186813123, 0.024758384783620416 }, + { 0.020453771721800323, 0.018472358331025562 }, + { 6.9565160199393982e-05, 4.9604702301272413e-06 }, + { 0.00014497616539508931, 1.2314219125068862e-05 }, + { 0.00010420149536003543, 1.5460461597723272e-05 }, + { 0.00010161256468216026, 1.5833979077202971e-05 }, + { 0.00012293072897394614, 7.9995981663382658e-05 }, + { 0.00064253702115533442, 0.0019962987540310638 }, + { 0.0029752366843903938, 0.014908904738924167 }, + { 0.0088658938968145043, 0.0081938312082336304 }, + { 0.00010744062313181972, 4.2549372133322511e-06 }, + { 0.00021689507860009349, 8.5711391984310153e-06 }, + { 0.00013090305443543351, 9.9960392127424659e-06 }, + { 0.00010877659041292172, 1.0938726184762662e-05 }, + { 0.00014103150460651004, 4.8685730724774742e-05 }, + { 0.00032240289699682779, 0.00073784129062850416 }, + { 0.0013189475322486692, 0.0023302332621007171 }, + { 0.0038602853638760645, 0.0036054614627036197 }, + { 0.00017568760259675358, 4.1126448401971277e-06 }, + { 0.00022322313663868608, 5.7351731505295836e-06 }, + { 0.00013728842467987219, 8.4486096548979908e-06 }, + { 0.00014989710996601236, 1.4847813880058155e-05 }, + { 0.0001501777421463622, 2.8604719566080358e-05 }, + { 0.00022047215075807368, 0.00014258881557915556 }, + { 0.00056769716173513975, 0.00043600557039858242 }, + { 0.0017119985925070861, 0.0014726371292153246 }, + }, + // a2 pawn + { + { 0.0023161759614047433, 0.0025510473098109073 }, + { 0.00075842823022501235, 0.00077207446406526276 }, + { 0.00028771913104514129, 0.00016019947303758737 }, + { 0.00020004133751542211, 4.2796407503348775e-05 }, + { 0.00020646228085314459, 1.923318576876427e-05 }, + { 0.00020173698829528236, 3.5314200215993498e-05 }, + { 0.00027472902314768058, 1.3853743551072495e-05 }, + { 0.00023875869698889734, 9.1600715205736113e-06 }, + { 0.0050583654065612469, 0.0050855847517722198 }, + { 0.0016759156182195708, 0.0022485159379789918 }, + { 0.0003974641001085659, 0.00050048377825839569 }, + { 0.00018714016235117086, 7.0928795441938929e-05 }, + { 0.00015511844954688733, 1.6861646216512203e-05 }, + { 0.00021100970794458795, 2.0150181062301737e-05 }, + { 0.00029405707049853493, 1.6150184350836581e-05 }, + { 0.00013824099306669344, 6.4565164310062544e-06 }, + { 0.0084067104798585778, 0.0086556687732051198 }, + { 0.0025905986606935914, 0.011191427558035842 }, + { 0.00064581567458632289, 0.0023326443273121735 }, + { 0.00016083188358485459, 0.00013630423576568759 }, + { 0.00014736746777694348, 2.6855709146294458e-05 }, + { 0.00016624689889583016, 2.8853731219066823e-05 }, + { 0.00020281603879155705, 2.5013813427378683e-05 }, + { 9.3551306487463446e-05, 8.5177795585053438e-06 }, + { 0.021591332051394994, 0.017973271784820034 }, + { 0.006635115098403397, 0.030144406047286729 }, + { 0.00080458431876071813, 0.0019571960193803476 }, + { 0.00026579227160161071, 0.00010817382411005764 }, + { 0.00015930619313957243, 3.4721315327930483e-05 }, + { 0.00016794057339273018, 3.4861631418105393e-05 }, + { 0.00017738720594253425, 2.6723298187960382e-05 }, + { 9.3248935194551301e-05, 1.1859674044220549e-05 }, + { 0.074897130124098557, 0.042749253391918159 }, + { 0.0089758523044376308, 0.027255837275833385 }, + { 0.00054840468747756918, 0.00089144985999379102 }, + { 9.3762768764205914e-05, 2.1830021578480284e-05 }, + { 0.00024812430193733279, 5.0416954597918751e-05 }, + { 0.0001565255630145569, 3.5889298557414625e-05 }, + { 0.00017748009124166411, 2.8913019707873126e-05 }, + { 8.0446574178310551e-05, 1.190710483526559e-05 }, + { 0.13468038729833773, 0.046345035020682671 }, + { 0.011004336802758675, 0.0089764353079108926 }, + { 7.8644204118598991e-05, 1.5561252028693985e-05 }, + { 9.0108621570777526e-05, 1.7480222783057951e-05 }, + { 9.6011778772924958e-05, 2.0701564008200339e-05 }, + { 0.00022954328954543783, 4.6308262323642041e-05 }, + { 0.000169086817509652, 2.9229224981506736e-05 }, + { 7.8173848774068999e-05, 1.3513822881916366e-05 }, + { 0.41701172040143147, 0.083980907240993261 }, + { 0.00012659278129921537, 1.1998013851435252e-05 }, + { 9.2371465560218036e-05, 1.6958484081562493e-05 }, + { 9.1100715616802976e-05, 1.6124492672353851e-05 }, + { 0.00010559872741290395, 1.9476268572870105e-05 }, + { 0.00010428449924436425, 2.8432782948542081e-05 }, + { 0.00025005315410649783, 5.2897189712982369e-05 }, + { 7.9243017855542633e-05, 2.4276659883220335e-05 }, + { 9.7407034542833259e-05, 5.2786517867210607e-06 }, + { 5.2901142278902792e-05, 1.0337936164858805e-05 }, + { 4.4397196701118916e-05, 1.6705519862655606e-05 }, + { 5.2731181944324726e-05, 1.5292477546105418e-05 }, + { 5.0482171935605682e-05, 1.8667968842144192e-05 }, + { 5.819165176338511e-05, 3.1086930964104187e-05 }, + { 6.1241056370989235e-05, 3.5260840576067828e-05 }, + { 0.00011368962985200392, 3.5193646955420686e-05 }, + }, + // b2 pawn + { + { 0.0004048889951900751, 0.00037437518628443182 }, + { 0.0013998130784145441, 0.0012815681163392562 }, + { 0.00053631774089292451, 0.00062712794291457661 }, + { 0.00023264407751000742, 0.00017780420164713857 }, + { 0.00014969948166999135, 3.9938702342885032e-05 }, + { 0.00014643663850268454, 3.2132384650055307e-05 }, + { 0.00018975873727344921, 1.0626473477049473e-05 }, + { 0.00018347415745998121, 6.2015759291391568e-06 }, + { 0.00078576812869655824, 0.00094782530771674305 }, + { 0.0026681736957307163, 0.0029609046803629503 }, + { 0.0012344278388893657, 0.001755379979766657 }, + { 0.00037662814885907128, 0.0005754125704117998 }, + { 0.0001449149006233228, 9.998806008886759e-05 }, + { 0.00014103150460651004, 4.3723284211687288e-05 }, + { 0.0002049484481056237, 1.3529633145598047e-05 }, + { 9.1078976504240666e-05, 4.420944981989896e-06 }, + { 0.0011391255456991562, 0.0040765915101540155 }, + { 0.004251490575849645, 0.0076604581289514201 }, + { 0.0022477076382482657, 0.009713379366075461 }, + { 0.00068185912321463385, 0.0015548366663793414 }, + { 0.00016498603036721614, 0.00030035746057568459 }, + { 0.00012637934273951269, 4.9727231844805439e-05 }, + { 0.00012941491336639533, 1.6924887271238922e-05 }, + { 6.6841842280224522e-05, 6.0375444434417224e-06 }, + { 0.002185905317516577, 0.0086641331931236985 }, + { 0.019333634302782867, 0.028921446578415461 }, + { 0.0069667729285028887, 0.022055610325822341 }, + { 0.0012611847338876497, 0.0051866459335084816 }, + { 0.00028796221384924713, 0.00037168348889262575 }, + { 0.00012545839488005479, 2.6936736747663068e-05 }, + { 0.00012794851140991947, 1.9223304353963217e-05 }, + { 5.9650148588020136e-05, 7.9822068762884176e-06 }, + { 0.0024528576672158309, 0.0053029284466042806 }, + { 0.068103396579025741, 0.071667537917597279 }, + { 0.012336282348036647, 0.023641707836066284 }, + { 0.0023147273459949093, 0.0036305424697516456 }, + { 8.6829968139789045e-05, 2.068180117859824e-05 }, + { 0.00014575482088141208, 2.9924876583500675e-05 }, + { 0.00012293863410578698, 2.1365595082830919e-05 }, + { 6.0005879520857944e-05, 8.8438662469400032e-06 }, + { 0.0033591770802022425, 0.0040495856035027448 }, + { 0.10716072019988221, 0.042802824494120574 }, + { 0.028047536229693533, 0.031005980437771023 }, + { 5.8112600444976707e-05, 1.1320148796083204e-05 }, + { 6.4266745583070825e-05, 1.3365601659900612e-05 }, + { 8.6494000036553323e-05, 2.0007888689166612e-05 }, + { 0.00015036944159350257, 2.6207488335345558e-05 }, + { 5.9100741925081735e-05, 1.1482203998820428e-05 }, + { 3.0330014590343737e-05, 6.8833935504116264e-06 }, + { 0.33116592338928036, 0.11528828861674295 }, + { 6.8152117882843793e-05, 1.0094853360752969e-05 }, + { 6.2665956385300677e-05, 1.0250979714609563e-05 }, + { 6.4681765004714943e-05, 1.258496989061764e-05 }, + { 7.1535514310723416e-05, 1.9059272868265785e-05 }, + { 0.00012052756889433071, 2.6808278355249415e-05 }, + { 7.2928793797671506e-05, 2.3926857799263154e-05 }, + { 2.7875471153762845e-05, 7.7786497313867828e-06 }, + { 7.5711400205647262e-05, 7.0513776020294816e-06 }, + { 3.7454514661900991e-05, 7.5691637376045159e-06 }, + { 3.3458470516356255e-05, 8.7371469670886602e-06 }, + { 3.3974280368971078e-05, 1.1047421747574216e-05 }, + { 3.5980207573584289e-05, 2.0124489383819004e-05 }, + { 4.3707473948005611e-05, 2.5859662534348589e-05 }, + { 4.4071110012684257e-05, 2.2820139341545523e-05 }, + }, + // c2 pawn + { + { 0.00016183583532864131, 9.5557233692076642e-05 }, + { 0.00033861632240239105, 0.00034462817516735006 }, + { 0.0011305366199540832, 0.0012873171234705071 }, + { 0.00050347389437719356, 0.00067034727497141029 }, + { 0.00021031405634259399, 0.0001784583513069681 }, + { 0.00014226075260776071, 9.801968226049838e-05 }, + { 0.00017266586595059242, 1.7895242204702062e-05 }, + { 0.00015217774050209476, 6.818176212724695e-06 }, + { 0.0001819405618828582, 0.00022413025051742249 }, + { 0.00081288668347656058, 0.0012631847322433821 }, + { 0.0024237806160222605, 0.0030797425273263014 }, + { 0.0013471115407146226, 0.0022216701102474984 }, + { 0.00038865975952083009, 0.00079377009840244869 }, + { 0.0001813654635414371, 0.0004219423408537277 }, + { 0.00017741487390397718, 5.212643935850045e-05 }, + { 7.7011794393465476e-05, 4.0632377661918762e-06 }, + { 0.00024702548861145598, 0.0011506986587141463 }, + { 0.0011779693872820847, 0.0070127768432506586 }, + { 0.0044123560562448231, 0.010068966030257177 }, + { 0.0029928671046784276, 0.0088115322814280063 }, + { 0.00078266931701494885, 0.0042814411441116284 }, + { 0.00020375477319765681, 0.00061968526128642547 }, + { 0.0001182074126990441, 2.0057295763171862e-05 }, + { 5.1958455306882596e-05, 5.2391261275168595e-06 }, + { 0.00016556112870863728, 0.00038817952276149907 }, + { 0.0036005207553030947, 0.015424001153390356 }, + { 0.019838505429212928, 0.031317205478344906 }, + { 0.013079216519853613, 0.09722164141461892 }, + { 0.0021513243182788213, 0.0061481490955928387 }, + { 0.00015593070184353365, 7.9241041572582422e-05 }, + { 0.00011538528063186415, 1.9092869678589356e-05 }, + { 5.2237111204272212e-05, 7.0237096405865403e-06 }, + { 0.00010924694575745171, 0.00019633580696502826 }, + { 0.0039255382746562805, 0.011818253129657506 }, + { 0.080398655245374345, 0.11946648281016432 }, + { 0.017436037048633574, 0.042936852051916101 }, + { 0.00041308266434310597, 0.00073093220539960976 }, + { 7.4697567047059501e-05, 1.7952554410548154e-05 }, + { 0.00013479830815000754, 2.3747016049884039e-05 }, + { 5.713631666263294e-05, 8.9999926007965969e-06 }, + { 2.2833973322266991e-05, 4.9328022686843008e-06 }, + { 0.0037973565618570557, 0.003404005106588687 }, + { 0.10643081566162191, 0.069205988557922454 }, + { 0.0064990420877440542, 0.0088518563589481316 }, + { 5.1098772219191218e-05, 1.0940702467722873e-05 }, + { 6.1515759702458422e-05, 1.5616587951579866e-05 }, + { 8.2118509562648264e-05, 1.4810264503814163e-05 }, + { 6.7452513714929432e-05, 1.50731101375221e-05 }, + { 2.6999977802389791e-05, 9.1739055012950816e-06 }, + { 8.7221272165910628e-05, 9.8320077270450306e-06 }, + { 0.20144712094465947, 0.070506074445598879 }, + { 5.714619807743399e-05, 8.7312181182080298e-06 }, + { 5.399797932181937e-05, 1.0266789978291243e-05 }, + { 5.4596793058763019e-05, 1.5162042870731553e-05 }, + { 9.381612840413159e-05, 2.1365595082830919e-05 }, + { 3.7863605234664469e-05, 1.7598799760670551e-05 }, + { 2.6088911357732954e-05, 1.2881412334649148e-05 }, + { 3.0632385883255871e-05, 8.590902028033116e-06 }, + { 5.9681769115383496e-05, 7.7055272618590107e-06 }, + { 3.2707482991476434e-05, 6.8675832867299457e-06 }, + { 2.7693653121423522e-05, 8.9624432245526052e-06 }, + { 3.0118552313601259e-05, 1.5561252028693985e-05 }, + { 3.4579022954795354e-05, 2.2367570543657418e-05 }, + { 3.174503318985414e-05, 2.0499983146258914e-05 }, + }, + // d2 pawn + { + { 9.4150120224407088e-05, 5.9889278826205548e-05 }, + { 0.00014046233511396956, 0.00010442086276861875 }, + { 0.00033810248883273645, 0.00049544030414393973 }, + { 0.00089568503437752113, 0.00118281720938348 }, + { 0.00044937710090736367, 0.00055222286615669498 }, + { 0.00018847810591523308, 0.00027828633247605866 }, + { 0.0001269504885150134, 5.4369520518338861e-05 }, + { 0.00012995246233157246, 1.3664020386892331e-05 }, + { 6.0173863572475798e-05, 5.9911017938767858e-05 }, + { 0.00032909656738305923, 0.00083351117244931275 }, + { 0.00095499130973046478, 0.001669162659344533 }, + { 0.0022026207187940336, 0.0037858091405205485 }, + { 0.0011878488258001748, 0.0024147094772348963 }, + { 0.00041815380641900502, 0.0017310815807708743 }, + { 0.0002058318465888376, 0.00043573284335007346 }, + { 5.8746987275204138e-05, 8.1719300404685839e-06 }, + { 4.0377437160051665e-05, 3.6322104525700624e-05 }, + { 0.00027118752408298414, 0.0017052910881401331 }, + { 0.0020804054042516834, 0.014521221263185681 }, + { 0.0050185729491574174, 0.015172422308838576 }, + { 0.0031563768516743671, 0.018014404162070886 }, + { 0.00095767707827339014, 0.0090651921519368864 }, + { 0.00011188725979229234, 0.00012337144007407299 }, + { 4.1608661444262527e-05, 4.3952533035071658e-06 }, + { 4.0280599295001368e-05, 9.4802293601276403e-06 }, + { 0.00025653733849894701, 0.0008256416137017563 }, + { 0.0069114607210125295, 0.053674519113438832 }, + { 0.029500839382709126, 0.063715261846741242 }, + { 0.017404386877025807, 0.09069253611048414 }, + { 0.00051596597896868136, 0.0017301072732714908 }, + { 0.00011127263579166702, 2.0181801589665096e-05 }, + { 4.5112611132714961e-05, 6.0513784241631926e-06 }, + { 2.5183773761956748e-05, 3.5869535727812522e-06 }, + { 9.2812176660344887e-05, 0.00013354336847027414 }, + { 0.0060660226808983489, 0.0090535953235263752 }, + { 0.10492061729846483, 0.32718081599363746 }, + { 0.0086636351698177252, 0.023380231766449773 }, + { 8.0239064467488506e-05, 5.2094818831137091e-05 }, + { 6.5246981931335008e-05, 1.1614614957154502e-05 }, + { 5.7073075607906221e-05, 7.8794401623574954e-06 }, + { 1.9130419054833346e-05, 4.2964391554966628e-06 }, + { 4.2436724004590545e-05, 5.7173866038876934e-06 }, + { 0.002147915230172459, 0.0011734061499269598 }, + { 0.076792089040495962, 0.042094101756627804 }, + { 0.00082434517207985848, 0.00066452712165359165 }, + { 3.9677832992137303e-05, 9.5414941318941517e-06 }, + { 4.8723280101018728e-05, 8.4505859378582021e-06 }, + { 2.9302347451034508e-05, 5.95058799319248e-06 }, + { 2.0699587725240132e-05, 7.5078989658380045e-06 }, + { 5.819165176338511e-05, 8.3458429409670686e-06 }, + { 4.0326053803086199e-05, 8.7035501567650893e-06 }, + { 0.033609017823416173, 0.0048741442141423058 }, + { 4.036953202821082e-05, 7.3241046505384695e-06 }, + { 3.4962421849076106e-05, 8.9387278290300855e-06 }, + { 5.3428809829278876e-05, 1.0683785682895565e-05 }, + { 2.1015792998873741e-05, 8.4347756741765206e-06 }, + { 1.8505913639406968e-05, 9.2667908004249543e-06 }, + { 2.1723302298628941e-05, 8.5335898221870237e-06 }, + { 2.0826069834693573e-05, 7.0731167145917918e-06 }, + { 3.9626449635171845e-05, 6.3003900771496599e-06 }, + { 2.1899191482087634e-05, 5.9189674658291187e-06 }, + { 1.8120538462166009e-05, 7.7509817699438406e-06 }, + { 1.9865596316031487e-05, 1.051184906535729e-05 }, + { 1.8248996854579662e-05, 9.7588852575172585e-06 }, + }, + // e2 pawn + { + { 9.6912963802780745e-05, 3.689522658416154e-05 }, + { 9.6958418310865577e-05, 4.39999638261167e-05 }, + { 0.00014934572702011376, 0.00021523697719647724 }, + { 0.00050307073265331073, 0.00082580762147041399 }, + { 0.00087729967399868694, 0.0010156157658178684 }, + { 0.00034547007170839954, 0.00060039476331181509 }, + { 0.00016167773269182449, 0.00011050781428606573 }, + { 0.0001328042386431556, 3.8355699691756778e-05 }, + { 4.3349766732207585e-05, 3.9525659204201132e-06 }, + { 0.00018115795383061504, 0.00075307645596876349 }, + { 0.00041589886756140531, 0.0010857500955098029 }, + { 0.0014923209074990168, 0.0030684816670190247 }, + { 0.0021698598761626313, 0.0041567159502098119 }, + { 0.00095063953465208213, 0.0029157110416288671 }, + { 0.00044731386149690438, 0.0018663660545290934 }, + { 0.00010130821710628792, 0.00013054337093667528 }, + { 3.2383372586001986e-05, 2.5750966971537033e-06 }, + { 7.1527609178882571e-05, 6.0201531533918742e-05 }, + { 0.00075988277448372696, 0.0090929075441708723 }, + { 0.0041874511028069982, 0.026185255152043195 }, + { 0.0051721538505612608, 0.016798942710750657 }, + { 0.0035640939077805026, 0.029962250070561205 }, + { 0.00040074077725659417, 0.0019891367045832627 }, + { 4.6798380497774139e-05, 2.4671916475262344e-05 }, + { 3.2693649010754963e-05, 3.8537517724096101e-06 }, + { 8.1100723838140081e-05, 1.1075089709017157e-05 }, + { 0.00043475063071884908, 0.0012773843253124915 }, + { 0.017204847515382281, 0.16293402217281971 }, + { 0.045354350064407849, 0.11284279457983687 }, + { 0.0064616014070628747, 0.033907460265803414 }, + { 0.00025814603282855796, 0.00059720306633107587 }, + { 5.5899163529541445e-05, 9.9565135535382647e-06 }, + { 3.7571115356553381e-05, 5.3893236324928236e-06 }, + { 5.0003911459234851e-05, 7.7944599950684626e-06 }, + { 5.9845800601080928e-05, 3.2754913782521477e-05 }, + { 0.0097826540126797045, 0.021906211239162303 }, + { 0.10805090128621554, 0.20487691852016185 }, + { 0.0049781638914700018, 0.007654966038604996 }, + { 9.9015728872444252e-05, 0.00010484576360506391 }, + { 3.82035259038206e-05, 5.7746988097337848e-06 }, + { 2.3887332140058953e-05, 5.4802326486624868e-06 }, + { 4.6760831121530145e-05, 6.8715358526503665e-06 }, + { 3.7889296913147202e-05, 8.5474238029084939e-06 }, + { 0.00045554903259209967, 0.00057683154157723063 }, + { 0.075783558249090457, 0.033791023602636722 }, + { 0.0013183941730198104, 0.00075155471808940172 }, + { 4.4367552456715768e-05, 7.6106656797689276e-06 }, + { 2.2169942247636412e-05, 4.7252925578622451e-06 }, + { 2.2863617566670143e-05, 8.8359611150991616e-06 }, + { 6.0768724743499025e-05, 9.9505847046576343e-06 }, + { 3.924897958977172e-05, 8.8932733209452539e-06 }, + { 4.3065181985937342e-05, 7.9150132556412759e-06 }, + { 0.019312507837938222, 0.0046774269845659576 }, + { 3.5387322685521273e-05, 8.1580960597471136e-06 }, + { 5.4464382100428947e-05, 9.1442612568919315e-06 }, + { 1.887943111888667e-05, 6.9703500006608688e-06 }, + { 2.0418955544890304e-05, 1.120947695031144e-05 }, + { 2.342685821033001e-05, 1.1047421747574216e-05 }, + { 1.9843857203469176e-05, 8.6304276872373172e-06 }, + { 2.4116580963443319e-05, 6.6324056144649496e-06 }, + { 3.8207478469741023e-05, 6.1422874403328558e-06 }, + { 1.8891288816647931e-05, 6.3418920193140707e-06 }, + { 1.9377454424859603e-05, 8.4802301822613522e-06 }, + { 1.7094847605816988e-05, 8.5118507096247135e-06 }, + }, + // f2 pawn + { + { 0.00011607697966793767, 3.9268742419373822e-06 }, + { 0.0001630710121787726, 6.1146194788899144e-06 }, + { 9.2693599682732279e-05, 2.5956500399398882e-05 }, + { 0.0001575888032471499, 0.00014375679880863972 }, + { 0.00044681979075685186, 0.00052079206195751427 }, + { 0.0010528410316563851, 0.0009958094579906433 }, + { 0.00033844636206781302, 0.00026659068991753557 }, + { 0.00017600380787038719, 6.4195599396503261e-05 }, + { 6.2130383703083754e-05, 2.45849600250131e-06 }, + { 0.00014367577120727109, 1.5104730664885461e-05 }, + { 0.00010586354932957209, 8.557107589413524e-05 }, + { 0.00027816775549844609, 0.00054712603240231325 }, + { 0.0011264022360013238, 0.001769962971730047 }, + { 0.0022240633889123126, 0.0031394816086475312 }, + { 0.00090919095212759664, 0.0018037356712370767 }, + { 0.0002528041399871102, 0.0004275253402163211 }, + { 4.2288502782574789e-05, 3.1146219452910491e-06 }, + { 9.4229171542815497e-05, 1.0999990956529175e-05 }, + { 0.0001057469486349197, 0.00016153741660164959 }, + { 0.00057892640151505331, 0.0022771068235643505 }, + { 0.0026099425183081274, 0.010455086266174137 }, + { 0.0064482456868177754, 0.012876574393962554 }, + { 0.001762144796339456, 0.010693396346931066 }, + { 0.00031138511949365668, 0.00061706273379822675 }, + { 4.1090875308687491e-05, 4.5849764676873313e-06 }, + { 9.0193601738066556e-05, 1.1189714120709339e-05 }, + { 0.00012390898903925012, 9.0590834613068772e-05 }, + { 0.00070284527196910447, 0.0019487474097254498 }, + { 0.013223481223383026, 0.044811771459096983 }, + { 0.017962724362661393, 0.035300085603091676 }, + { 0.0043177691774862097, 0.012820410408516345 }, + { 0.00024226462296030997, 0.00046634151383780683 }, + { 4.1444629958565095e-05, 6.4782555435685646e-06 }, + { 0.00011393666522203017, 1.58003822668794e-05 }, + { 6.3254888707443276e-05, 1.2272717182904451e-05 }, + { 0.00070404092316003156, 0.0013681688356556609 }, + { 0.0086278822347845667, 0.022967977164666996 }, + { 0.073632690452175437, 0.092047631834358018 }, + { 0.0047304723955009552, 0.010009029320639927 }, + { 0.00020155319397998281, 0.00039545619662099252 }, + { 6.0191650119117686e-05, 1.5932793225213476e-05 }, + { 8.4312183648481434e-05, 1.3557301107040988e-05 }, + { 5.9831966620359456e-05, 1.3709474894977162e-05 }, + { 4.9086916165697381e-05, 9.7905057848806198e-06 }, + { 0.011728903400743449, 0.017377562788406877 }, + { 0.071114429676674418, 0.044499898197712155 }, + { 0.0094253064803804434, 0.0078653393834363962 }, + { 2.3996027702870504e-05, 4.4743046219155675e-06 }, + { 4.3353719298128008e-05, 2.1958479970893937e-05 }, + { 0.00012179238998886515, 2.2122511456591373e-05 }, + { 6.2784533362913284e-05, 1.5272714716503315e-05 }, + { 5.754935980131684e-05, 9.5790435081381434e-06 }, + { 5.9865563430683027e-05, 8.0770684583784999e-06 }, + { 0.33497612579037878, 0.088089623230665492 }, + { 9.4547353099409305e-05, 1.0296434222694394e-05 }, + { 2.7559265880129238e-05, 8.138333230145013e-06 }, + { 3.9519730355320498e-05, 2.7359661301148021e-05 }, + { 4.2122495013917146e-05, 2.5349781530614395e-05 }, + { 3.3160051789364539e-05, 1.7250973959673582e-05 }, + { 2.911262428685434e-05, 9.1995971797778126e-06 }, + { 3.3620525719093482e-05, 6.1007854981684442e-06 }, + { 6.8748955336827238e-05, 7.1837885603635547e-06 }, + { 3.0810251349674782e-05, 8.3339852432058079e-06 }, + { 2.728258626569983e-05, 1.2049397208400714e-05 }, + }, + // g2 pawn + { + { 0.00015198999362087481, 2.8853731219066824e-06 }, + { 0.00016687140431125653, 4.1462416505206986e-06 }, + { 0.00010717580121515157, 7.2727212935730075e-06 }, + { 0.00010816987154413723, 2.6276658238952911e-05 }, + { 0.00016800579073041711, 0.00010143667549870157 }, + { 0.00038541272661720501, 0.00038227241299343119 }, + { 0.0012146847721168671, 0.00083074832887093913 }, + { 0.00036451748687890408, 0.00027086934252639036 }, + { 7.5039463999175844e-05, 2.7806301250155494e-06 }, + { 0.00016771725341822643, 6.4071093570010029e-06 }, + { 8.874103376231217e-05, 1.0559279856402331e-05 }, + { 9.9114543020454747e-05, 5.1806281518946418e-05 }, + { 0.00024820335325574118, 0.00038097794765449362 }, + { 0.00086800323895385887, 0.0016127397808305358 }, + { 0.002241150331386289, 0.0024737865037644555 }, + { 0.00089243404890797565, 0.0012674436220226348 }, + { 5.6938688366611938e-05, 3.7233170970357461e-06 }, + { 9.4484112044682586e-05, 8.4189654104948408e-06 }, + { 8.4503883095621803e-05, 1.6442674228947669e-05 }, + { 0.00010241691184696575, 0.00010298015249062562 }, + { 0.00047249763525886114, 0.0012500760473683088 }, + { 0.0025004366794828879, 0.009016178358240718 }, + { 0.004694972424686702, 0.0094397274171410962 }, + { 0.0017678285861330201, 0.0048032332052470091 }, + { 4.4529607659452989e-05, 5.3616556710498831e-06 }, + { 0.00010145050947942303, 1.1772717593971307e-05 }, + { 8.4725226787165327e-05, 1.5671923874465747e-05 }, + { 0.0001496125252197421, 9.1912967913449311e-05 }, + { 0.00083302895940702147, 0.0026732033358644511 }, + { 0.0052304423401896968, 0.019635402829392141 }, + { 0.021720537478767607, 0.033325114894767201 }, + { 0.0026130472588386171, 0.0082017738894507152 }, + { 4.556715621356327e-05, 7.1146186567562034e-06 }, + { 9.861651971448181e-05, 1.5102754381925251e-05 }, + { 0.00012063033560826163, 2.0075082309813753e-05 }, + { 7.3326026672673722e-05, 1.5337932054190249e-05 }, + { 0.00094435297855565402, 0.0015493920068239627 }, + { 0.0098343535749188006, 0.018758626870377909 }, + { 0.059500668473758726, 0.065784955797348596 }, + { 0.003237580342226438, 0.0064243959040539604 }, + { 5.1768732142702431e-05, 1.2067183755042605e-05 }, + { 0.00014822517458167465, 2.2486147521270022e-05 }, + { 8.1578984314510918e-05, 1.755927410146635e-05 }, + { 5.9448567726078704e-05, 1.155335018538799e-05 }, + { 5.2707466548802205e-05, 9.5928774888596137e-06 }, + { 0.018260937556225251, 0.01885835801368195 }, + { 0.13572349908898099, 0.050359930929384851 }, + { 0.0057292838273081577, 0.0079927760375596221 }, + { 8.2916927878573133e-05, 2.9162031360859594e-05 }, + { 0.000150138216487158, 2.7918949378887468e-05 }, + { 8.0855664751074035e-05, 1.9476268572870105e-05 }, + { 6.7735122178239478e-05, 1.1472322584019377e-05 }, + { 6.3879394122869651e-05, 9.6462371287852852e-06 }, + { 6.182801241017161e-05, 8.5829968961922744e-06 }, + { 0.38282501332963331, 0.068301216574493881 }, + { 2.7683771706622469e-05, 5.4881377805033267e-06 }, + { 5.3717347141469542e-05, 2.9980212506386556e-05 }, + { 5.0992052939339878e-05, 2.9747011117081768e-05 }, + { 3.9428821339150835e-05, 2.173713627935041e-05 }, + { 3.6490088577318479e-05, 1.1667974597080173e-05 }, + { 3.4140288137628722e-05, 8.9624432245526052e-06 }, + { 3.638534558042735e-05, 7.0671878657111614e-06 }, + { 7.482404915651294e-05, 6.0138290479192018e-06 }, + { 2.5405117453500276e-05, 6.4703504117277247e-06 }, + }, + // h2 pawn + { + { 0.0001930788926466021, 4.7608656511460256e-06 }, + { 0.00024419149884651476, 6.3181766237915501e-06 }, + { 0.00014692873295977686, 1.0499991367596029e-05 }, + { 0.00016419551718313213, 1.7689708776840214e-05 }, + { 0.00016504531885602245, 3.292092155117912e-05 }, + { 0.000247966199300516, 0.00017805321330012502 }, + { 0.00061177420059670465, 0.00050038694039334546 }, + { 0.0019319628385443858, 0.0016984373388341245 }, + { 0.00011633784901868539, 4.3853718887061155e-06 }, + { 0.00023885553485394762, 9.1501901057725619e-06 }, + { 0.00014160462666497095, 1.1233192345833961e-05 }, + { 0.00012061452534457995, 1.3355720245099561e-05 }, + { 0.00015872516594927068, 5.4701536055654154e-05 }, + { 0.00037919731670734439, 0.0010346117976314075 }, + { 0.0014973880970089953, 0.0028175569721270743 }, + { 0.0045679863630784055, 0.0042543186367657061 }, + { 7.4758831818826009e-05, 5.4525646872195455e-06 }, + { 0.00015956113364143953, 1.3573111370722667e-05 }, + { 0.00011565800768037314, 1.752765357410299e-05 }, + { 0.00011392678380722913, 1.7452554821615007e-05 }, + { 0.00014285166121286351, 0.00011344061819901745 }, + { 0.00068775635156790064, 0.0020612018627273222 }, + { 0.0035682539834117448, 0.023711027937178612 }, + { 0.011521178275078731, 0.0097330137372851483 }, + { 7.3776619187601616e-05, 8.6976213078844589e-06 }, + { 0.00014141687978375101, 1.82569019864205e-05 }, + { 0.00012209673756473751, 2.2039507572262548e-05 }, + { 0.00012193665864496048, 2.4501956140684278e-05 }, + { 0.00023556897629111831, 7.6687683987991035e-05 }, + { 0.00060708250484916594, 0.0020700437526913022 }, + { 0.007456171735637466, 0.024579379001933469 }, + { 0.024333596595303986, 0.022723246140572344 }, + { 6.2792438494754129e-05, 1.0021730891225197e-05 }, + { 0.00014987537085345005, 2.1248994388178526e-05 }, + { 0.00012647420432160278, 2.5428832849022797e-05 }, + { 0.00020137730479652413, 3.4794437797458252e-05 }, + { 8.4733131919006172e-05, 1.9027652340902422e-05 }, + { 0.00048215177751948727, 0.00079545982033342834 }, + { 0.0096873438143576553, 0.028228982720836342 }, + { 0.07236386540836362, 0.043188399275940516 }, + { 7.2551323752271388e-05, 1.5349789751951507e-05 }, + { 0.00016339314630128683, 2.559879318360086e-05 }, + { 0.00020434765808571983, 3.7171906198590952e-05 }, + { 8.7867516693899313e-05, 1.8298403928584913e-05 }, + { 8.5215344961297418e-05, 1.5517773803569364e-05 }, + { 7.1539466876643839e-05, 1.4057300695974132e-05 }, + { 0.011677103048073383, 0.0081560170100729718 }, + { 0.1775299587895991, 0.054488518444221992 }, + { 9.1764746691433549e-05, 3.0312228043701846e-05 }, + { 0.00029102347615461249, 5.3288493739103959e-05 }, + { 0.00011631610990612308, 2.8711438845931701e-05 }, + { 0.00011080228044713702, 1.8671921408064615e-05 }, + { 9.2284509109968795e-05, 1.542488850443949e-05 }, + { 8.5752893926474552e-05, 1.4658090715877988e-05 }, + { 0.00010854734158953735, 1.0335959881898596e-05 }, + { 0.38052643023914035, 0.0532775451315044 }, + { 0.00013887537989692089, 4.650589061966305e-05 }, + { 7.4391243188226948e-05, 3.9660046445495416e-05 }, + { 6.2831964153958327e-05, 3.3369537783146803e-05 }, + { 5.5648175593594772e-05, 1.8665992559183984e-05 }, + { 5.3992050472938743e-05, 1.543081735332012e-05 }, + { 4.5835930696151837e-05, 1.5970342601457466e-05 }, + { 4.1974273791901391e-05, 7.6739067344956494e-06 }, + { 8.378056353218492e-05, 3.673910023030495e-06 }, + }, + // a1 rook + { + { 0.0037913960924490621, 0.0084351946461640858 }, + { 0.0031569776416942707, 0.0056204439958405092 }, + { 0.0036927143553968935, 0.013013920130848271 }, + { 0.0055073709662720911, 0.025206773743047674 }, + { 0.0046011207231892864, 0.013264461426845942 }, + { 0.0030391160785132637, 0.0086647260780117613 }, + { 0.0021053777157368976, 0.0023927312344344002 }, + { 0.0027564048484892945, 0.0018008364641344484 }, + { 0.0070758874633020065, 0.0036351946398399801 }, + { 0.0073497291354005529, 0.0046388637751633788 }, + { 0.0069316761194125184, 0.0063736291473720846 }, + { 0.0069492729428902288, 0.0099253258321431899 }, + { 0.0053485667490044122, 0.0073291125515596413 }, + { 0.00466503569040544, 0.006592269283826043 }, + { 0.0040034393963818398, 0.0039536706625948699 }, + { 0.0042563482793658413, 0.0016458879749221393 }, + { 0.0033376158331063508, 0.003046920419923133 }, + { 0.002726847560536393, 0.0030289263635704207 }, + { 0.0032411771772140204, 0.005626307627383453 }, + { 0.0039709078025738226, 0.0072028893351739854 }, + { 0.0029277584625543073, 0.0055997780049255926 }, + { 0.0023196581719806333, 0.0040796013891024156 }, + { 0.002030678172406878, 0.0027635333011267723 }, + { 0.0021502373626507056, 0.0013073072256130319 }, + { 0.0023659466714746735, 0.0027522507017069329 }, + { 0.0022506641575567401, 0.0024821955877601491 }, + { 0.0026512073065173133, 0.0045074883891004546 }, + { 0.0032277503107823531, 0.0073214663127865887 }, + { 0.002608671768364712, 0.0051081934288370228 }, + { 0.0019066703692196174, 0.0029753750241976085 }, + { 0.0018321585727708177, 0.0019553481948125515 }, + { 0.0016388484550178711, 0.001081224407530922 }, + { 0.0019318126410394097, 0.002634561075143464 }, + { 0.0017902356823358816, 0.002810035239180515 }, + { 0.0021158460865771302, 0.0042202099691554407 }, + { 0.0031601693386750099, 0.0074926677530636658 }, + { 0.0023085969162523375, 0.0048788853169638505 }, + { 0.0019032296605858917, 0.0028022407791854463 }, + { 0.0017719708752176205, 0.0019421723163168308 }, + { 0.0014587893145131328, 0.00093572452715137689 }, + { 0.002192869738668357, 0.0030128572068209526 }, + { 0.0023862529788908314, 0.0028303534042944346 }, + { 0.0025609801079689229, 0.0051883198451757795 }, + { 0.0038248980411905434, 0.0069970317969066647 }, + { 0.0030151911969969604, 0.0051105550869744738 }, + { 0.0025695868202606381, 0.0033079399681758366 }, + { 0.0024737766223496545, 0.002148308510481541 }, + { 0.0014271766922816127, 0.00095518103289464484 }, + { 0.0032463906116630544, 0.003465759996529331 }, + { 0.0026139010130774281, 0.0041249610356051567 }, + { 0.0038314158223933161, 0.0059783942944426358 }, + { 0.0061613368317863203, 0.009474395372829101 }, + { 0.0042092751955365984, 0.0060580799996812649 }, + { 0.0031726890912279408, 0.0045493796590080271 }, + { 0.0019945161468009542, 0.0022707629552620764 }, + { 0.0009355545668167988, 0.00094901898262470994 }, + { 0.22759503620645244, 0.050923124142253667 }, + { 0.021995195355728719, 0.012230355557652348 }, + { 0.026273217530319186, 0.020690232001706495 }, + { 0.053618309673484535, 0.036060729246515086 }, + { 0.025382528539265075, 0.020454836938315877 }, + { 0.017525054762010314, 0.011241095501391841 }, + { 0.0082365288015889687, 0.004040514464715381 }, + { 0.0045695199586555284, 0.0022203835500404015 }, + }, + // b1 knight + { + { 0.001950715787553819, 0.0051982961215589199 }, + { 0.00022646424069343058, 0.00081697956548715559 }, + { 0.00067351130399070664, 0.0051937032399593918 }, + { 0.00061248763874534047, 0.002512932716640296 }, + { 0.00088165144907706948, 0.0037076175051998376 }, + { 0.00051172685201903074, 0.0039670896238946964 }, + { 0.00026948199188832285, 0.00097124623707819241 }, + { 0.0002643416799088165, 0.00079784321758344162 }, + { 0.00086508229273866847, 0.0015493208606373952 }, + { 0.0012074871495757822, 0.0030535745646501603 }, + { 0.0044317157241230412, 0.0066903126814820638 }, + { 0.0017306902767447528, 0.0065040499887652264 }, + { 0.0031600250700189146, 0.014243013982028031 }, + { 0.0017934254030336607, 0.0043521742875405065 }, + { 0.00064390658524675999, 0.0025433378299831279 }, + { 0.00050979009471802486, 0.00084077005976216431 }, + { 0.00082323845362214094, 0.0014650047244229934 }, + { 0.0021452314379124936, 0.0098976875149446517 }, + { 0.0022216602288326975, 0.0070609408352739376 }, + { 0.0061208289599508948, 0.025691095479257471 }, + { 0.003705421854831044, 0.011696927142447251 }, + { 0.0052999324016366027, 0.046805123575234371 }, + { 0.0012502064820436828, 0.0042434530330504707 }, + { 0.00093464152408918183, 0.0016563583220453322 }, + { 0.0010766236207995529, 0.0019365240996165505 }, + { 0.0068211801628242138, 0.01638010511042742 }, + { 0.0051380214675554731, 0.020617514670185567 }, + { 0.010305195085057004, 0.095771199919329711 }, + { 0.0040613879653411192, 0.017929663125020038 }, + { 0.0041292396882140116, 0.012171802246107245 }, + { 0.0041876724464985421, 0.0079591574881234875 }, + { 0.0018925616851666778, 0.0030881338247753533 }, + { 0.0045774606635896522, 0.006182943533390297 }, + { 0.0012798131770705896, 0.0039138090352874334 }, + { 0.0050344405250449436, 0.013113744159451442 }, + { 0.0042208562136834289, 0.017384129976683656 }, + { 0.010187584509811944, 0.088901618610526992 }, + { 0.0034679101923900395, 0.0087102675425468432 }, + { 0.0016534986406019081, 0.0038518624458996494 }, + { 0.0011109892051946455, 0.0017993147262550867 }, + { 0.0053197308043319872, 0.0066901861993726112 }, + { 0.0040064848484235235, 0.0038829394954489524 }, + { 0.056837077778212737, 0.13281887894732483 }, + { 0.0017464333468057861, 0.0029380212999666781 }, + { 0.0032146139579458371, 0.0064318998504538779 }, + { 0.0068161327361438376, 0.012106023644059613 }, + { 0.0055117345990482345, 0.0075817645177588154 }, + { 0.00068729785392113195, 0.00083338864290577973 }, + { 0.0010047995691766388, 0.00094986680801464006 }, + { 0.00077837485414241237, 0.00093547156293246995 }, + { 0.0014869730858086884, 0.0017317060861863007 }, + { 0.01753996779322806, 0.020857480876063154 }, + { 0.0071226107450472927, 0.0082888726320730927 }, + { 0.0012231985991094521, 0.0015672595810672218 }, + { 0.0005751260093825694, 0.00054141852721322663 }, + { 0.00062592636287476882, 0.00058044418682849457 }, + { 0.00016349196044929733, 0.00017339511436290992 }, + { 0.059128141112042093, 0.0048284406944044886 }, + { 0.00066679391820895261, 0.00057715960454862551 }, + { 0.0019113877566456388, 0.0011852737291030212 }, + { 0.00053495212936741933, 0.0005166339626092323 }, + { 0.0020487651140587205, 0.0012506610271245311 }, + { 0.00053381181409937811, 0.0003857842678137245 }, + { 0.00019481209280270632, 0.00011964614669407702 }, + }, + // c1 bishop + { + { 0, 0 }, + { 0.0010926611570216574, 0.0046427847205564353 }, + { 0, 0 }, + { 0.0022291997483258985, 0.010363695036962182 }, + { 0, 0 }, + { 0.0017388167522771364, 0.016607612828523841 }, + { 0, 0 }, + { 0.001568945350432281, 0.0023258004594209664 }, + { 0.0019498580807490878, 0.0025999168348509816 }, + { 0, 0 }, + { 0.0032817186458597696, 0.0053499679336232011 }, + { 0, 0 }, + { 0.002962011398820668, 0.041968477353979093 }, + { 0, 0 }, + { 0.0029398631956855941, 0.030133591826928458 }, + { 0, 0 }, + { 0, 0 }, + { 0.0034232402686404117, 0.010043817829588504 }, + { 0, 0 }, + { 0.0066337573920097334, 0.029194199318602933 }, + { 0, 0 }, + { 0.0084600997640286533, 0.11886393192214292 }, + { 0, 0 }, + { 0.01024041055333836, 0.026043166336052973 }, + { 0.002576646102994508, 0.0032387740171344048 }, + { 0, 0 }, + { 0.0070616661311203345, 0.023827035746942945 }, + { 0, 0 }, + { 0.0097806362277773305, 0.040550686029475515 }, + { 0, 0 }, + { 0.015996982895761097, 0.036582900753978825 }, + { 0, 0 }, + { 0, 0 }, + { 0.0049559623286950022, 0.014012101128391167 }, + { 0, 0 }, + { 0.0099871597734022422, 0.036717716848675475 }, + { 0, 0 }, + { 0.019206869584866112, 0.045870559126180641 }, + { 0, 0 }, + { 0.0043020399414058982, 0.0059718705843909816 }, + { 0.0069205239546680534, 0.0071672075463273931 }, + { 0, 0 }, + { 0.010688673030656164, 0.017688068461983241 }, + { 0, 0 }, + { 0.028560399444414686, 0.063743259847438546 }, + { 0, 0 }, + { 0.010493368843396366, 0.020945308867097848 }, + { 0, 0 }, + { 0, 0 }, + { 0.023465735648723261, 0.01701886150227987 }, + { 0, 0 }, + { 0.019433928686730564, 0.032627309144346632 }, + { 0, 0 }, + { 0.0046562313498177046, 0.0051732091856620133 }, + { 0, 0 }, + { 0.0029951951660055552, 0.0016165500543778208 }, + { 0.0018279075881234058, 0.0010923232126354616 }, + { 0, 0 }, + { 0.079809908693830006, 0.012578177406083397 }, + { 0, 0 }, + { 0.0025060532756558049, 0.0020279390442240271 }, + { 0, 0 }, + { 0.0010232461943272394, 0.00064346192158071269 }, + { 0, 0 }, + }, + // d1 queen + { + { 0.0046022748724380497, 0.001983946985529751 }, + { 0.0025841698122240279, 0.002056496332999062 }, + { 0.0038588822029743154, 0.0035888428992912132 }, + { 0.0057494814391615048, 0.033599634431921099 }, + { 0.0062728821946264959, 0.0058991117509278887 }, + { 0.0055042879648541636, 0.0046015792208360558 }, + { 0.0032654083825891557, 0.0020960832569750297 }, + { 0.0059252006622856216, 0.0015707180762475894 }, + { 0.0046573538785391038, 0.0015297477541994747 }, + { 0.0084257539424631624, 0.0036423724995514628 }, + { 0.0073938832492975656, 0.0054212287446024554 }, + { 0.0069803381347417707, 0.012154999888379538 }, + { 0.0075348594179811901, 0.013240623501779888 }, + { 0.016847314212484758, 0.0083421136950211517 }, + { 0.016866968346524049, 0.0057658608723357256 }, + { 0.013486065987740216, 0.0023175336677984074 }, + { 0.0033247462784694627, 0.0021635081027285164 }, + { 0.0029445568677160931, 0.0074149780936148477 }, + { 0.0056720684593271169, 0.0080362364761376003 }, + { 0.0056519558276410583, 0.011399292999790735 }, + { 0.0075598020852220013, 0.011387800914377114 }, + { 0.0080102325449471559, 0.018011698630698358 }, + { 0.007178207537283922, 0.0083900899401632111 }, + { 0.0082222817777288151, 0.003651746009631739 }, + { 0.0027431578238070065, 0.0028171775257987142 }, + { 0.0041682613952633589, 0.0054661397748732281 }, + { 0.0040766745140383438, 0.0073862607259200354 }, + { 0.0070159270382892337, 0.018413812924612298 }, + { 0.0065060895127801634, 0.01415221563770414 }, + { 0.0059504417482534244, 0.010467995346470228 }, + { 0.006558196189309062, 0.011334876056702688 }, + { 0.0093359271072219838, 0.0057454458693567559 }, + { 0.0053448651710199385, 0.0037540482970670128 }, + { 0.0034590959703875027, 0.005929313307125819 }, + { 0.0055480567035739352, 0.0071899901362926944 }, + { 0.0071004487079314969, 0.020756680563677639 }, + { 0.0068280675089405461, 0.01422041716266099 }, + { 0.006007989131771781, 0.010828216394193636 }, + { 0.0089964412203170988, 0.014046684103911883 }, + { 0.005397596352964263, 0.0048323517583827441 }, + { 0.0020611405979555557, 0.0017730677122605369 }, + { 0.0092834429606476841, 0.0085668328778607163 }, + { 0.006413328719476784, 0.0098845017550341311 }, + { 0.010786763859103231, 0.013859156590100511 }, + { 0.0079591831798019701, 0.013699332610825364 }, + { 0.013359184669128809, 0.022861564208674485 }, + { 0.0079161832151537197, 0.010476023007854602 }, + { 0.0041509392751171176, 0.0038681964245657853 }, + { 0.0012859534882279622, 0.00087947358525491807 }, + { 0.0031091515940571877, 0.0032201040720093005 }, + { 0.012766979622404105, 0.0089934412227835013 }, + { 0.014333695725657269, 0.017405845373850443 }, + { 0.015803267640001308, 0.019879959940586295 }, + { 0.0047060396092638785, 0.008964571681300753 }, + { 0.0031396199484547459, 0.0056514755908817276 }, + { 0.0012663210933012356, 0.0015302892557305724 }, + { 0.0013584336657936661, 0.0012097262781697001 }, + { 0.0019297691644585525, 0.0015419117758195676 }, + { 0.0032527700530586125, 0.0031449756752769151 }, + { 0.059384696237087677, 0.040692535715227553 }, + { 0.0041365183383564649, 0.0045422907320297537 }, + { 0.0027037072633552934, 0.0038109435072084998 }, + { 0.00097221659201165555, 0.0011920741187691039 }, + { 0.00061293823126026836, 0.00049537903937217317 }, + }, + // e1 king + { + { 0.00034806690751811557, 0.00086663367486243331 }, + { 0.00041714590210929786, 0.00067485320012068922 }, + { 0.0004093672523779111, 0.00066272079902795968 }, + { 0.00034937915940369503, 0.00066862197994714697 }, + { 0.0003780807168348257, 0.00074528792482257569 }, + { 0.00045270120884643701, 0.0006723808701374664 }, + { 0.00048865967730745894, 0.00069308836299454741 }, + { 0.0004198830540091888, 0.00089542416502677341 }, + { 0.00065544214888550603, 0.0010548410300121175 }, + { 0.0011448132880586407, 0.00074944404788789736 }, + { 0.0013858447104517794, 0.00077282149902422215 }, + { 0.0010629022882068144, 0.00071475237680437007 }, + { 0.0011683330315681005, 0.00082182145873967031 }, + { 0.001712186339388306, 0.00074528001969073479 }, + { 0.0014062201877715452, 0.00071694012204132258 }, + { 0.00093991622330998244, 0.0010903864553344557 }, + { 0.00088577595161502788, 0.001445892091914802 }, + { 0.0021886978053393537, 0.0010844002942479794 }, + { 0.0024623675408203616, 0.001209829044883631 }, + { 0.0021337255185181507, 0.0013002874685383659 }, + { 0.0023613103116500206, 0.0012870700881004809 }, + { 0.0033942699367266924, 0.0014380185806013249 }, + { 0.003497418073268936, 0.0014105818442647288 }, + { 0.001570148906755049, 0.0020540398132795211 }, + { 0.00096428774477529285, 0.002008039851097672 }, + { 0.0019988738507282174, 0.0016649551529222459 }, + { 0.0025174761911658191, 0.0018913996307860742 }, + { 0.0024237786397393003, 0.0019706130043972139 }, + { 0.0027617170970863393, 0.0023316522332661482 }, + { 0.0035780464654795855, 0.0025409900058263983 }, + { 0.0033726573062738351, 0.0029844896412100975 }, + { 0.0019141150271307287, 0.0036614041044582858 }, + { 0.0010731690781851056, 0.0024910849085151739 }, + { 0.0020330971427501752, 0.0020642156942416428 }, + { 0.0030260903975225192, 0.0027786973202804642 }, + { 0.0034381335370285543, 0.0031977404540315633 }, + { 0.004298543896849286, 0.0040285184271469055 }, + { 0.0050673061106732368, 0.0046072116272726539 }, + { 0.0045376800638835839, 0.0046535594152555008 }, + { 0.0027976617315666396, 0.0056393194743934753 }, + { 0.0015199513195657136, 0.0031254895252892439 }, + { 0.0033247838278457069, 0.0035820602961717722 }, + { 0.004503587206537, 0.0044082691030831091 }, + { 0.005688309552694123, 0.0063357003247997328 }, + { 0.0073748872174840266, 0.0076872209527985846 }, + { 0.0094901641345686173, 0.0087492971547280304 }, + { 0.0097389840881079437, 0.0092059548820608086 }, + { 0.006174062117767113, 0.0096613161677716886 }, + { 0.0024860611972303201, 0.0033422541692139638 }, + { 0.0047620672311858335, 0.0041002239017922069 }, + { 0.0062453308338782081, 0.0059438152714878399 }, + { 0.0084837953967215711, 0.0088483860060700036 }, + { 0.011102890081418432, 0.011778344071559024 }, + { 0.015483684898788699, 0.01236839299357414 }, + { 0.02491092418390423, 0.018222789366244316 }, + { 0.022915714361784242, 0.022005721038774798 }, + { 0.0023553063640169023, 0.0047672411399756632 }, + { 0.012817716734841578, 0.011950847882306879 }, + { 0.025443583825037804, 0.017487815662191077 }, + { 0.0047271759555233255, 0.009937549142252089 }, + { 0.052570944921910896, 0.040295725764778821 }, + { 0.012106061193435857, 0.020701809067287406 }, + { 0.1720090838818599, 0.10760425936092512 }, + { 0.031964125895105985, 0.04036572175466354 }, + }, + // f1 bishop + { + { 0.0019554865346197662, 0.0069580298526869195 }, + { 0, 0 }, + { 0.0010797856735358889, 0.0057872561116629594 }, + { 0, 0 }, + { 0.0013745601347489801, 0.004268073566168768 }, + { 0, 0 }, + { 0.0011222638994826438, 0.0039537101882540747 }, + { 0, 0 }, + { 0, 0 }, + { 0.0028157605309162433, 0.010987884247114927 }, + { 0, 0 }, + { 0.0021728302294518271, 0.035515909536327335 }, + { 0, 0 }, + { 0.0051533020874038171, 0.025437437585031551 }, + { 0, 0 }, + { 0.0022563143505399804, 0.0082444003366194864 }, + { 0.0033363608934266174, 0.013769259430806476 }, + { 0, 0 }, + { 0.0059256967093086347, 0.091110326280838469 }, + { 0, 0 }, + { 0.0069372116879840668, 0.037789715967348141 }, + { 0, 0 }, + { 0.005600681166238409, 0.02124336395802489 }, + { 0, 0 }, + { 0, 0 }, + { 0.010676613752032963, 0.022691171068128135 }, + { 0, 0 }, + { 0.011726604983660726, 0.047062184628717772 }, + { 0, 0 }, + { 0.0064378207942026675, 0.028253820645080259 }, + { 0, 0 }, + { 0.0039926034369110082, 0.0067834766365093262 }, + { 0.0034670248176238653, 0.004025565860404352 }, + { 0, 0 }, + { 0.031348567112640474, 0.052547763122787632 }, + { 0, 0 }, + { 0.010024377134108918, 0.046296758380530663 }, + { 0, 0 }, + { 0.0052608968606065332, 0.01794330935886029 }, + { 0, 0 }, + { 0, 0 }, + { 0.017103906886906592, 0.019944819571057426 }, + { 0, 0 }, + { 0.032741911816926254, 0.065635778054380103 }, + { 0, 0 }, + { 0.012791177230968917, 0.02503382329235081 }, + { 0, 0 }, + { 0.0048651600318051916, 0.0062692774545070728 }, + { 0.0053074205377728386, 0.0028274956991339705 }, + { 0, 0 }, + { 0.010702463533152511, 0.0072165217350335141 }, + { 0, 0 }, + { 0.024249207336620057, 0.038543616533311308 }, + { 0, 0 }, + { 0.024597001517089663, 0.021263385680694778 }, + { 0, 0 }, + { 0, 0 }, + { 0.0044353066302617429, 0.0017776744278407866 }, + { 0, 0 }, + { 0.0030594441250419843, 0.0025951856134442388 }, + { 0, 0 }, + { 0.045030140844785391, 0.009073113094041409 }, + { 0, 0 }, + { 0.001060236282493491, 0.0005417525190335021 }, + }, + // g1 knight + { + { 0.00039352141560294683, 0.0011423034086991738 }, + { 0.00025387923791746447, 0.0011903270846322783 }, + { 0.00041976842959749662, 0.0024105770695650969 }, + { 0.0011514832430493495, 0.0054476358375167818 }, + { 0.00046605692909153657, 0.0018370419679654968 }, + { 0.00068417335056103988, 0.0083883527874411869 }, + { 0.00017915993175784267, 0.00064634531841965912 }, + { 0.0017142159819884418, 0.0033520664141114065 }, + { 0.00041750953817397651, 0.00056421890372517001 }, + { 0.00067497968223014264, 0.0014259039660552374 }, + { 0.0012284950374428151, 0.0015820520590243941 }, + { 0.0018210696490810791, 0.019894453999816476 }, + { 0.0022254586446822208, 0.0084037994150581892 }, + { 0.004234231696758131, 0.018327560031096892 }, + { 0.00078819302788873599, 0.0033806592759797259 }, + { 0.00077342426532708624, 0.0024725967814224091 }, + { 0.00039030995579260552, 0.00055741060892724645 }, + { 0.00074126026014966753, 0.001817654632125836 }, + { 0.0037077499161581717, 0.050540954495974171 }, + { 0.0031082998161013368, 0.0095022135317770172 }, + { 0.0046238242618361798, 0.024614179368579809 }, + { 0.002491252892566792, 0.012526408673940694 }, + { 0.0025733002559428725, 0.018208230089676449 }, + { 0.001358028527786823, 0.0028774087015770358 }, + { 0.00080964557942181609, 0.0011677757197733213 }, + { 0.0017689353045907377, 0.0035872559440741645 }, + { 0.0023979268823367925, 0.0066367534369774113 }, + { 0.0021418994248415795, 0.008681619344755637 }, + { 0.014225448779077684, 0.12649948098066385 }, + { 0.005081740881414611, 0.02237463773152313 }, + { 0.013125044545417923, 0.032871840563862303 }, + { 0.0014478209440839669, 0.0030799954915452085 }, + { 0.00036569535152318927, 0.00046415772116677472 }, + { 0.00083442026261100943, 0.0018716802794090984 }, + { 0.0026421104760514665, 0.0069345298720070621 }, + { 0.0088254966968248499, 0.088696713640646491 }, + { 0.0033409616801579863, 0.018507781226804368 }, + { 0.0040306389787632116, 0.010388323475212321 }, + { 0.0024989406332820091, 0.010548886584314587 }, + { 0.0050412231281643845, 0.012531505507695077 }, + { 0.00043706683434821525, 0.00055786317772513454 }, + { 0.0029956595925012047, 0.0032561396155057708 }, + { 0.0023091581806130371, 0.0039225521111034027 }, + { 0.0022525831283111042, 0.0046571068431690774 }, + { 0.001859417443640995, 0.0031376910962855808 }, + { 0.051723846804110137, 0.15000158814098682 }, + { 0.0037861747528681873, 0.004825114610182455 }, + { 0.0040581448850034148, 0.0073632923653564747 }, + { 0.00016480421233487682, 0.00026280017919985265 }, + { 0.00027502348930875188, 0.00038888110321237364 }, + { 0.00097030552638913245, 0.0011853053496303845 }, + { 0.0055140152295843174, 0.007219326080554052 }, + { 0.0097580255744295664, 0.012326209233788457 }, + { 0.0013020918148810377, 0.0017413542995980461 }, + { 0.0010883508838854393, 0.00097015928145007695 }, + { 0.0033318767073899007, 0.0023949011931247107 }, + { 0.0001420611480287795, 0.00015406113816317495 }, + { 0.00033875663849256601, 0.00031466377292464521 }, + { 0.00061860028194127021, 0.00053243632115907195 }, + { 0.00027837921777518855, 0.0002782290202702126 }, + { 0.0020900318785508666, 0.0013795897748827147 }, + { 0.0010462066497589598, 0.00074809424662607388 }, + { 0.031938406548661813, 0.0028957644177114669 }, + { 0.00016350974699593922, 9.3492017998657136e-05 }, + }, + // h1 rook + { + { 0.0027870807125976748, 0.0018825241440117708 }, + { 0.0025532113396523372, 0.0025641342555734184 }, + { 0.0030148611577426056, 0.0064044552089854408 }, + { 0.0043897888811221843, 0.016697023822209663 }, + { 0.0053796437985537153, 0.023380342438295544 }, + { 0.0037052084162713414, 0.016883681771518545 }, + { 0.0024404130134153884, 0.0039782160969606788 }, + { 0.0037223368606874819, 0.0047704308606734422 }, + { 0.0049824820697380616, 0.0016459354057131842 }, + { 0.0051148969806380559, 0.0026395709524475964 }, + { 0.0050791045199456908, 0.0040131745662438352 }, + { 0.0053742643563360233, 0.0072684584512278348 }, + { 0.0065476823639607443, 0.010768696680280991 }, + { 0.0063677062273403348, 0.00957553758216673 }, + { 0.0049556263605917668, 0.0057329656424630294 }, + { 0.0059196611411481527, 0.0035957361742564261 }, + { 0.0023602806682277511, 0.0010713528741446727 }, + { 0.002177628644479217, 0.0018021566211518687 }, + { 0.0025090908225656478, 0.0031516614405313059 }, + { 0.0030144303280572795, 0.0049896006409607379 }, + { 0.0037354850712217596, 0.0087936113475448208 }, + { 0.0034136928456596368, 0.0091935517302025298 }, + { 0.0024853754270431272, 0.004473751262686709 }, + { 0.0030866456837063154, 0.0031290725262961049 }, + { 0.0015878445443807698, 0.00090496368287570732 }, + { 0.001683095454214014, 0.0014941054910120864 }, + { 0.0019921584412294236, 0.0026590017665123816 }, + { 0.0024335315961479366, 0.0052282387846890625 }, + { 0.0037554830784961254, 0.0090342692524584805 }, + { 0.0029805350990067172, 0.0067331031601365323 }, + { 0.0024882113930910286, 0.0032167364858451024 }, + { 0.0025501836741572957, 0.0036285345662640722 }, + { 0.0010802678865781802, 0.00082254082573718671 }, + { 0.0012685503404803525, 0.0015379315419377048 }, + { 0.0015527734269688823, 0.0025829524219205383 }, + { 0.0022952451485731586, 0.0053369620154620585 }, + { 0.0035913824228950833, 0.0088715855917399083 }, + { 0.0034835089937949775, 0.0066256763709854338 }, + { 0.002754244771213785, 0.0037485917798138727 }, + { 0.0027042369071886298, 0.0027975708225504701 }, + { 0.00097810393895012135, 0.000912487392105227 }, + { 0.0013745364193534575, 0.0015487319283152526 }, + { 0.0017664491406267934, 0.00318594797360799 }, + { 0.0027951894015834167, 0.0052249265344477503 }, + { 0.0047736601070304261, 0.0083041908012976805 }, + { 0.0058562264106913307, 0.0090117119587506418 }, + { 0.00503224487467615, 0.0046648479435242203 }, + { 0.003929186493000828, 0.0032425447650224859 }, + { 0.0010470564514318502, 0.0013328961373818317 }, + { 0.0014861805963416442, 0.0022012807989470113 }, + { 0.0023995355766664034, 0.003811046273922431 }, + { 0.0039884453375627262, 0.0065880558485548755 }, + { 0.0062335245194739125, 0.0092058659493275997 }, + { 0.0081813430762080631, 0.015924326829011935 }, + { 0.0037185246108572367, 0.0046050140006209011 }, + { 0.0026837606394378931, 0.0027412526870333638 }, + { 0.0045956325854087836, 0.0033844280475848463 }, + { 0.0062515521726369486, 0.004775849828550339 }, + { 0.010781601808011161, 0.010339612052809062 }, + { 0.023124316957083293, 0.021721691628016369 }, + { 0.051024687299861822, 0.034859082013086726 }, + { 0.11830833949353907, 0.040456308636710687 }, + { 0.015851429655741628, 0.0077185015594927889 }, + { 0.12512746036951874, 0.025984152550578139 }, + }, +}; diff --git a/chess.js b/chess.js new file mode 100644 index 0000000..11565d8 --- /dev/null +++ b/chess.js @@ -0,0 +1,1789 @@ +/** + * @license + * Copyright (c) 2023, Jeff Hlywa (jhlywa@gmail.com) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +export const WHITE = "w"; +export const BLACK = "b"; +export const PAWN = "p"; +export const KNIGHT = "n"; +export const BISHOP = "b"; +export const ROOK = "r"; +export const QUEEN = "q"; +export const KING = "k"; +export const PIECE_SYMBOLS = ["p", "n", "b", "r", "q", "k"]; +export const DEFAULT_POSITION = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"; +const EMPTY = -1; +const FLAGS = { + NORMAL: "n", + CAPTURE: "c", + BIG_PAWN: "b", + EP_CAPTURE: "e", + PROMOTION: "p", + KSIDE_CASTLE: "k", + QSIDE_CASTLE: "q", +}; +// prettier-ignore +export const SQUARES = [ + 'a8', 'b8', 'c8', 'd8', 'e8', 'f8', 'g8', 'h8', + 'a7', 'b7', 'c7', 'd7', 'e7', 'f7', 'g7', 'h7', + 'a6', 'b6', 'c6', 'd6', 'e6', 'f6', 'g6', 'h6', + 'a5', 'b5', 'c5', 'd5', 'e5', 'f5', 'g5', 'h5', + 'a4', 'b4', 'c4', 'd4', 'e4', 'f4', 'g4', 'h4', + 'a3', 'b3', 'c3', 'd3', 'e3', 'f3', 'g3', 'h3', + 'a2', 'b2', 'c2', 'd2', 'e2', 'f2', 'g2', 'h2', + 'a1', 'b1', 'c1', 'd1', 'e1', 'f1', 'g1', 'h1' +]; +const BITS = { + NORMAL: 1, + CAPTURE: 2, + BIG_PAWN: 4, + EP_CAPTURE: 8, + PROMOTION: 16, + KSIDE_CASTLE: 32, + QSIDE_CASTLE: 64, +}; +/* + * NOTES ABOUT 0x88 MOVE GENERATION ALGORITHM + * ---------------------------------------------------------------------------- + * From https://github.com/jhlywa/chess.js/issues/230 + * + * A lot of people are confused when they first see the internal representation + * of chess.js. It uses the 0x88 Move Generation Algorithm which internally + * stores the board as an 8x16 array. This is purely for efficiency but has a + * couple of interesting benefits: + * + * 1. 0x88 offers a very inexpensive "off the board" check. Bitwise AND (&) any + * square with 0x88, if the result is non-zero then the square is off the + * board. For example, assuming a knight square A8 (0 in 0x88 notation), + * there are 8 possible directions in which the knight can move. These + * directions are relative to the 8x16 board and are stored in the + * PIECE_OFFSETS map. One possible move is A8 - 18 (up one square, and two + * squares to the left - which is off the board). 0 - 18 = -18 & 0x88 = 0x88 + * (because of two-complement representation of -18). The non-zero result + * means the square is off the board and the move is illegal. Take the + * opposite move (from A8 to C7), 0 + 18 = 18 & 0x88 = 0. A result of zero + * means the square is on the board. + * + * 2. The relative distance (or difference) between two squares on a 8x16 board + * is unique and can be used to inexpensively determine if a piece on a + * square can attack any other arbitrary square. For example, let's see if a + * pawn on E7 can attack E2. The difference between E7 (20) - E2 (100) is + * -80. We add 119 to make the ATTACKS array index non-negative (because the + * worst case difference is A8 - H1 = -119). The ATTACKS array contains a + * bitmask of pieces that can attack from that distance and direction. + * ATTACKS[-80 + 119=39] gives us 24 or 0b11000 in binary. Look at the + * PIECE_MASKS map to determine the mask for a given piece type. In our pawn + * example, we would check to see if 24 & 0x1 is non-zero, which it is + * not. So, naturally, a pawn on E7 can't attack a piece on E2. However, a + * rook can since 24 & 0x8 is non-zero. The only thing left to check is that + * there are no blocking pieces between E7 and E2. That's where the RAYS + * array comes in. It provides an offset (in this case 16) to add to E7 (20) + * to check for blocking pieces. E7 (20) + 16 = E6 (36) + 16 = E5 (52) etc. + */ +// prettier-ignore +// eslint-disable-next-line +export const Ox88 = { + a8: 0, b8: 1, c8: 2, d8: 3, e8: 4, f8: 5, g8: 6, h8: 7, + a7: 16, b7: 17, c7: 18, d7: 19, e7: 20, f7: 21, g7: 22, h7: 23, + a6: 32, b6: 33, c6: 34, d6: 35, e6: 36, f6: 37, g6: 38, h6: 39, + a5: 48, b5: 49, c5: 50, d5: 51, e5: 52, f5: 53, g5: 54, h5: 55, + a4: 64, b4: 65, c4: 66, d4: 67, e4: 68, f4: 69, g4: 70, h4: 71, + a3: 80, b3: 81, c3: 82, d3: 83, e3: 84, f3: 85, g3: 86, h3: 87, + a2: 96, b2: 97, c2: 98, d2: 99, e2: 100, f2: 101, g2: 102, h2: 103, + a1: 112, b1: 113, c1: 114, d1: 115, e1: 116, f1: 117, g1: 118, h1: 119 +}; +const PAWN_OFFSETS = { + b: [16, 32, 17, 15], + w: [-16, -32, -17, -15], +}; +const PIECE_OFFSETS = { + n: [-18, -33, -31, -14, 18, 33, 31, 14], + b: [-17, -15, 17, 15], + r: [-16, 1, 16, -1], + q: [-17, -16, -15, 1, 17, 16, 15, -1], + k: [-17, -16, -15, 1, 17, 16, 15, -1], +}; +// prettier-ignore +const ATTACKS = [ + 20, 0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 0, 0, 0, 20, 0, + 0, 20, 0, 0, 0, 0, 0, 24, 0, 0, 0, 0, 0, 20, 0, 0, + 0, 0, 20, 0, 0, 0, 0, 24, 0, 0, 0, 0, 20, 0, 0, 0, + 0, 0, 0, 20, 0, 0, 0, 24, 0, 0, 0, 20, 0, 0, 0, 0, + 0, 0, 0, 0, 20, 0, 0, 24, 0, 0, 20, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 20, 2, 24, 2, 20, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 2, 53, 56, 53, 2, 0, 0, 0, 0, 0, 0, + 24, 24, 24, 24, 24, 24, 56, 0, 56, 24, 24, 24, 24, 24, 24, 0, + 0, 0, 0, 0, 0, 2, 53, 56, 53, 2, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 20, 2, 24, 2, 20, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 20, 0, 0, 24, 0, 0, 20, 0, 0, 0, 0, 0, + 0, 0, 0, 20, 0, 0, 0, 24, 0, 0, 0, 20, 0, 0, 0, 0, + 0, 0, 20, 0, 0, 0, 0, 24, 0, 0, 0, 0, 20, 0, 0, 0, + 0, 20, 0, 0, 0, 0, 0, 24, 0, 0, 0, 0, 0, 20, 0, 0, + 20, 0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 0, 0, 0, 20 +]; +// prettier-ignore +const RAYS = [ + 17, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 15, 0, + 0, 17, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 15, 0, 0, + 0, 0, 17, 0, 0, 0, 0, 16, 0, 0, 0, 0, 15, 0, 0, 0, + 0, 0, 0, 17, 0, 0, 0, 16, 0, 0, 0, 15, 0, 0, 0, 0, + 0, 0, 0, 0, 17, 0, 0, 16, 0, 0, 15, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 17, 0, 16, 0, 15, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 17, 16, 15, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 0, -1, -1, -1, -1, -1, -1, -1, 0, + 0, 0, 0, 0, 0, 0, -15, -16, -17, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, -15, 0, -16, 0, -17, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, -15, 0, 0, -16, 0, 0, -17, 0, 0, 0, 0, 0, + 0, 0, 0, -15, 0, 0, 0, -16, 0, 0, 0, -17, 0, 0, 0, 0, + 0, 0, -15, 0, 0, 0, 0, -16, 0, 0, 0, 0, -17, 0, 0, 0, + 0, -15, 0, 0, 0, 0, 0, -16, 0, 0, 0, 0, 0, -17, 0, 0, + -15, 0, 0, 0, 0, 0, 0, -16, 0, 0, 0, 0, 0, 0, -17 +]; +const PIECE_MASKS = { p: 0x1, n: 0x2, b: 0x4, r: 0x8, q: 0x10, k: 0x20 }; +const SYMBOLS = "pnbrqkPNBRQK"; +const PROMOTIONS = [KNIGHT, BISHOP, ROOK, QUEEN]; +const RANK_1 = 7; +const RANK_2 = 6; +/* + * const RANK_3 = 5 + * const RANK_4 = 4 + * const RANK_5 = 3 + * const RANK_6 = 2 + */ +const RANK_7 = 1; +const RANK_8 = 0; +const ROOKS = { + w: [ + { square: Ox88.a1, flag: BITS.QSIDE_CASTLE }, + { square: Ox88.h1, flag: BITS.KSIDE_CASTLE }, + ], + b: [ + { square: Ox88.a8, flag: BITS.QSIDE_CASTLE }, + { square: Ox88.h8, flag: BITS.KSIDE_CASTLE }, + ], +}; +const SECOND_RANK = { b: RANK_7, w: RANK_2 }; +const TERMINATION_MARKERS = ["1-0", "0-1", "1/2-1/2", "*"]; +// Extracts the zero-based rank of an 0x88 square. +export function rank(square) { + return square >> 4; +} +// Extracts the zero-based file of an 0x88 square. +export function file(square) { + return square & 0xf; +} +function isDigit(c) { + return "0123456789".indexOf(c) !== -1; +} +// Converts a 0x88 square to algebraic notation. +function algebraic(square) { + const f = file(square); + const r = rank(square); + return ("abcdefgh".substring(f, f + 1) + + "87654321".substring(r, r + 1)); +} +function swapColor(color) { + return color === WHITE ? BLACK : WHITE; +} +export function validateFen(fen) { + // 1st criterion: 6 space-seperated fields? + const tokens = fen.split(/\s+/); + if (tokens.length !== 6) { + return { + ok: false, + error: "Invalid FEN: must contain six space-delimited fields", + }; + } + // 2nd criterion: move number field is a integer value > 0? + const moveNumber = parseInt(tokens[5], 10); + if (isNaN(moveNumber) || moveNumber <= 0) { + return { + ok: false, + error: "Invalid FEN: move number must be a positive integer", + }; + } + // 3rd criterion: half move counter is an integer >= 0? + const halfMoves = parseInt(tokens[4], 10); + if (isNaN(halfMoves) || halfMoves < 0) { + return { + ok: false, + error: "Invalid FEN: half move counter number must be a non-negative integer", + }; + } + // 4th criterion: 4th field is a valid e.p.-string? + if (!/^(-|[abcdefgh][36])$/.test(tokens[3])) { + return { + ok: false, + error: "Invalid FEN: en-passant square is invalid", + }; + } + // 5th criterion: 3th field is a valid castle-string? + if (/[^kKqQ-]/.test(tokens[2])) { + return { + ok: false, + error: "Invalid FEN: castling availability is invalid", + }; + } + // 6th criterion: 2nd field is "w" (white) or "b" (black)? + if (!/^(w|b)$/.test(tokens[1])) { + return { ok: false, error: "Invalid FEN: side-to-move is invalid" }; + } + // 7th criterion: 1st field contains 8 rows? + const rows = tokens[0].split("/"); + if (rows.length !== 8) { + return { + ok: false, + error: "Invalid FEN: piece data does not contain 8 '/'-delimited rows", + }; + } + // 8th criterion: every row is valid? + for (let i = 0; i < rows.length; i++) { + // check for right sum of fields AND not two numbers in succession + let sumFields = 0; + let previousWasNumber = false; + for (let k = 0; k < rows[i].length; k++) { + if (isDigit(rows[i][k])) { + if (previousWasNumber) { + return { + ok: false, + error: "Invalid FEN: piece data is invalid (consecutive number)", + }; + } + sumFields += parseInt(rows[i][k], 10); + previousWasNumber = true; + } + else { + if (!/^[prnbqkPRNBQK]$/.test(rows[i][k])) { + return { + ok: false, + error: "Invalid FEN: piece data is invalid (invalid piece)", + }; + } + sumFields += 1; + previousWasNumber = false; + } + } + if (sumFields !== 8) { + return { + ok: false, + error: "Invalid FEN: piece data is invalid (too many squares in rank)", + }; + } + } + if ((tokens[3][1] == "3" && tokens[1] == "w") || + (tokens[3][1] == "6" && tokens[1] == "b")) { + return { ok: false, error: "Invalid FEN: illegal en-passant square" }; + } + const kings = [ + { color: "white", regex: /K/g }, + { color: "black", regex: /k/g }, + ]; + for (const { color, regex } of kings) { + if (!regex.test(tokens[0])) { + return { ok: false, error: `Invalid FEN: missing ${color} king` }; + } + if ((tokens[0].match(regex) || []).length > 1) { + return { ok: false, error: `Invalid FEN: too many ${color} kings` }; + } + } + return { ok: true }; +} +// this function is used to uniquely identify ambiguous moves +function getDisambiguator(move, moves) { + const from = move.from; + const to = move.to; + const piece = move.piece; + let ambiguities = 0; + let sameRank = 0; + let sameFile = 0; + for (let i = 0, len = moves.length; i < len; i++) { + const ambigFrom = moves[i].from; + const ambigTo = moves[i].to; + const ambigPiece = moves[i].piece; + /* + * if a move of the same piece type ends on the same to square, we'll need + * to add a disambiguator to the algebraic notation + */ + if (piece === ambigPiece && from !== ambigFrom && to === ambigTo) { + ambiguities++; + if (rank(from) === rank(ambigFrom)) { + sameRank++; + } + if (file(from) === file(ambigFrom)) { + sameFile++; + } + } + } + if (ambiguities > 0) { + if (sameRank > 0 && sameFile > 0) { + /* + * if there exists a similar moving piece on the same rank and file as + * the move in question, use the square as the disambiguator + */ + return algebraic(from); + } + else if (sameFile > 0) { + /* + * if the moving piece rests on the same file, use the rank symbol as the + * disambiguator + */ + return algebraic(from).charAt(1); + } + else { + // else use the file symbol + return algebraic(from).charAt(0); + } + } + return ""; +} +function addMove(moves, color, from, to, piece, captured = undefined, flags = BITS.NORMAL) { + const r = rank(to); + if (piece === PAWN && (r === RANK_1 || r === RANK_8)) { + for (let i = 0; i < PROMOTIONS.length; i++) { + const promotion = PROMOTIONS[i]; + moves.push({ + color, + from, + to, + piece, + captured, + promotion, + flags: flags | BITS.PROMOTION, + }); + } + } + else { + moves.push({ + color, + from, + to, + piece, + captured, + flags, + }); + } +} +function inferPieceType(san) { + let pieceType = san.charAt(0); + if (pieceType >= "a" && pieceType <= "h") { + const matches = san.match(/[a-h]\d.*[a-h]\d/); + if (matches) { + return undefined; + } + return PAWN; + } + pieceType = pieceType.toLowerCase(); + if (pieceType === "o") { + return KING; + } + return pieceType; +} +// parses all of the decorators out of a SAN string +function strippedSan(move) { + return move.replace(/=/, "").replace(/[+#]?[?!]*$/, ""); +} +export class Chess { + constructor(fen = DEFAULT_POSITION) { + this._board = new Array(128); + this._turn = WHITE; + this._header = {}; + this._kings = { w: EMPTY, b: EMPTY }; + this._epSquare = -1; + this._halfMoves = 0; + this._moveNumber = 0; + this._history = []; + this._comments = {}; + this._castling = { w: 0, b: 0 }; + this.load(fen); + } + clear(keepHeaders = false) { + this._board = new Array(128); + this._kings = { w: EMPTY, b: EMPTY }; + this._turn = WHITE; + this._castling = { w: 0, b: 0 }; + this._epSquare = EMPTY; + this._halfMoves = 0; + this._moveNumber = 1; + this._history = []; + this._comments = {}; + this._header = keepHeaders ? this._header : {}; + this._updateSetup(this.fen()); + } + load(fen, keepHeaders = false) { + let tokens = fen.split(/\s+/); + // append commonly omitted fen tokens + if (tokens.length >= 2 && tokens.length < 6) { + const adjustments = ["-", "-", "0", "1"]; + fen = tokens + .concat(adjustments.slice(-(6 - tokens.length))) + .join(" "); + } + tokens = fen.split(/\s+/); + const { ok, error } = validateFen(fen); + if (!ok) { + throw new Error(error); + } + const position = tokens[0]; + let square = 0; + this.clear(keepHeaders); + for (let i = 0; i < position.length; i++) { + const piece = position.charAt(i); + if (piece === "/") { + square += 8; + } + else if (isDigit(piece)) { + square += parseInt(piece, 10); + } + else { + const color = piece < "a" ? WHITE : BLACK; + this.put({ type: piece.toLowerCase(), color }, algebraic(square)); + square++; + } + } + this._turn = tokens[1]; + if (tokens[2].indexOf("K") > -1) { + this._castling.w |= BITS.KSIDE_CASTLE; + } + if (tokens[2].indexOf("Q") > -1) { + this._castling.w |= BITS.QSIDE_CASTLE; + } + if (tokens[2].indexOf("k") > -1) { + this._castling.b |= BITS.KSIDE_CASTLE; + } + if (tokens[2].indexOf("q") > -1) { + this._castling.b |= BITS.QSIDE_CASTLE; + } + this._epSquare = tokens[3] === "-" ? EMPTY : Ox88[tokens[3]]; + this._halfMoves = parseInt(tokens[4], 10); + this._moveNumber = parseInt(tokens[5], 10); + this._updateSetup(this.fen()); + } + fen() { + var _a, _b; + let empty = 0; + let fen = ""; + for (let i = Ox88.a8; i <= Ox88.h1; i++) { + if (this._board[i]) { + if (empty > 0) { + fen += empty; + empty = 0; + } + const { color, type: piece } = this._board[i]; + fen += + color === WHITE ? piece.toUpperCase() : piece.toLowerCase(); + } + else { + empty++; + } + if ((i + 1) & 0x88) { + if (empty > 0) { + fen += empty; + } + if (i !== Ox88.h1) { + fen += "/"; + } + empty = 0; + i += 8; + } + } + let castling = ""; + if (this._castling[WHITE] & BITS.KSIDE_CASTLE) { + castling += "K"; + } + if (this._castling[WHITE] & BITS.QSIDE_CASTLE) { + castling += "Q"; + } + if (this._castling[BLACK] & BITS.KSIDE_CASTLE) { + castling += "k"; + } + if (this._castling[BLACK] & BITS.QSIDE_CASTLE) { + castling += "q"; + } + // do we have an empty castling flag? + castling = castling || "-"; + let epSquare = "-"; + /* + * only print the ep square if en passant is a valid move (pawn is present + * and ep capture is not pinned) + */ + if (this._epSquare !== EMPTY) { + const bigPawnSquare = this._epSquare + (this._turn === WHITE ? 16 : -16); + const squares = [bigPawnSquare + 1, bigPawnSquare - 1]; + for (const square of squares) { + // is the square off the board? + if (square & 0x88) { + continue; + } + const color = this._turn; + // is there a pawn that can capture the epSquare? + if (((_a = this._board[square]) === null || _a === void 0 ? void 0 : _a.color) === color && + ((_b = this._board[square]) === null || _b === void 0 ? void 0 : _b.type) === PAWN) { + // if the pawn makes an ep capture, does it leave it's king in check? + this._makeMove({ + color, + from: square, + to: this._epSquare, + piece: PAWN, + captured: PAWN, + flags: BITS.EP_CAPTURE, + }); + const isLegal = !this._isKingAttacked(color); + this._undoMove(); + // if ep is legal, break and set the ep square in the FEN output + if (isLegal) { + epSquare = algebraic(this._epSquare); + break; + } + } + } + } + return [ + fen, + this._turn, + castling, + epSquare, + this._halfMoves, + this._moveNumber, + ].join(" "); + } + /* + * Called when the initial board setup is changed with put() or remove(). + * modifies the SetUp and FEN properties of the header object. If the FEN + * is equal to the default position, the SetUp and FEN are deleted the setup + * is only updated if history.length is zero, ie moves haven't been made. + */ + _updateSetup(fen) { + if (this._history.length > 0) + return; + if (fen !== DEFAULT_POSITION) { + this._header["SetUp"] = "1"; + this._header["FEN"] = fen; + } + else { + delete this._header["SetUp"]; + delete this._header["FEN"]; + } + } + reset() { + this.load(DEFAULT_POSITION); + } + get(square) { + var _a; + return (_a = this._board[Ox88[square]]) !== null && _a !== void 0 ? _a : false; + } + put({ type, color }, square) { + // check for piece + if (SYMBOLS.indexOf(type.toLowerCase()) === -1) { + return false; + } + // check for valid square + if (!(square in Ox88)) { + return false; + } + const sq = Ox88[square]; + // don't let the user place more than one king + if (type == KING && + !(this._kings[color] == EMPTY || this._kings[color] == sq)) { + return false; + } + this._board[sq] = { type: type, color: color }; + if (type === KING) { + this._kings[color] = sq; + } + this._updateSetup(this.fen()); + return true; + } + remove(square) { + const piece = this.get(square); + delete this._board[Ox88[square]]; + if (piece && piece.type === KING) { + this._kings[piece.color] = EMPTY; + } + this._updateSetup(this.fen()); + return piece; + } + _attacked(color, square) { + for (let i = Ox88.a8; i <= Ox88.h1; i++) { + // did we run off the end of the board + if (i & 0x88) { + i += 7; + continue; + } + // if empty square or wrong color + if (this._board[i] === undefined || + this._board[i].color !== color) { + continue; + } + const piece = this._board[i]; + const difference = i - square; + // skip - to/from square are the same + if (difference === 0) { + continue; + } + const index = difference + 119; + if (ATTACKS[index] & PIECE_MASKS[piece.type]) { + if (piece.type === PAWN) { + if (difference > 0) { + if (piece.color === WHITE) + return true; + } + else { + if (piece.color === BLACK) + return true; + } + continue; + } + // if the piece is a knight or a king + if (piece.type === "n" || piece.type === "k") + return true; + const offset = RAYS[index]; + let j = i + offset; + let blocked = false; + while (j !== square) { + if (this._board[j] != null) { + blocked = true; + break; + } + j += offset; + } + if (!blocked) + return true; + } + } + return false; + } + _isKingAttacked(color) { + return this._attacked(swapColor(color), this._kings[color]); + } + isAttacked(square, attackedBy) { + return this._attacked(attackedBy, Ox88[square]); + } + isCheck() { + return this._isKingAttacked(this._turn); + } + inCheck() { + return this.isCheck(); + } + isCheckmate() { + return this.isCheck() && this._moves().length === 0; + } + isStalemate() { + return !this.isCheck() && this._moves().length === 0; + } + isInsufficientMaterial() { + /* + * k.b. vs k.b. (of opposite colors) with mate in 1: + * 8/8/8/8/1b6/8/B1k5/K7 b - - 0 1 + * + * k.b. vs k.n. with mate in 1: + * 8/8/8/8/1n6/8/B7/K1k5 b - - 2 1 + */ + const pieces = { + b: 0, + n: 0, + r: 0, + q: 0, + k: 0, + p: 0, + }; + const bishops = []; + let numPieces = 0; + let squareColor = 0; + for (let i = Ox88.a8; i <= Ox88.h1; i++) { + squareColor = (squareColor + 1) % 2; + if (i & 0x88) { + i += 7; + continue; + } + const piece = this._board[i]; + if (piece) { + pieces[piece.type] = + piece.type in pieces ? pieces[piece.type] + 1 : 1; + if (piece.type === BISHOP) { + bishops.push(squareColor); + } + numPieces++; + } + } + // k vs. k + if (numPieces === 2) { + return true; + } + else if ( + // k vs. kn .... or .... k vs. kb + numPieces === 3 && + (pieces[BISHOP] === 1 || pieces[KNIGHT] === 1)) { + return true; + } + else if (numPieces === pieces[BISHOP] + 2) { + // kb vs. kb where any number of bishops are all on the same color + let sum = 0; + const len = bishops.length; + for (let i = 0; i < len; i++) { + sum += bishops[i]; + } + if (sum === 0 || sum === len) { + return true; + } + } + return false; + } + isThreefoldRepetition() { + const moves = []; + const positions = {}; + let repetition = false; + while (true) { + const move = this._undoMove(); + if (!move) + break; + moves.push(move); + } + while (true) { + /* + * remove the last two fields in the FEN string, they're not needed when + * checking for draw by rep + */ + const fen = this.fen().split(" ").slice(0, 4).join(" "); + // has the position occurred three or move times + positions[fen] = fen in positions ? positions[fen] + 1 : 1; + if (positions[fen] >= 3) { + repetition = true; + } + const move = moves.pop(); + if (!move) { + break; + } + else { + this._makeMove(move); + } + } + return repetition; + } + isDraw() { + return (this._halfMoves >= 100 || // 50 moves per side = 100 half moves + this.isStalemate() || + this.isInsufficientMaterial() || + this.isThreefoldRepetition()); + } + isGameOver() { + return this.isCheckmate() || this.isStalemate() || this.isDraw(); + } + moves({ verbose = false, square = undefined, piece = undefined, } = {}) { + const moves = this._moves({ square, piece }); + if (verbose) { + return moves.map(move => this._makePretty(move)); + } + else { + return moves.map(move => this._moveToSan(move, moves)); + } + } + _moves({ legal = true, piece = undefined, square = undefined, } = {}) { + var _a; + const forSquare = square ? square.toLowerCase() : undefined; + const forPiece = piece === null || piece === void 0 ? void 0 : piece.toLowerCase(); + const moves = []; + const us = this._turn; + const them = swapColor(us); + let firstSquare = Ox88.a8; + let lastSquare = Ox88.h1; + let singleSquare = false; + // are we generating moves for a single square? + if (forSquare) { + // illegal square, return empty moves + if (!(forSquare in Ox88)) { + return []; + } + else { + firstSquare = lastSquare = Ox88[forSquare]; + singleSquare = true; + } + } + for (let from = firstSquare; from <= lastSquare; from++) { + // did we run off the end of the board + if (from & 0x88) { + from += 7; + continue; + } + // empty square or opponent, skip + if (!this._board[from] || this._board[from].color === them) { + continue; + } + const { type } = this._board[from]; + let to; + if (type === PAWN) { + if (forPiece && forPiece !== type) + continue; + // single square, non-capturing + to = from + PAWN_OFFSETS[us][0]; + if (!this._board[to]) { + addMove(moves, us, from, to, PAWN); + // double square + to = from + PAWN_OFFSETS[us][1]; + if (SECOND_RANK[us] === rank(from) && !this._board[to]) { + addMove(moves, us, from, to, PAWN, undefined, BITS.BIG_PAWN); + } + } + // pawn captures + for (let j = 2; j < 4; j++) { + to = from + PAWN_OFFSETS[us][j]; + if (to & 0x88) + continue; + if (((_a = this._board[to]) === null || _a === void 0 ? void 0 : _a.color) === them) { + addMove(moves, us, from, to, PAWN, this._board[to].type, BITS.CAPTURE); + } + else if (to === this._epSquare) { + addMove(moves, us, from, to, PAWN, PAWN, BITS.EP_CAPTURE); + } + } + } + else { + if (forPiece && forPiece !== type) + continue; + for (let j = 0, len = PIECE_OFFSETS[type].length; j < len; j++) { + const offset = PIECE_OFFSETS[type][j]; + to = from; + while (true) { + to += offset; + if (to & 0x88) + break; + if (!this._board[to]) { + addMove(moves, us, from, to, type); + } + else { + // own color, stop loop + if (this._board[to].color === us) + break; + addMove(moves, us, from, to, type, this._board[to].type, BITS.CAPTURE); + break; + } + /* break, if knight or king */ + if (type === KNIGHT || type === KING) + break; + } + } + } + } + /* + * check for castling if we're: + * a) generating all moves, or + * b) doing single square move generation on the king's square + */ + if (forPiece === undefined || forPiece === KING) { + if (!singleSquare || lastSquare === this._kings[us]) { + // king-side castling + if (this._castling[us] & BITS.KSIDE_CASTLE) { + const castlingFrom = this._kings[us]; + const castlingTo = castlingFrom + 2; + if (!this._board[castlingFrom + 1] && + !this._board[castlingTo] && + !this._attacked(them, this._kings[us]) && + !this._attacked(them, castlingFrom + 1) && + !this._attacked(them, castlingTo)) { + addMove(moves, us, this._kings[us], castlingTo, KING, undefined, BITS.KSIDE_CASTLE); + } + } + // queen-side castling + if (this._castling[us] & BITS.QSIDE_CASTLE) { + const castlingFrom = this._kings[us]; + const castlingTo = castlingFrom - 2; + if (!this._board[castlingFrom - 1] && + !this._board[castlingFrom - 2] && + !this._board[castlingFrom - 3] && + !this._attacked(them, this._kings[us]) && + !this._attacked(them, castlingFrom - 1) && + !this._attacked(them, castlingTo)) { + addMove(moves, us, this._kings[us], castlingTo, KING, undefined, BITS.QSIDE_CASTLE); + } + } + } + } + /* + * return all pseudo-legal moves (this includes moves that allow the king + * to be captured) + */ + if (!legal) { + return moves; + } + // filter out illegal moves + const legalMoves = []; + for (let i = 0, len = moves.length; i < len; i++) { + this._makeMove(moves[i]); + if (!this._isKingAttacked(us)) { + legalMoves.push(moves[i]); + } + this._undoMove(); + } + return legalMoves; + } + move(move, { strict = false } = {}) { + /* + * The move function can be called with in the following parameters: + * + * .move('Nxb7') <- argument is a case-sensitive SAN string + * + * .move({ from: 'h7', <- argument is a move object + * to :'h8', + * promotion: 'q' }) + * + * + * An optional strict argument may be supplied to tell chess.js to + * strictly follow the SAN specification. + */ + let moveObj = null; + if (typeof move === "string") { + moveObj = this._moveFromSan(move, strict); + } + else if (typeof move === "object") { + const moves = this._moves(); + // convert the pretty move object to an ugly move object + for (let i = 0, len = moves.length; i < len; i++) { + if (move.from === algebraic(moves[i].from) && + move.to === algebraic(moves[i].to) && + (!("promotion" in moves[i]) || + move.promotion === moves[i].promotion)) { + moveObj = moves[i]; + break; + } + } + } + // failed to find move + if (!moveObj) { + if (typeof move === "string") { + throw new Error(`Invalid move: ${move}`); + } + else { + throw new Error(`Invalid move: ${JSON.stringify(move)}`); + } + } + /* + * need to make a copy of move because we can't generate SAN after the move + * is made + */ + const prettyMove = this._makePretty(moveObj); + this._makeMove(moveObj); + return prettyMove; + } + _push(move) { + this._history.push({ + move, + kings: { b: this._kings.b, w: this._kings.w }, + turn: this._turn, + castling: { b: this._castling.b, w: this._castling.w }, + epSquare: this._epSquare, + halfMoves: this._halfMoves, + moveNumber: this._moveNumber, + }); + } + _makeMove(move) { + const us = this._turn; + const them = swapColor(us); + this._push(move); + this._board[move.to] = this._board[move.from]; + delete this._board[move.from]; + // if ep capture, remove the captured pawn + if (move.flags & BITS.EP_CAPTURE) { + if (this._turn === BLACK) { + delete this._board[move.to - 16]; + } + else { + delete this._board[move.to + 16]; + } + } + // if pawn promotion, replace with new piece + if (move.promotion) { + this._board[move.to] = { type: move.promotion, color: us }; + } + // if we moved the king + if (this._board[move.to].type === KING) { + this._kings[us] = move.to; + // if we castled, move the rook next to the king + if (move.flags & BITS.KSIDE_CASTLE) { + const castlingTo = move.to - 1; + const castlingFrom = move.to + 1; + this._board[castlingTo] = this._board[castlingFrom]; + delete this._board[castlingFrom]; + } + else if (move.flags & BITS.QSIDE_CASTLE) { + const castlingTo = move.to + 1; + const castlingFrom = move.to - 2; + this._board[castlingTo] = this._board[castlingFrom]; + delete this._board[castlingFrom]; + } + // turn off castling + this._castling[us] = 0; + } + // turn off castling if we move a rook + if (this._castling[us]) { + for (let i = 0, len = ROOKS[us].length; i < len; i++) { + if (move.from === ROOKS[us][i].square && + this._castling[us] & ROOKS[us][i].flag) { + this._castling[us] ^= ROOKS[us][i].flag; + break; + } + } + } + // turn off castling if we capture a rook + if (this._castling[them]) { + for (let i = 0, len = ROOKS[them].length; i < len; i++) { + if (move.to === ROOKS[them][i].square && + this._castling[them] & ROOKS[them][i].flag) { + this._castling[them] ^= ROOKS[them][i].flag; + break; + } + } + } + // if big pawn move, update the en passant square + if (move.flags & BITS.BIG_PAWN) { + if (us === BLACK) { + this._epSquare = move.to - 16; + } + else { + this._epSquare = move.to + 16; + } + } + else { + this._epSquare = EMPTY; + } + // reset the 50 move counter if a pawn is moved or a piece is captured + if (move.piece === PAWN) { + this._halfMoves = 0; + } + else if (move.flags & (BITS.CAPTURE | BITS.EP_CAPTURE)) { + this._halfMoves = 0; + } + else { + this._halfMoves++; + } + if (us === BLACK) { + this._moveNumber++; + } + this._turn = them; + } + undo() { + const move = this._undoMove(); + return move ? this._makePretty(move) : null; + } + _undoMove() { + const old = this._history.pop(); + if (old === undefined) { + return null; + } + const move = old.move; + this._kings = old.kings; + this._turn = old.turn; + this._castling = old.castling; + this._epSquare = old.epSquare; + this._halfMoves = old.halfMoves; + this._moveNumber = old.moveNumber; + const us = this._turn; + const them = swapColor(us); + this._board[move.from] = this._board[move.to]; + this._board[move.from].type = move.piece; // to undo any promotions + delete this._board[move.to]; + if (move.captured) { + if (move.flags & BITS.EP_CAPTURE) { + // en passant capture + let index; + if (us === BLACK) { + index = move.to - 16; + } + else { + index = move.to + 16; + } + this._board[index] = { type: PAWN, color: them }; + } + else { + // regular capture + this._board[move.to] = { type: move.captured, color: them }; + } + } + if (move.flags & (BITS.KSIDE_CASTLE | BITS.QSIDE_CASTLE)) { + let castlingTo, castlingFrom; + if (move.flags & BITS.KSIDE_CASTLE) { + castlingTo = move.to + 1; + castlingFrom = move.to - 1; + } + else { + castlingTo = move.to - 2; + castlingFrom = move.to + 1; + } + this._board[castlingTo] = this._board[castlingFrom]; + delete this._board[castlingFrom]; + } + return move; + } + pgn({ newline = "\n", maxWidth = 0, } = {}) { + /* + * using the specification from http://www.chessclub.com/help/PGN-spec + * example for html usage: .pgn({ max_width: 72, newline_char: "
" }) + */ + const result = []; + let headerExists = false; + /* add the PGN header information */ + for (const i in this._header) { + /* + * TODO: order of enumerated properties in header object is not + * guaranteed, see ECMA-262 spec (section 12.6.4) + */ + result.push("[" + i + ' "' + this._header[i] + '"]' + newline); + headerExists = true; + } + if (headerExists && this._history.length) { + result.push(newline); + } + const appendComment = (moveString) => { + const comment = this._comments[this.fen()]; + if (typeof comment !== "undefined") { + const delimiter = moveString.length > 0 ? " " : ""; + moveString = `${moveString}${delimiter}{${comment}}`; + } + return moveString; + }; + // pop all of history onto reversed_history + const reversedHistory = []; + while (this._history.length > 0) { + reversedHistory.push(this._undoMove()); + } + const moves = []; + let moveString = ""; + // special case of a commented starting position with no moves + if (reversedHistory.length === 0) { + moves.push(appendComment("")); + } + // build the list of moves. a move_string looks like: "3. e3 e6" + while (reversedHistory.length > 0) { + moveString = appendComment(moveString); + const move = reversedHistory.pop(); + // make TypeScript stop complaining about move being undefined + if (!move) { + break; + } + // if the position started with black to move, start PGN with #. ... + if (!this._history.length && move.color === "b") { + const prefix = `${this._moveNumber}. ...`; + // is there a comment preceding the first move? + moveString = moveString ? `${moveString} ${prefix}` : prefix; + } + else if (move.color === "w") { + // store the previous generated move_string if we have one + if (moveString.length) { + moves.push(moveString); + } + moveString = this._moveNumber + "."; + } + moveString = + moveString + + " " + + this._moveToSan(move, this._moves({ legal: true })); + this._makeMove(move); + } + // are there any other leftover moves? + if (moveString.length) { + moves.push(appendComment(moveString)); + } + // is there a result? + if (typeof this._header.Result !== "undefined") { + moves.push(this._header.Result); + } + /* + * history should be back to what it was before we started generating PGN, + * so join together moves + */ + if (maxWidth === 0) { + return result.join("") + moves.join(" "); + } + // TODO (jah): huh? + const strip = function () { + if (result.length > 0 && result[result.length - 1] === " ") { + result.pop(); + return true; + } + return false; + }; + // NB: this does not preserve comment whitespace. + const wrapComment = function (width, move) { + for (const token of move.split(" ")) { + if (!token) { + continue; + } + if (width + token.length > maxWidth) { + while (strip()) { + width--; + } + result.push(newline); + width = 0; + } + result.push(token); + width += token.length; + result.push(" "); + width++; + } + if (strip()) { + width--; + } + return width; + }; + // wrap the PGN output at max_width + let currentWidth = 0; + for (let i = 0; i < moves.length; i++) { + if (currentWidth + moves[i].length > maxWidth) { + if (moves[i].includes("{")) { + currentWidth = wrapComment(currentWidth, moves[i]); + continue; + } + } + // if the current move will push past max_width + if (currentWidth + moves[i].length > maxWidth && i !== 0) { + // don't end the line with whitespace + if (result[result.length - 1] === " ") { + result.pop(); + } + result.push(newline); + currentWidth = 0; + } + else if (i !== 0) { + result.push(" "); + currentWidth++; + } + result.push(moves[i]); + currentWidth += moves[i].length; + } + return result.join(""); + } + header(...args) { + for (let i = 0; i < args.length; i += 2) { + if (typeof args[i] === "string" && + typeof args[i + 1] === "string") { + this._header[args[i]] = args[i + 1]; + } + } + return this._header; + } + loadPgn(pgn, { strict = false, newlineChar = "\r?\n", } = {}) { + function mask(str) { + return str.replace(/\\/g, "\\"); + } + function parsePgnHeader(header) { + const headerObj = {}; + const headers = header.split(new RegExp(mask(newlineChar))); + let key = ""; + let value = ""; + for (let i = 0; i < headers.length; i++) { + const regex = /^\s*\[\s*([A-Za-z]+)\s*"(.*)"\s*\]\s*$/; + key = headers[i].replace(regex, "$1"); + value = headers[i].replace(regex, "$2"); + if (key.trim().length > 0) { + headerObj[key] = value; + } + } + return headerObj; + } + // strip whitespace from head/tail of PGN block + pgn = pgn.trim(); + /* + * RegExp to split header. Takes advantage of the fact that header and movetext + * will always have a blank line between them (ie, two newline_char's). Handles + * case where movetext is empty by matching newlineChar until end of string is + * matched - effectively trimming from the end extra newlineChar. + * + * With default newline_char, will equal: + * /^(\[((?:\r?\n)|.)*\])((?:\s*\r?\n){2}|(?:\s*\r?\n)*$)/ + */ + const headerRegex = new RegExp("^(\\[((?:" + + mask(newlineChar) + + ")|.)*\\])" + + "((?:\\s*" + + mask(newlineChar) + + "){2}|(?:\\s*" + + mask(newlineChar) + + ")*$)"); + // If no header given, begin with moves. + const headerRegexResults = headerRegex.exec(pgn); + const headerString = headerRegexResults + ? headerRegexResults.length >= 2 + ? headerRegexResults[1] + : "" + : ""; + // Put the board in the starting position + this.reset(); + // parse PGN header + const headers = parsePgnHeader(headerString); + let fen = ""; + for (const key in headers) { + // check to see user is including fen (possibly with wrong tag case) + if (key.toLowerCase() === "fen") { + fen = headers[key]; + } + this.header(key, headers[key]); + } + /* + * the permissive parser should attempt to load a fen tag, even if it's the + * wrong case and doesn't include a corresponding [SetUp "1"] tag + */ + if (!strict) { + if (fen) { + this.load(fen, true); + } + } + else { + /* + * strict parser - load the starting position indicated by [Setup '1'] + * and [FEN position] + */ + if (headers["SetUp"] === "1") { + if (!("FEN" in headers)) { + throw new Error("Invalid PGN: FEN tag must be supplied with SetUp tag"); + } + // second argument to load: don't clear the headers + this.load(headers["FEN"], true); + } + } + /* + * NB: the regexes below that delete move numbers, recursive annotations, + * and numeric annotation glyphs may also match text in comments. To + * prevent this, we transform comments by hex-encoding them in place and + * decoding them again after the other tokens have been deleted. + * + * While the spec states that PGN files should be ASCII encoded, we use + * {en,de}codeURIComponent here to support arbitrary UTF8 as a convenience + * for modern users + */ + function toHex(s) { + return Array.from(s) + .map(function (c) { + /* + * encodeURI doesn't transform most ASCII characters, so we handle + * these ourselves + */ + return c.charCodeAt(0) < 128 + ? c.charCodeAt(0).toString(16) + : encodeURIComponent(c).replace(/%/g, "").toLowerCase(); + }) + .join(""); + } + function fromHex(s) { + return s.length == 0 + ? "" + : decodeURIComponent("%" + (s.match(/.{1,2}/g) || []).join("%")); + } + const encodeComment = function (s) { + s = s.replace(new RegExp(mask(newlineChar), "g"), " "); + return `{${toHex(s.slice(1, s.length - 1))}}`; + }; + const decodeComment = function (s) { + if (s.startsWith("{") && s.endsWith("}")) { + return fromHex(s.slice(1, s.length - 1)); + } + }; + // delete header to get the moves + let ms = pgn + .replace(headerString, "") + .replace( + // encode comments so they don't get deleted below + new RegExp(`({[^}]*})+?|;([^${mask(newlineChar)}]*)`, "g"), function (_match, bracket, semicolon) { + return bracket !== undefined + ? encodeComment(bracket) + : " " + encodeComment(`{${semicolon.slice(1)}}`); + }) + .replace(new RegExp(mask(newlineChar), "g"), " "); + // delete recursive annotation variations + const ravRegex = /(\([^()]+\))+?/g; + while (ravRegex.test(ms)) { + ms = ms.replace(ravRegex, ""); + } + // delete move numbers + ms = ms.replace(/\d+\.(\.\.)?/g, ""); + // delete ... indicating black to move + ms = ms.replace(/\.\.\./g, ""); + /* delete numeric annotation glyphs */ + ms = ms.replace(/\$\d+/g, ""); + // trim and get array of moves + let moves = ms.trim().split(new RegExp(/\s+/)); + // delete empty entries + moves = moves.filter(move => move !== ""); + let result = ""; + for (let halfMove = 0; halfMove < moves.length; halfMove++) { + const comment = decodeComment(moves[halfMove]); + if (comment !== undefined) { + this._comments[this.fen()] = comment; + continue; + } + const move = this._moveFromSan(moves[halfMove], strict); + // invalid move + if (move == null) { + // was the move an end of game marker + if (TERMINATION_MARKERS.indexOf(moves[halfMove]) > -1) { + result = moves[halfMove]; + } + else { + throw new Error(`Invalid move in PGN: ${moves[halfMove]}`); + } + } + else { + // reset the end of game marker if making a valid move + result = ""; + this._makeMove(move); + } + } + /* + * Per section 8.2.6 of the PGN spec, the Result tag pair must match match + * the termination marker. Only do this when headers are present, but the + * result tag is missing + */ + if (result && + Object.keys(this._header).length && + !this._header["Result"]) { + this.header("Result", result); + } + } + /* + * Convert a move from 0x88 coordinates to Standard Algebraic Notation + * (SAN) + * + * @param {boolean} strict Use the strict SAN parser. It will throw errors + * on overly disambiguated moves (see below): + * + * r1bqkbnr/ppp2ppp/2n5/1B1pP3/4P3/8/PPPP2PP/RNBQK1NR b KQkq - 2 4 + * 4. ... Nge7 is overly disambiguated because the knight on c6 is pinned + * 4. ... Ne7 is technically the valid SAN + */ + _moveToSan(move, moves) { + let output = ""; + if (move.flags & BITS.KSIDE_CASTLE) { + output = "O-O"; + } + else if (move.flags & BITS.QSIDE_CASTLE) { + output = "O-O-O"; + } + else { + if (move.piece !== PAWN) { + const disambiguator = getDisambiguator(move, moves); + output += move.piece.toUpperCase() + disambiguator; + } + if (move.flags & (BITS.CAPTURE | BITS.EP_CAPTURE)) { + if (move.piece === PAWN) { + output += algebraic(move.from)[0]; + } + output += "x"; + } + output += algebraic(move.to); + if (move.promotion) { + output += "=" + move.promotion.toUpperCase(); + } + } + this._makeMove(move); + if (this.isCheck()) { + if (this.isCheckmate()) { + output += "#"; + } + else { + output += "+"; + } + } + this._undoMove(); + return output; + } + // convert a move from Standard Algebraic Notation (SAN) to 0x88 coordinates + _moveFromSan(move, strict = false) { + // strip off any move decorations: e.g Nf3+?! becomes Nf3 + const cleanMove = strippedSan(move); + let pieceType = inferPieceType(cleanMove); + let moves = this._moves({ legal: true, piece: pieceType }); + // strict parser + for (let i = 0, len = moves.length; i < len; i++) { + if (cleanMove === strippedSan(this._moveToSan(moves[i], moves))) { + return moves[i]; + } + } + // the strict parser failed + if (strict) { + return null; + } + let piece = undefined; + let matches = undefined; + let from = undefined; + let to = undefined; + let promotion = undefined; + /* + * The default permissive (non-strict) parser allows the user to parse + * non-standard chess notations. This parser is only run after the strict + * Standard Algebraic Notation (SAN) parser has failed. + * + * When running the permissive parser, we'll run a regex to grab the piece, the + * to/from square, and an optional promotion piece. This regex will + * parse common non-standard notation like: Pe2-e4, Rc1c4, Qf3xf7, + * f7f8q, b1c3 + * + * NOTE: Some positions and moves may be ambiguous when using the permissive + * parser. For example, in this position: 6k1/8/8/B7/8/8/8/BN4K1 w - - 0 1, + * the move b1c3 may be interpreted as Nc3 or B1c3 (a disambiguated bishop + * move). In these cases, the permissive parser will default to the most + * basic interpretation (which is b1c3 parsing to Nc3). + */ + let overlyDisambiguated = false; + matches = cleanMove.match(/([pnbrqkPNBRQK])?([a-h][1-8])x?-?([a-h][1-8])([qrbnQRBN])?/ + // piece from to promotion + ); + if (matches) { + piece = matches[1]; + from = matches[2]; + to = matches[3]; + promotion = matches[4]; + if (from.length == 1) { + overlyDisambiguated = true; + } + } + else { + /* + * The [a-h]?[1-8]? portion of the regex below handles moves that may be + * overly disambiguated (e.g. Nge7 is unnecessary and non-standard when + * there is one legal knight move to e7). In this case, the value of + * 'from' variable will be a rank or file, not a square. + */ + matches = cleanMove.match(/([pnbrqkPNBRQK])?([a-h]?[1-8]?)x?-?([a-h][1-8])([qrbnQRBN])?/); + if (matches) { + piece = matches[1]; + from = matches[2]; + to = matches[3]; + promotion = matches[4]; + if (from.length == 1) { + overlyDisambiguated = true; + } + } + } + pieceType = inferPieceType(cleanMove); + moves = this._moves({ + legal: true, + piece: piece ? piece : pieceType, + }); + for (let i = 0, len = moves.length; i < len; i++) { + if (from && to) { + // hand-compare move properties with the results from our permissive regex + if ((!piece || piece.toLowerCase() == moves[i].piece) && + Ox88[from] == moves[i].from && + Ox88[to] == moves[i].to && + (!promotion || + promotion.toLowerCase() == moves[i].promotion)) { + return moves[i]; + } + else if (overlyDisambiguated) { + /* + * SPECIAL CASE: we parsed a move string that may have an unneeded + * rank/file disambiguator (e.g. Nge7). The 'from' variable will + */ + const square = algebraic(moves[i].from); + if ((!piece || piece.toLowerCase() == moves[i].piece) && + Ox88[to] == moves[i].to && + (from == square[0] || from == square[1]) && + (!promotion || + promotion.toLowerCase() == moves[i].promotion)) { + return moves[i]; + } + } + } + } + return null; + } + ascii() { + let s = " +------------------------+\n"; + for (let i = Ox88.a8; i <= Ox88.h1; i++) { + // display the rank + if (file(i) === 0) { + s += " " + "87654321"[rank(i)] + " |"; + } + if (this._board[i]) { + const piece = this._board[i].type; + const color = this._board[i].color; + const symbol = color === WHITE ? piece.toUpperCase() : piece.toLowerCase(); + s += " " + symbol + " "; + } + else { + s += " . "; + } + if ((i + 1) & 0x88) { + s += "|\n"; + i += 8; + } + } + s += " +------------------------+\n"; + s += " a b c d e f g h"; + return s; + } + perft(depth) { + const moves = this._moves({ legal: false }); + let nodes = 0; + const color = this._turn; + for (let i = 0, len = moves.length; i < len; i++) { + this._makeMove(moves[i]); + if (!this._isKingAttacked(color)) { + if (depth - 1 > 0) { + nodes += this.perft(depth - 1); + } + else { + nodes++; + } + } + this._undoMove(); + } + return nodes; + } + // pretty = external move object + _makePretty(uglyMove) { + const { color, piece, from, to, flags, captured, promotion } = uglyMove; + let prettyFlags = ""; + for (const flag in BITS) { + if (BITS[flag] & flags) { + prettyFlags += FLAGS[flag]; + } + } + const fromAlgebraic = algebraic(from); + const toAlgebraic = algebraic(to); + const move = { + color, + piece, + from: fromAlgebraic, + to: toAlgebraic, + san: this._moveToSan(uglyMove, this._moves({ legal: true })), + flags: prettyFlags, + lan: fromAlgebraic + toAlgebraic, + before: this.fen(), + after: "", + }; + // generate the FEN for the 'after' key + this._makeMove(uglyMove); + move.after = this.fen(); + this._undoMove(); + if (captured) { + move.captured = captured; + } + if (promotion) { + move.promotion = promotion; + move.lan += promotion; + } + return move; + } + turn() { + return this._turn; + } + board() { + const output = []; + let row = []; + for (let i = Ox88.a8; i <= Ox88.h1; i++) { + if (!this._board[i]) { + row.push(false); + } + else { + row.push({ + square: algebraic(i), + type: this._board[i].type, + color: this._board[i].color, + }); + } + if ((i + 1) & 0x88) { + output.push(row); + row = []; + i += 8; + } + } + return output; + } + squareColor(square) { + if (square in Ox88) { + const sq = Ox88[square]; + return (rank(sq) + file(sq)) % 2 === 0 ? "w" : "b"; + } + return null; + } + history({ verbose = false } = {}) { + const reversedHistory = []; + const moveHistory = []; + while (this._history.length > 0) { + reversedHistory.push(this._undoMove()); + } + while (true) { + const move = reversedHistory.pop(); + if (!move) { + break; + } + if (verbose) { + moveHistory.push(this._makePretty(move)); + } + else { + moveHistory.push(this._moveToSan(move, this._moves())); + } + this._makeMove(move); + } + return moveHistory; + } + _pruneComments() { + const reversedHistory = []; + const currentComments = {}; + const copyComment = (fen) => { + if (fen in this._comments) { + currentComments[fen] = this._comments[fen]; + } + }; + while (this._history.length > 0) { + reversedHistory.push(this._undoMove()); + } + copyComment(this.fen()); + while (true) { + const move = reversedHistory.pop(); + if (!move) { + break; + } + this._makeMove(move); + copyComment(this.fen()); + } + this._comments = currentComments; + } + getComment() { + return this._comments[this.fen()]; + } + setComment(comment) { + this._comments[this.fen()] = comment + .replace("{", "[") + .replace("}", "]"); + } + deleteComment() { + const comment = this._comments[this.fen()]; + delete this._comments[this.fen()]; + return comment; + } + getComments() { + this._pruneComments(); + return Object.keys(this._comments).map((fen) => { + return { fen: fen, comment: this._comments[fen] }; + }); + } + deleteComments() { + this._pruneComments(); + return Object.keys(this._comments).map(fen => { + const comment = this._comments[fen]; + delete this._comments[fen]; + return { fen: fen, comment: comment }; + }); + } +} diff --git a/chess.ts b/chess.ts new file mode 100644 index 0000000..e238e16 --- /dev/null +++ b/chess.ts @@ -0,0 +1,2292 @@ +/** + * @license + * Copyright (c) 2023, Jeff Hlywa (jhlywa@gmail.com) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +export const WHITE: Color = "w"; +export const BLACK: Color = "b"; + +export const PAWN = "p"; +export const KNIGHT = "n"; +export const BISHOP = "b"; +export const ROOK = "r"; +export const QUEEN = "q"; +export const KING = "k"; + +export type Color = "w" | "b"; +export type PieceSymbol = "p" | "n" | "b" | "r" | "q" | "k"; +export const PIECE_SYMBOLS = ["p", "n", "b", "r", "q", "k"]; + +// prettier-ignore +export type Square = + 'a8' | 'b8' | 'c8' | 'd8' | 'e8' | 'f8' | 'g8' | 'h8' | + 'a7' | 'b7' | 'c7' | 'd7' | 'e7' | 'f7' | 'g7' | 'h7' | + 'a6' | 'b6' | 'c6' | 'd6' | 'e6' | 'f6' | 'g6' | 'h6' | + 'a5' | 'b5' | 'c5' | 'd5' | 'e5' | 'f5' | 'g5' | 'h5' | + 'a4' | 'b4' | 'c4' | 'd4' | 'e4' | 'f4' | 'g4' | 'h4' | + 'a3' | 'b3' | 'c3' | 'd3' | 'e3' | 'f3' | 'g3' | 'h3' | + 'a2' | 'b2' | 'c2' | 'd2' | 'e2' | 'f2' | 'g2' | 'h2' | + 'a1' | 'b1' | 'c1' | 'd1' | 'e1' | 'f1' | 'g1' | 'h1' + +export const DEFAULT_POSITION = + "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"; + +export type Piece = { + color: Color; + type: PieceSymbol; +}; + +type InternalMove = { + color: Color; + from: number; + to: number; + piece: PieceSymbol; + captured?: PieceSymbol; + promotion?: PieceSymbol; + flags: number; +}; + +interface History { + move: InternalMove; + kings: Record; + turn: Color; + castling: Record; + epSquare: number; + halfMoves: number; + moveNumber: number; +} + +export type Move = { + color: Color; + from: Square; + to: Square; + piece: PieceSymbol; + captured?: PieceSymbol; + promotion?: PieceSymbol; + flags: string; + san: string; + lan: string; + before: string; + after: string; +}; + +const EMPTY = -1; + +const FLAGS: Record = { + NORMAL: "n", + CAPTURE: "c", + BIG_PAWN: "b", + EP_CAPTURE: "e", + PROMOTION: "p", + KSIDE_CASTLE: "k", + QSIDE_CASTLE: "q", +}; + +// prettier-ignore +export const SQUARES: Square[] = [ + 'a8', 'b8', 'c8', 'd8', 'e8', 'f8', 'g8', 'h8', + 'a7', 'b7', 'c7', 'd7', 'e7', 'f7', 'g7', 'h7', + 'a6', 'b6', 'c6', 'd6', 'e6', 'f6', 'g6', 'h6', + 'a5', 'b5', 'c5', 'd5', 'e5', 'f5', 'g5', 'h5', + 'a4', 'b4', 'c4', 'd4', 'e4', 'f4', 'g4', 'h4', + 'a3', 'b3', 'c3', 'd3', 'e3', 'f3', 'g3', 'h3', + 'a2', 'b2', 'c2', 'd2', 'e2', 'f2', 'g2', 'h2', + 'a1', 'b1', 'c1', 'd1', 'e1', 'f1', 'g1', 'h1' +] + +const BITS: Record = { + NORMAL: 1, + CAPTURE: 2, + BIG_PAWN: 4, + EP_CAPTURE: 8, + PROMOTION: 16, + KSIDE_CASTLE: 32, + QSIDE_CASTLE: 64, +}; + +/* + * NOTES ABOUT 0x88 MOVE GENERATION ALGORITHM + * ---------------------------------------------------------------------------- + * From https://github.com/jhlywa/chess.js/issues/230 + * + * A lot of people are confused when they first see the internal representation + * of chess.js. It uses the 0x88 Move Generation Algorithm which internally + * stores the board as an 8x16 array. This is purely for efficiency but has a + * couple of interesting benefits: + * + * 1. 0x88 offers a very inexpensive "off the board" check. Bitwise AND (&) any + * square with 0x88, if the result is non-zero then the square is off the + * board. For example, assuming a knight square A8 (0 in 0x88 notation), + * there are 8 possible directions in which the knight can move. These + * directions are relative to the 8x16 board and are stored in the + * PIECE_OFFSETS map. One possible move is A8 - 18 (up one square, and two + * squares to the left - which is off the board). 0 - 18 = -18 & 0x88 = 0x88 + * (because of two-complement representation of -18). The non-zero result + * means the square is off the board and the move is illegal. Take the + * opposite move (from A8 to C7), 0 + 18 = 18 & 0x88 = 0. A result of zero + * means the square is on the board. + * + * 2. The relative distance (or difference) between two squares on a 8x16 board + * is unique and can be used to inexpensively determine if a piece on a + * square can attack any other arbitrary square. For example, let's see if a + * pawn on E7 can attack E2. The difference between E7 (20) - E2 (100) is + * -80. We add 119 to make the ATTACKS array index non-negative (because the + * worst case difference is A8 - H1 = -119). The ATTACKS array contains a + * bitmask of pieces that can attack from that distance and direction. + * ATTACKS[-80 + 119=39] gives us 24 or 0b11000 in binary. Look at the + * PIECE_MASKS map to determine the mask for a given piece type. In our pawn + * example, we would check to see if 24 & 0x1 is non-zero, which it is + * not. So, naturally, a pawn on E7 can't attack a piece on E2. However, a + * rook can since 24 & 0x8 is non-zero. The only thing left to check is that + * there are no blocking pieces between E7 and E2. That's where the RAYS + * array comes in. It provides an offset (in this case 16) to add to E7 (20) + * to check for blocking pieces. E7 (20) + 16 = E6 (36) + 16 = E5 (52) etc. + */ + +// prettier-ignore +// eslint-disable-next-line +export const Ox88: Record = { + a8: 0, b8: 1, c8: 2, d8: 3, e8: 4, f8: 5, g8: 6, h8: 7, + a7: 16, b7: 17, c7: 18, d7: 19, e7: 20, f7: 21, g7: 22, h7: 23, + a6: 32, b6: 33, c6: 34, d6: 35, e6: 36, f6: 37, g6: 38, h6: 39, + a5: 48, b5: 49, c5: 50, d5: 51, e5: 52, f5: 53, g5: 54, h5: 55, + a4: 64, b4: 65, c4: 66, d4: 67, e4: 68, f4: 69, g4: 70, h4: 71, + a3: 80, b3: 81, c3: 82, d3: 83, e3: 84, f3: 85, g3: 86, h3: 87, + a2: 96, b2: 97, c2: 98, d2: 99, e2: 100, f2: 101, g2: 102, h2: 103, + a1: 112, b1: 113, c1: 114, d1: 115, e1: 116, f1: 117, g1: 118, h1: 119 +} + +const PAWN_OFFSETS = { + b: [16, 32, 17, 15], + w: [-16, -32, -17, -15], +}; + +const PIECE_OFFSETS = { + n: [-18, -33, -31, -14, 18, 33, 31, 14], + b: [-17, -15, 17, 15], + r: [-16, 1, 16, -1], + q: [-17, -16, -15, 1, 17, 16, 15, -1], + k: [-17, -16, -15, 1, 17, 16, 15, -1], +}; + +// prettier-ignore +const ATTACKS = [ + 20, 0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 0, 0, 0,20, 0, + 0,20, 0, 0, 0, 0, 0, 24, 0, 0, 0, 0, 0,20, 0, 0, + 0, 0,20, 0, 0, 0, 0, 24, 0, 0, 0, 0,20, 0, 0, 0, + 0, 0, 0,20, 0, 0, 0, 24, 0, 0, 0,20, 0, 0, 0, 0, + 0, 0, 0, 0,20, 0, 0, 24, 0, 0,20, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0,20, 2, 24, 2,20, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 2,53, 56, 53, 2, 0, 0, 0, 0, 0, 0, + 24,24,24,24,24,24,56, 0, 56,24,24,24,24,24,24, 0, + 0, 0, 0, 0, 0, 2,53, 56, 53, 2, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0,20, 2, 24, 2,20, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0,20, 0, 0, 24, 0, 0,20, 0, 0, 0, 0, 0, + 0, 0, 0,20, 0, 0, 0, 24, 0, 0, 0,20, 0, 0, 0, 0, + 0, 0,20, 0, 0, 0, 0, 24, 0, 0, 0, 0,20, 0, 0, 0, + 0,20, 0, 0, 0, 0, 0, 24, 0, 0, 0, 0, 0,20, 0, 0, + 20, 0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 0, 0, 0,20 +]; + +// prettier-ignore +const RAYS = [ + 17, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 15, 0, + 0, 17, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 15, 0, 0, + 0, 0, 17, 0, 0, 0, 0, 16, 0, 0, 0, 0, 15, 0, 0, 0, + 0, 0, 0, 17, 0, 0, 0, 16, 0, 0, 0, 15, 0, 0, 0, 0, + 0, 0, 0, 0, 17, 0, 0, 16, 0, 0, 15, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 17, 0, 16, 0, 15, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 17, 16, 15, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 0, -1, -1, -1,-1, -1, -1, -1, 0, + 0, 0, 0, 0, 0, 0,-15,-16,-17, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0,-15, 0,-16, 0,-17, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0,-15, 0, 0,-16, 0, 0,-17, 0, 0, 0, 0, 0, + 0, 0, 0,-15, 0, 0, 0,-16, 0, 0, 0,-17, 0, 0, 0, 0, + 0, 0,-15, 0, 0, 0, 0,-16, 0, 0, 0, 0,-17, 0, 0, 0, + 0,-15, 0, 0, 0, 0, 0,-16, 0, 0, 0, 0, 0,-17, 0, 0, + -15, 0, 0, 0, 0, 0, 0,-16, 0, 0, 0, 0, 0, 0,-17 +]; + +const PIECE_MASKS = { p: 0x1, n: 0x2, b: 0x4, r: 0x8, q: 0x10, k: 0x20 }; + +const SYMBOLS = "pnbrqkPNBRQK"; + +const PROMOTIONS: PieceSymbol[] = [KNIGHT, BISHOP, ROOK, QUEEN]; + +const RANK_1 = 7; +const RANK_2 = 6; +/* + * const RANK_3 = 5 + * const RANK_4 = 4 + * const RANK_5 = 3 + * const RANK_6 = 2 + */ +const RANK_7 = 1; +const RANK_8 = 0; + +const ROOKS = { + w: [ + { square: Ox88.a1, flag: BITS.QSIDE_CASTLE }, + { square: Ox88.h1, flag: BITS.KSIDE_CASTLE }, + ], + b: [ + { square: Ox88.a8, flag: BITS.QSIDE_CASTLE }, + { square: Ox88.h8, flag: BITS.KSIDE_CASTLE }, + ], +}; + +const SECOND_RANK = { b: RANK_7, w: RANK_2 }; + +const TERMINATION_MARKERS = ["1-0", "0-1", "1/2-1/2", "*"]; + +// Extracts the zero-based rank of an 0x88 square. +export function rank(square: number): number { + return square >> 4; +} + +// Extracts the zero-based file of an 0x88 square. +export function file(square: number): number { + return square & 0xf; +} + +function isDigit(c: string): boolean { + return "0123456789".indexOf(c) !== -1; +} + +// Converts a 0x88 square to algebraic notation. +function algebraic(square: number): Square { + const f = file(square); + const r = rank(square); + return ("abcdefgh".substring(f, f + 1) + + "87654321".substring(r, r + 1)) as Square; +} + +function swapColor(color: Color): Color { + return color === WHITE ? BLACK : WHITE; +} + +export function validateFen(fen: string) { + // 1st criterion: 6 space-seperated fields? + const tokens = fen.split(/\s+/); + if (tokens.length !== 6) { + return { + ok: false, + error: "Invalid FEN: must contain six space-delimited fields", + }; + } + + // 2nd criterion: move number field is a integer value > 0? + const moveNumber = parseInt(tokens[5], 10); + if (isNaN(moveNumber) || moveNumber <= 0) { + return { + ok: false, + error: "Invalid FEN: move number must be a positive integer", + }; + } + + // 3rd criterion: half move counter is an integer >= 0? + const halfMoves = parseInt(tokens[4], 10); + if (isNaN(halfMoves) || halfMoves < 0) { + return { + ok: false, + error: "Invalid FEN: half move counter number must be a non-negative integer", + }; + } + + // 4th criterion: 4th field is a valid e.p.-string? + if (!/^(-|[abcdefgh][36])$/.test(tokens[3])) { + return { + ok: false, + error: "Invalid FEN: en-passant square is invalid", + }; + } + + // 5th criterion: 3th field is a valid castle-string? + if (/[^kKqQ-]/.test(tokens[2])) { + return { + ok: false, + error: "Invalid FEN: castling availability is invalid", + }; + } + + // 6th criterion: 2nd field is "w" (white) or "b" (black)? + if (!/^(w|b)$/.test(tokens[1])) { + return { ok: false, error: "Invalid FEN: side-to-move is invalid" }; + } + + // 7th criterion: 1st field contains 8 rows? + const rows = tokens[0].split("/"); + if (rows.length !== 8) { + return { + ok: false, + error: "Invalid FEN: piece data does not contain 8 '/'-delimited rows", + }; + } + + // 8th criterion: every row is valid? + for (let i = 0; i < rows.length; i++) { + // check for right sum of fields AND not two numbers in succession + let sumFields = 0; + let previousWasNumber = false; + + for (let k = 0; k < rows[i].length; k++) { + if (isDigit(rows[i][k])) { + if (previousWasNumber) { + return { + ok: false, + error: "Invalid FEN: piece data is invalid (consecutive number)", + }; + } + sumFields += parseInt(rows[i][k], 10); + previousWasNumber = true; + } else { + if (!/^[prnbqkPRNBQK]$/.test(rows[i][k])) { + return { + ok: false, + error: "Invalid FEN: piece data is invalid (invalid piece)", + }; + } + sumFields += 1; + previousWasNumber = false; + } + } + if (sumFields !== 8) { + return { + ok: false, + error: "Invalid FEN: piece data is invalid (too many squares in rank)", + }; + } + } + + if ( + (tokens[3][1] == "3" && tokens[1] == "w") || + (tokens[3][1] == "6" && tokens[1] == "b") + ) { + return { ok: false, error: "Invalid FEN: illegal en-passant square" }; + } + + const kings = [ + { color: "white", regex: /K/g }, + { color: "black", regex: /k/g }, + ]; + + for (const { color, regex } of kings) { + if (!regex.test(tokens[0])) { + return { ok: false, error: `Invalid FEN: missing ${color} king` }; + } + + if ((tokens[0].match(regex) || []).length > 1) { + return { ok: false, error: `Invalid FEN: too many ${color} kings` }; + } + } + + return { ok: true }; +} + +// this function is used to uniquely identify ambiguous moves +function getDisambiguator(move: InternalMove, moves: InternalMove[]) { + const from = move.from; + const to = move.to; + const piece = move.piece; + + let ambiguities = 0; + let sameRank = 0; + let sameFile = 0; + + for (let i = 0, len = moves.length; i < len; i++) { + const ambigFrom = moves[i].from; + const ambigTo = moves[i].to; + const ambigPiece = moves[i].piece; + + /* + * if a move of the same piece type ends on the same to square, we'll need + * to add a disambiguator to the algebraic notation + */ + if (piece === ambigPiece && from !== ambigFrom && to === ambigTo) { + ambiguities++; + + if (rank(from) === rank(ambigFrom)) { + sameRank++; + } + + if (file(from) === file(ambigFrom)) { + sameFile++; + } + } + } + + if (ambiguities > 0) { + if (sameRank > 0 && sameFile > 0) { + /* + * if there exists a similar moving piece on the same rank and file as + * the move in question, use the square as the disambiguator + */ + return algebraic(from); + } else if (sameFile > 0) { + /* + * if the moving piece rests on the same file, use the rank symbol as the + * disambiguator + */ + return algebraic(from).charAt(1); + } else { + // else use the file symbol + return algebraic(from).charAt(0); + } + } + + return ""; +} + +function addMove( + moves: InternalMove[], + color: Color, + from: number, + to: number, + piece: PieceSymbol, + captured: PieceSymbol | undefined = undefined, + flags: number = BITS.NORMAL +) { + const r = rank(to); + + if (piece === PAWN && (r === RANK_1 || r === RANK_8)) { + for (let i = 0; i < PROMOTIONS.length; i++) { + const promotion = PROMOTIONS[i]; + moves.push({ + color, + from, + to, + piece, + captured, + promotion, + flags: flags | BITS.PROMOTION, + }); + } + } else { + moves.push({ + color, + from, + to, + piece, + captured, + flags, + }); + } +} + +function inferPieceType(san: string) { + let pieceType = san.charAt(0); + if (pieceType >= "a" && pieceType <= "h") { + const matches = san.match(/[a-h]\d.*[a-h]\d/); + if (matches) { + return undefined; + } + return PAWN; + } + pieceType = pieceType.toLowerCase(); + if (pieceType === "o") { + return KING; + } + return pieceType as PieceSymbol; +} + +// parses all of the decorators out of a SAN string +function strippedSan(move: string) { + return move.replace(/=/, "").replace(/[+#]?[?!]*$/, ""); +} + +export class Chess { + private _board = new Array(128); + private _turn: Color = WHITE; + private _header: Record = {}; + private _kings: Record = { w: EMPTY, b: EMPTY }; + private _epSquare = -1; + private _halfMoves = 0; + private _moveNumber = 0; + private _history: History[] = []; + private _comments: Record = {}; + private _castling: Record = { w: 0, b: 0 }; + + constructor(fen = DEFAULT_POSITION) { + this.load(fen); + } + + clear(keepHeaders = false) { + this._board = new Array(128); + this._kings = { w: EMPTY, b: EMPTY }; + this._turn = WHITE; + this._castling = { w: 0, b: 0 }; + this._epSquare = EMPTY; + this._halfMoves = 0; + this._moveNumber = 1; + this._history = []; + this._comments = {}; + this._header = keepHeaders ? this._header : {}; + this._updateSetup(this.fen()); + } + + load(fen: string, keepHeaders = false) { + let tokens = fen.split(/\s+/); + + // append commonly omitted fen tokens + if (tokens.length >= 2 && tokens.length < 6) { + const adjustments = ["-", "-", "0", "1"]; + fen = tokens + .concat(adjustments.slice(-(6 - tokens.length))) + .join(" "); + } + + tokens = fen.split(/\s+/); + + const { ok, error } = validateFen(fen); + if (!ok) { + throw new Error(error); + } + + const position = tokens[0]; + let square = 0; + + this.clear(keepHeaders); + + for (let i = 0; i < position.length; i++) { + const piece = position.charAt(i); + + if (piece === "/") { + square += 8; + } else if (isDigit(piece)) { + square += parseInt(piece, 10); + } else { + const color = piece < "a" ? WHITE : BLACK; + this.put( + { type: piece.toLowerCase() as PieceSymbol, color }, + algebraic(square) + ); + square++; + } + } + + this._turn = tokens[1] as Color; + + if (tokens[2].indexOf("K") > -1) { + this._castling.w |= BITS.KSIDE_CASTLE; + } + if (tokens[2].indexOf("Q") > -1) { + this._castling.w |= BITS.QSIDE_CASTLE; + } + if (tokens[2].indexOf("k") > -1) { + this._castling.b |= BITS.KSIDE_CASTLE; + } + if (tokens[2].indexOf("q") > -1) { + this._castling.b |= BITS.QSIDE_CASTLE; + } + + this._epSquare = tokens[3] === "-" ? EMPTY : Ox88[tokens[3] as Square]; + this._halfMoves = parseInt(tokens[4], 10); + this._moveNumber = parseInt(tokens[5], 10); + + this._updateSetup(this.fen()); + } + + fen() { + let empty = 0; + let fen = ""; + + for (let i = Ox88.a8; i <= Ox88.h1; i++) { + if (this._board[i]) { + if (empty > 0) { + fen += empty; + empty = 0; + } + const { color, type: piece } = this._board[i]; + + fen += + color === WHITE ? piece.toUpperCase() : piece.toLowerCase(); + } else { + empty++; + } + + if ((i + 1) & 0x88) { + if (empty > 0) { + fen += empty; + } + + if (i !== Ox88.h1) { + fen += "/"; + } + + empty = 0; + i += 8; + } + } + + let castling = ""; + if (this._castling[WHITE] & BITS.KSIDE_CASTLE) { + castling += "K"; + } + if (this._castling[WHITE] & BITS.QSIDE_CASTLE) { + castling += "Q"; + } + if (this._castling[BLACK] & BITS.KSIDE_CASTLE) { + castling += "k"; + } + if (this._castling[BLACK] & BITS.QSIDE_CASTLE) { + castling += "q"; + } + + // do we have an empty castling flag? + castling = castling || "-"; + + let epSquare = "-"; + /* + * only print the ep square if en passant is a valid move (pawn is present + * and ep capture is not pinned) + */ + if (this._epSquare !== EMPTY) { + const bigPawnSquare = + this._epSquare + (this._turn === WHITE ? 16 : -16); + const squares = [bigPawnSquare + 1, bigPawnSquare - 1]; + + for (const square of squares) { + // is the square off the board? + if (square & 0x88) { + continue; + } + + const color = this._turn; + + // is there a pawn that can capture the epSquare? + if ( + this._board[square]?.color === color && + this._board[square]?.type === PAWN + ) { + // if the pawn makes an ep capture, does it leave it's king in check? + this._makeMove({ + color, + from: square, + to: this._epSquare, + piece: PAWN, + captured: PAWN, + flags: BITS.EP_CAPTURE, + }); + const isLegal = !this._isKingAttacked(color); + this._undoMove(); + + // if ep is legal, break and set the ep square in the FEN output + if (isLegal) { + epSquare = algebraic(this._epSquare); + break; + } + } + } + } + + return [ + fen, + this._turn, + castling, + epSquare, + this._halfMoves, + this._moveNumber, + ].join(" "); + } + + /* + * Called when the initial board setup is changed with put() or remove(). + * modifies the SetUp and FEN properties of the header object. If the FEN + * is equal to the default position, the SetUp and FEN are deleted the setup + * is only updated if history.length is zero, ie moves haven't been made. + */ + private _updateSetup(fen: string) { + if (this._history.length > 0) return; + + if (fen !== DEFAULT_POSITION) { + this._header["SetUp"] = "1"; + this._header["FEN"] = fen; + } else { + delete this._header["SetUp"]; + delete this._header["FEN"]; + } + } + + reset() { + this.load(DEFAULT_POSITION); + } + + get(square: Square) { + return this._board[Ox88[square]] ?? false; + } + + put({ type, color }: { type: PieceSymbol; color: Color }, square: Square) { + // check for piece + if (SYMBOLS.indexOf(type.toLowerCase()) === -1) { + return false; + } + + // check for valid square + if (!(square in Ox88)) { + return false; + } + + const sq = Ox88[square]; + + // don't let the user place more than one king + if ( + type == KING && + !(this._kings[color] == EMPTY || this._kings[color] == sq) + ) { + return false; + } + + this._board[sq] = { type: type as PieceSymbol, color: color as Color }; + + if (type === KING) { + this._kings[color] = sq; + } + + this._updateSetup(this.fen()); + + return true; + } + + remove(square: Square) { + const piece = this.get(square); + delete this._board[Ox88[square]]; + if (piece && piece.type === KING) { + this._kings[piece.color] = EMPTY; + } + + this._updateSetup(this.fen()); + + return piece; + } + + _attacked(color: Color, square: number) { + for (let i = Ox88.a8; i <= Ox88.h1; i++) { + // did we run off the end of the board + if (i & 0x88) { + i += 7; + continue; + } + + // if empty square or wrong color + if ( + this._board[i] === undefined || + this._board[i].color !== color + ) { + continue; + } + + const piece = this._board[i]; + const difference = i - square; + + // skip - to/from square are the same + if (difference === 0) { + continue; + } + + const index = difference + 119; + + if (ATTACKS[index] & PIECE_MASKS[piece.type]) { + if (piece.type === PAWN) { + if (difference > 0) { + if (piece.color === WHITE) return true; + } else { + if (piece.color === BLACK) return true; + } + continue; + } + + // if the piece is a knight or a king + if (piece.type === "n" || piece.type === "k") return true; + + const offset = RAYS[index]; + let j = i + offset; + + let blocked = false; + while (j !== square) { + if (this._board[j] != null) { + blocked = true; + break; + } + j += offset; + } + + if (!blocked) return true; + } + } + + return false; + } + + private _isKingAttacked(color: Color) { + return this._attacked(swapColor(color), this._kings[color]); + } + + isAttacked(square: Square, attackedBy: Color) { + return this._attacked(attackedBy, Ox88[square]); + } + + isCheck() { + return this._isKingAttacked(this._turn); + } + + inCheck() { + return this.isCheck(); + } + + isCheckmate() { + return this.isCheck() && this._moves().length === 0; + } + + isStalemate() { + return !this.isCheck() && this._moves().length === 0; + } + + isInsufficientMaterial() { + /* + * k.b. vs k.b. (of opposite colors) with mate in 1: + * 8/8/8/8/1b6/8/B1k5/K7 b - - 0 1 + * + * k.b. vs k.n. with mate in 1: + * 8/8/8/8/1n6/8/B7/K1k5 b - - 2 1 + */ + const pieces: Record = { + b: 0, + n: 0, + r: 0, + q: 0, + k: 0, + p: 0, + }; + const bishops = []; + let numPieces = 0; + let squareColor = 0; + + for (let i = Ox88.a8; i <= Ox88.h1; i++) { + squareColor = (squareColor + 1) % 2; + if (i & 0x88) { + i += 7; + continue; + } + + const piece = this._board[i]; + if (piece) { + pieces[piece.type] = + piece.type in pieces ? pieces[piece.type] + 1 : 1; + if (piece.type === BISHOP) { + bishops.push(squareColor); + } + numPieces++; + } + } + + // k vs. k + if (numPieces === 2) { + return true; + } else if ( + // k vs. kn .... or .... k vs. kb + numPieces === 3 && + (pieces[BISHOP] === 1 || pieces[KNIGHT] === 1) + ) { + return true; + } else if (numPieces === pieces[BISHOP] + 2) { + // kb vs. kb where any number of bishops are all on the same color + let sum = 0; + const len = bishops.length; + for (let i = 0; i < len; i++) { + sum += bishops[i]; + } + if (sum === 0 || sum === len) { + return true; + } + } + + return false; + } + + isThreefoldRepetition() { + const moves = []; + const positions: Record = {}; + let repetition = false; + + while (true) { + const move = this._undoMove(); + if (!move) break; + moves.push(move); + } + + while (true) { + /* + * remove the last two fields in the FEN string, they're not needed when + * checking for draw by rep + */ + const fen = this.fen().split(" ").slice(0, 4).join(" "); + + // has the position occurred three or move times + positions[fen] = fen in positions ? positions[fen] + 1 : 1; + if (positions[fen] >= 3) { + repetition = true; + } + + const move = moves.pop(); + + if (!move) { + break; + } else { + this._makeMove(move); + } + } + + return repetition; + } + + isDraw() { + return ( + this._halfMoves >= 100 || // 50 moves per side = 100 half moves + this.isStalemate() || + this.isInsufficientMaterial() || + this.isThreefoldRepetition() + ); + } + + isGameOver() { + return this.isCheckmate() || this.isStalemate() || this.isDraw(); + } + + moves(): string[]; + moves({ square }: { square: Square }): string[]; + moves({ piece }: { piece: PieceSymbol }): string[]; + + moves({ square, piece }: { square: Square; piece: PieceSymbol }): string[]; + + moves({ verbose, square }: { verbose: true; square?: Square }): Move[]; + moves({ verbose, square }: { verbose: false; square?: Square }): string[]; + moves({ + verbose, + square, + }: { + verbose?: boolean; + square?: Square; + }): string[] | Move[]; + + moves({ verbose, piece }: { verbose: true; piece?: PieceSymbol }): Move[]; + moves({ + verbose, + piece, + }: { + verbose: false; + piece?: PieceSymbol; + }): string[]; + moves({ + verbose, + piece, + }: { + verbose?: boolean; + piece?: PieceSymbol; + }): string[] | Move[]; + + moves({ + verbose, + square, + piece, + }: { + verbose: true; + square?: Square; + piece?: PieceSymbol; + }): Move[]; + moves({ + verbose, + square, + piece, + }: { + verbose: false; + square?: Square; + piece?: PieceSymbol; + }): string[]; + moves({ + verbose, + square, + piece, + }: { + verbose?: boolean; + square?: Square; + piece?: PieceSymbol; + }): string[] | Move[]; + + moves({ square, piece }: { square?: Square; piece?: PieceSymbol }): Move[]; + + moves({ + verbose = false, + square = undefined, + piece = undefined, + }: { verbose?: boolean; square?: Square; piece?: PieceSymbol } = {}) { + const moves = this._moves({ square, piece }); + + if (verbose) { + return moves.map(move => this._makePretty(move)); + } else { + return moves.map(move => this._moveToSan(move, moves)); + } + } + + _moves({ + legal = true, + piece = undefined, + square = undefined, + }: { + legal?: boolean; + piece?: PieceSymbol; + square?: Square; + } = {}) { + const forSquare = square ? (square.toLowerCase() as Square) : undefined; + const forPiece = piece?.toLowerCase(); + + const moves: InternalMove[] = []; + const us = this._turn; + const them = swapColor(us); + + let firstSquare = Ox88.a8; + let lastSquare = Ox88.h1; + let singleSquare = false; + + // are we generating moves for a single square? + if (forSquare) { + // illegal square, return empty moves + if (!(forSquare in Ox88)) { + return []; + } else { + firstSquare = lastSquare = Ox88[forSquare]; + singleSquare = true; + } + } + + for (let from = firstSquare; from <= lastSquare; from++) { + // did we run off the end of the board + if (from & 0x88) { + from += 7; + continue; + } + + // empty square or opponent, skip + if (!this._board[from] || this._board[from].color === them) { + continue; + } + const { type } = this._board[from]; + + let to: number; + if (type === PAWN) { + if (forPiece && forPiece !== type) continue; + + // single square, non-capturing + to = from + PAWN_OFFSETS[us][0]; + if (!this._board[to]) { + addMove(moves, us, from, to, PAWN); + + // double square + to = from + PAWN_OFFSETS[us][1]; + if (SECOND_RANK[us] === rank(from) && !this._board[to]) { + addMove( + moves, + us, + from, + to, + PAWN, + undefined, + BITS.BIG_PAWN + ); + } + } + + // pawn captures + for (let j = 2; j < 4; j++) { + to = from + PAWN_OFFSETS[us][j]; + if (to & 0x88) continue; + + if (this._board[to]?.color === them) { + addMove( + moves, + us, + from, + to, + PAWN, + this._board[to].type, + BITS.CAPTURE + ); + } else if (to === this._epSquare) { + addMove( + moves, + us, + from, + to, + PAWN, + PAWN, + BITS.EP_CAPTURE + ); + } + } + } else { + if (forPiece && forPiece !== type) continue; + + for ( + let j = 0, len = PIECE_OFFSETS[type].length; + j < len; + j++ + ) { + const offset = PIECE_OFFSETS[type][j]; + to = from; + + while (true) { + to += offset; + if (to & 0x88) break; + + if (!this._board[to]) { + addMove(moves, us, from, to, type); + } else { + // own color, stop loop + if (this._board[to].color === us) break; + + addMove( + moves, + us, + from, + to, + type, + this._board[to].type, + BITS.CAPTURE + ); + break; + } + + /* break, if knight or king */ + if (type === KNIGHT || type === KING) break; + } + } + } + } + + /* + * check for castling if we're: + * a) generating all moves, or + * b) doing single square move generation on the king's square + */ + + if (forPiece === undefined || forPiece === KING) { + if (!singleSquare || lastSquare === this._kings[us]) { + // king-side castling + if (this._castling[us] & BITS.KSIDE_CASTLE) { + const castlingFrom = this._kings[us]; + const castlingTo = castlingFrom + 2; + + if ( + !this._board[castlingFrom + 1] && + !this._board[castlingTo] && + !this._attacked(them, this._kings[us]) && + !this._attacked(them, castlingFrom + 1) && + !this._attacked(them, castlingTo) + ) { + addMove( + moves, + us, + this._kings[us], + castlingTo, + KING, + undefined, + BITS.KSIDE_CASTLE + ); + } + } + + // queen-side castling + if (this._castling[us] & BITS.QSIDE_CASTLE) { + const castlingFrom = this._kings[us]; + const castlingTo = castlingFrom - 2; + + if ( + !this._board[castlingFrom - 1] && + !this._board[castlingFrom - 2] && + !this._board[castlingFrom - 3] && + !this._attacked(them, this._kings[us]) && + !this._attacked(them, castlingFrom - 1) && + !this._attacked(them, castlingTo) + ) { + addMove( + moves, + us, + this._kings[us], + castlingTo, + KING, + undefined, + BITS.QSIDE_CASTLE + ); + } + } + } + } + + /* + * return all pseudo-legal moves (this includes moves that allow the king + * to be captured) + */ + if (!legal) { + return moves; + } + + // filter out illegal moves + const legalMoves = []; + + for (let i = 0, len = moves.length; i < len; i++) { + this._makeMove(moves[i]); + if (!this._isKingAttacked(us)) { + legalMoves.push(moves[i]); + } + this._undoMove(); + } + + return legalMoves; + } + + move( + move: string | { from: string; to: string; promotion?: string }, + { strict = false }: { strict?: boolean } = {} + ) { + /* + * The move function can be called with in the following parameters: + * + * .move('Nxb7') <- argument is a case-sensitive SAN string + * + * .move({ from: 'h7', <- argument is a move object + * to :'h8', + * promotion: 'q' }) + * + * + * An optional strict argument may be supplied to tell chess.js to + * strictly follow the SAN specification. + */ + + let moveObj = null; + + if (typeof move === "string") { + moveObj = this._moveFromSan(move, strict); + } else if (typeof move === "object") { + const moves = this._moves(); + + // convert the pretty move object to an ugly move object + for (let i = 0, len = moves.length; i < len; i++) { + if ( + move.from === algebraic(moves[i].from) && + move.to === algebraic(moves[i].to) && + (!("promotion" in moves[i]) || + move.promotion === moves[i].promotion) + ) { + moveObj = moves[i]; + break; + } + } + } + + // failed to find move + if (!moveObj) { + if (typeof move === "string") { + throw new Error(`Invalid move: ${move}`); + } else { + throw new Error(`Invalid move: ${JSON.stringify(move)}`); + } + } + + /* + * need to make a copy of move because we can't generate SAN after the move + * is made + */ + const prettyMove = this._makePretty(moveObj); + + this._makeMove(moveObj); + + return prettyMove; + } + + _push(move: InternalMove) { + this._history.push({ + move, + kings: { b: this._kings.b, w: this._kings.w }, + turn: this._turn, + castling: { b: this._castling.b, w: this._castling.w }, + epSquare: this._epSquare, + halfMoves: this._halfMoves, + moveNumber: this._moveNumber, + }); + } + + private _makeMove(move: InternalMove) { + const us = this._turn; + const them = swapColor(us); + this._push(move); + + this._board[move.to] = this._board[move.from]; + delete this._board[move.from]; + + // if ep capture, remove the captured pawn + if (move.flags & BITS.EP_CAPTURE) { + if (this._turn === BLACK) { + delete this._board[move.to - 16]; + } else { + delete this._board[move.to + 16]; + } + } + + // if pawn promotion, replace with new piece + if (move.promotion) { + this._board[move.to] = { type: move.promotion, color: us }; + } + + // if we moved the king + if (this._board[move.to].type === KING) { + this._kings[us] = move.to; + + // if we castled, move the rook next to the king + if (move.flags & BITS.KSIDE_CASTLE) { + const castlingTo = move.to - 1; + const castlingFrom = move.to + 1; + this._board[castlingTo] = this._board[castlingFrom]; + delete this._board[castlingFrom]; + } else if (move.flags & BITS.QSIDE_CASTLE) { + const castlingTo = move.to + 1; + const castlingFrom = move.to - 2; + this._board[castlingTo] = this._board[castlingFrom]; + delete this._board[castlingFrom]; + } + + // turn off castling + this._castling[us] = 0; + } + + // turn off castling if we move a rook + if (this._castling[us]) { + for (let i = 0, len = ROOKS[us].length; i < len; i++) { + if ( + move.from === ROOKS[us][i].square && + this._castling[us] & ROOKS[us][i].flag + ) { + this._castling[us] ^= ROOKS[us][i].flag; + break; + } + } + } + + // turn off castling if we capture a rook + if (this._castling[them]) { + for (let i = 0, len = ROOKS[them].length; i < len; i++) { + if ( + move.to === ROOKS[them][i].square && + this._castling[them] & ROOKS[them][i].flag + ) { + this._castling[them] ^= ROOKS[them][i].flag; + break; + } + } + } + + // if big pawn move, update the en passant square + if (move.flags & BITS.BIG_PAWN) { + if (us === BLACK) { + this._epSquare = move.to - 16; + } else { + this._epSquare = move.to + 16; + } + } else { + this._epSquare = EMPTY; + } + + // reset the 50 move counter if a pawn is moved or a piece is captured + if (move.piece === PAWN) { + this._halfMoves = 0; + } else if (move.flags & (BITS.CAPTURE | BITS.EP_CAPTURE)) { + this._halfMoves = 0; + } else { + this._halfMoves++; + } + + if (us === BLACK) { + this._moveNumber++; + } + + this._turn = them; + } + + undo() { + const move = this._undoMove(); + return move ? this._makePretty(move) : null; + } + + private _undoMove() { + const old = this._history.pop(); + if (old === undefined) { + return null; + } + + const move = old.move; + + this._kings = old.kings; + this._turn = old.turn; + this._castling = old.castling; + this._epSquare = old.epSquare; + this._halfMoves = old.halfMoves; + this._moveNumber = old.moveNumber; + + const us = this._turn; + const them = swapColor(us); + + this._board[move.from] = this._board[move.to]; + this._board[move.from].type = move.piece; // to undo any promotions + delete this._board[move.to]; + + if (move.captured) { + if (move.flags & BITS.EP_CAPTURE) { + // en passant capture + let index: number; + if (us === BLACK) { + index = move.to - 16; + } else { + index = move.to + 16; + } + this._board[index] = { type: PAWN, color: them }; + } else { + // regular capture + this._board[move.to] = { type: move.captured, color: them }; + } + } + + if (move.flags & (BITS.KSIDE_CASTLE | BITS.QSIDE_CASTLE)) { + let castlingTo: number, castlingFrom: number; + if (move.flags & BITS.KSIDE_CASTLE) { + castlingTo = move.to + 1; + castlingFrom = move.to - 1; + } else { + castlingTo = move.to - 2; + castlingFrom = move.to + 1; + } + + this._board[castlingTo] = this._board[castlingFrom]; + delete this._board[castlingFrom]; + } + + return move; + } + + pgn({ + newline = "\n", + maxWidth = 0, + }: { newline?: string; maxWidth?: number } = {}) { + /* + * using the specification from http://www.chessclub.com/help/PGN-spec + * example for html usage: .pgn({ max_width: 72, newline_char: "
" }) + */ + + const result: string[] = []; + let headerExists = false; + + /* add the PGN header information */ + for (const i in this._header) { + /* + * TODO: order of enumerated properties in header object is not + * guaranteed, see ECMA-262 spec (section 12.6.4) + */ + result.push("[" + i + ' "' + this._header[i] + '"]' + newline); + headerExists = true; + } + + if (headerExists && this._history.length) { + result.push(newline); + } + + const appendComment = (moveString: string) => { + const comment = this._comments[this.fen()]; + if (typeof comment !== "undefined") { + const delimiter = moveString.length > 0 ? " " : ""; + moveString = `${moveString}${delimiter}{${comment}}`; + } + return moveString; + }; + + // pop all of history onto reversed_history + const reversedHistory = []; + while (this._history.length > 0) { + reversedHistory.push(this._undoMove()); + } + + const moves = []; + let moveString = ""; + + // special case of a commented starting position with no moves + if (reversedHistory.length === 0) { + moves.push(appendComment("")); + } + + // build the list of moves. a move_string looks like: "3. e3 e6" + while (reversedHistory.length > 0) { + moveString = appendComment(moveString); + const move = reversedHistory.pop(); + + // make TypeScript stop complaining about move being undefined + if (!move) { + break; + } + + // if the position started with black to move, start PGN with #. ... + if (!this._history.length && move.color === "b") { + const prefix = `${this._moveNumber}. ...`; + // is there a comment preceding the first move? + moveString = moveString ? `${moveString} ${prefix}` : prefix; + } else if (move.color === "w") { + // store the previous generated move_string if we have one + if (moveString.length) { + moves.push(moveString); + } + moveString = this._moveNumber + "."; + } + + moveString = + moveString + + " " + + this._moveToSan(move, this._moves({ legal: true })); + this._makeMove(move); + } + + // are there any other leftover moves? + if (moveString.length) { + moves.push(appendComment(moveString)); + } + + // is there a result? + if (typeof this._header.Result !== "undefined") { + moves.push(this._header.Result); + } + + /* + * history should be back to what it was before we started generating PGN, + * so join together moves + */ + if (maxWidth === 0) { + return result.join("") + moves.join(" "); + } + + // TODO (jah): huh? + const strip = function () { + if (result.length > 0 && result[result.length - 1] === " ") { + result.pop(); + return true; + } + return false; + }; + + // NB: this does not preserve comment whitespace. + const wrapComment = function (width: number, move: string) { + for (const token of move.split(" ")) { + if (!token) { + continue; + } + if (width + token.length > maxWidth) { + while (strip()) { + width--; + } + result.push(newline); + width = 0; + } + result.push(token); + width += token.length; + result.push(" "); + width++; + } + if (strip()) { + width--; + } + return width; + }; + + // wrap the PGN output at max_width + let currentWidth = 0; + for (let i = 0; i < moves.length; i++) { + if (currentWidth + moves[i].length > maxWidth) { + if (moves[i].includes("{")) { + currentWidth = wrapComment(currentWidth, moves[i]); + continue; + } + } + // if the current move will push past max_width + if (currentWidth + moves[i].length > maxWidth && i !== 0) { + // don't end the line with whitespace + if (result[result.length - 1] === " ") { + result.pop(); + } + + result.push(newline); + currentWidth = 0; + } else if (i !== 0) { + result.push(" "); + currentWidth++; + } + result.push(moves[i]); + currentWidth += moves[i].length; + } + + return result.join(""); + } + + header(...args: string[]) { + for (let i = 0; i < args.length; i += 2) { + if ( + typeof args[i] === "string" && + typeof args[i + 1] === "string" + ) { + this._header[args[i]] = args[i + 1]; + } + } + return this._header; + } + + loadPgn( + pgn: string, + { + strict = false, + newlineChar = "\r?\n", + }: { strict?: boolean; newlineChar?: string } = {} + ) { + function mask(str: string): string { + return str.replace(/\\/g, "\\"); + } + + function parsePgnHeader(header: string): { [key: string]: string } { + const headerObj: Record = {}; + const headers = header.split(new RegExp(mask(newlineChar))); + let key = ""; + let value = ""; + + for (let i = 0; i < headers.length; i++) { + const regex = /^\s*\[\s*([A-Za-z]+)\s*"(.*)"\s*\]\s*$/; + key = headers[i].replace(regex, "$1"); + value = headers[i].replace(regex, "$2"); + if (key.trim().length > 0) { + headerObj[key] = value; + } + } + + return headerObj; + } + + // strip whitespace from head/tail of PGN block + pgn = pgn.trim(); + + /* + * RegExp to split header. Takes advantage of the fact that header and movetext + * will always have a blank line between them (ie, two newline_char's). Handles + * case where movetext is empty by matching newlineChar until end of string is + * matched - effectively trimming from the end extra newlineChar. + * + * With default newline_char, will equal: + * /^(\[((?:\r?\n)|.)*\])((?:\s*\r?\n){2}|(?:\s*\r?\n)*$)/ + */ + const headerRegex = new RegExp( + "^(\\[((?:" + + mask(newlineChar) + + ")|.)*\\])" + + "((?:\\s*" + + mask(newlineChar) + + "){2}|(?:\\s*" + + mask(newlineChar) + + ")*$)" + ); + + // If no header given, begin with moves. + const headerRegexResults = headerRegex.exec(pgn); + const headerString = headerRegexResults + ? headerRegexResults.length >= 2 + ? headerRegexResults[1] + : "" + : ""; + + // Put the board in the starting position + this.reset(); + + // parse PGN header + const headers = parsePgnHeader(headerString); + let fen = ""; + + for (const key in headers) { + // check to see user is including fen (possibly with wrong tag case) + if (key.toLowerCase() === "fen") { + fen = headers[key]; + } + + this.header(key, headers[key]); + } + + /* + * the permissive parser should attempt to load a fen tag, even if it's the + * wrong case and doesn't include a corresponding [SetUp "1"] tag + */ + if (!strict) { + if (fen) { + this.load(fen, true); + } + } else { + /* + * strict parser - load the starting position indicated by [Setup '1'] + * and [FEN position] + */ + if (headers["SetUp"] === "1") { + if (!("FEN" in headers)) { + throw new Error( + "Invalid PGN: FEN tag must be supplied with SetUp tag" + ); + } + // second argument to load: don't clear the headers + this.load(headers["FEN"], true); + } + } + + /* + * NB: the regexes below that delete move numbers, recursive annotations, + * and numeric annotation glyphs may also match text in comments. To + * prevent this, we transform comments by hex-encoding them in place and + * decoding them again after the other tokens have been deleted. + * + * While the spec states that PGN files should be ASCII encoded, we use + * {en,de}codeURIComponent here to support arbitrary UTF8 as a convenience + * for modern users + */ + + function toHex(s: string): string { + return Array.from(s) + .map(function (c) { + /* + * encodeURI doesn't transform most ASCII characters, so we handle + * these ourselves + */ + return c.charCodeAt(0) < 128 + ? c.charCodeAt(0).toString(16) + : encodeURIComponent(c).replace(/%/g, "").toLowerCase(); + }) + .join(""); + } + + function fromHex(s: string): string { + return s.length == 0 + ? "" + : decodeURIComponent( + "%" + (s.match(/.{1,2}/g) || []).join("%") + ); + } + + const encodeComment = function (s: string) { + s = s.replace(new RegExp(mask(newlineChar), "g"), " "); + return `{${toHex(s.slice(1, s.length - 1))}}`; + }; + + const decodeComment = function (s: string) { + if (s.startsWith("{") && s.endsWith("}")) { + return fromHex(s.slice(1, s.length - 1)); + } + }; + + // delete header to get the moves + let ms = pgn + .replace(headerString, "") + .replace( + // encode comments so they don't get deleted below + new RegExp(`({[^}]*})+?|;([^${mask(newlineChar)}]*)`, "g"), + function (_match, bracket, semicolon) { + return bracket !== undefined + ? encodeComment(bracket) + : " " + encodeComment(`{${semicolon.slice(1)}}`); + } + ) + .replace(new RegExp(mask(newlineChar), "g"), " "); + + // delete recursive annotation variations + const ravRegex = /(\([^()]+\))+?/g; + while (ravRegex.test(ms)) { + ms = ms.replace(ravRegex, ""); + } + + // delete move numbers + ms = ms.replace(/\d+\.(\.\.)?/g, ""); + + // delete ... indicating black to move + ms = ms.replace(/\.\.\./g, ""); + + /* delete numeric annotation glyphs */ + ms = ms.replace(/\$\d+/g, ""); + + // trim and get array of moves + let moves = ms.trim().split(new RegExp(/\s+/)); + + // delete empty entries + moves = moves.filter(move => move !== ""); + + let result = ""; + + for (let halfMove = 0; halfMove < moves.length; halfMove++) { + const comment = decodeComment(moves[halfMove]); + if (comment !== undefined) { + this._comments[this.fen()] = comment; + continue; + } + + const move = this._moveFromSan(moves[halfMove], strict); + + // invalid move + if (move == null) { + // was the move an end of game marker + if (TERMINATION_MARKERS.indexOf(moves[halfMove]) > -1) { + result = moves[halfMove]; + } else { + throw new Error(`Invalid move in PGN: ${moves[halfMove]}`); + } + } else { + // reset the end of game marker if making a valid move + result = ""; + this._makeMove(move); + } + } + + /* + * Per section 8.2.6 of the PGN spec, the Result tag pair must match match + * the termination marker. Only do this when headers are present, but the + * result tag is missing + */ + + if ( + result && + Object.keys(this._header).length && + !this._header["Result"] + ) { + this.header("Result", result); + } + } + + /* + * Convert a move from 0x88 coordinates to Standard Algebraic Notation + * (SAN) + * + * @param {boolean} strict Use the strict SAN parser. It will throw errors + * on overly disambiguated moves (see below): + * + * r1bqkbnr/ppp2ppp/2n5/1B1pP3/4P3/8/PPPP2PP/RNBQK1NR b KQkq - 2 4 + * 4. ... Nge7 is overly disambiguated because the knight on c6 is pinned + * 4. ... Ne7 is technically the valid SAN + */ + + private _moveToSan(move: InternalMove, moves: InternalMove[]) { + let output = ""; + + if (move.flags & BITS.KSIDE_CASTLE) { + output = "O-O"; + } else if (move.flags & BITS.QSIDE_CASTLE) { + output = "O-O-O"; + } else { + if (move.piece !== PAWN) { + const disambiguator = getDisambiguator(move, moves); + output += move.piece.toUpperCase() + disambiguator; + } + + if (move.flags & (BITS.CAPTURE | BITS.EP_CAPTURE)) { + if (move.piece === PAWN) { + output += algebraic(move.from)[0]; + } + output += "x"; + } + + output += algebraic(move.to); + + if (move.promotion) { + output += "=" + move.promotion.toUpperCase(); + } + } + + this._makeMove(move); + if (this.isCheck()) { + if (this.isCheckmate()) { + output += "#"; + } else { + output += "+"; + } + } + this._undoMove(); + + return output; + } + + // convert a move from Standard Algebraic Notation (SAN) to 0x88 coordinates + private _moveFromSan(move: string, strict = false): InternalMove | null { + // strip off any move decorations: e.g Nf3+?! becomes Nf3 + const cleanMove = strippedSan(move); + + let pieceType = inferPieceType(cleanMove); + let moves = this._moves({ legal: true, piece: pieceType }); + + // strict parser + for (let i = 0, len = moves.length; i < len; i++) { + if (cleanMove === strippedSan(this._moveToSan(moves[i], moves))) { + return moves[i]; + } + } + + // the strict parser failed + if (strict) { + return null; + } + + let piece = undefined; + let matches = undefined; + let from = undefined; + let to = undefined; + let promotion = undefined; + + /* + * The default permissive (non-strict) parser allows the user to parse + * non-standard chess notations. This parser is only run after the strict + * Standard Algebraic Notation (SAN) parser has failed. + * + * When running the permissive parser, we'll run a regex to grab the piece, the + * to/from square, and an optional promotion piece. This regex will + * parse common non-standard notation like: Pe2-e4, Rc1c4, Qf3xf7, + * f7f8q, b1c3 + * + * NOTE: Some positions and moves may be ambiguous when using the permissive + * parser. For example, in this position: 6k1/8/8/B7/8/8/8/BN4K1 w - - 0 1, + * the move b1c3 may be interpreted as Nc3 or B1c3 (a disambiguated bishop + * move). In these cases, the permissive parser will default to the most + * basic interpretation (which is b1c3 parsing to Nc3). + */ + + let overlyDisambiguated = false; + + matches = cleanMove.match( + /([pnbrqkPNBRQK])?([a-h][1-8])x?-?([a-h][1-8])([qrbnQRBN])?/ + // piece from to promotion + ); + + if (matches) { + piece = matches[1]; + from = matches[2] as Square; + to = matches[3] as Square; + promotion = matches[4]; + + if (from.length == 1) { + overlyDisambiguated = true; + } + } else { + /* + * The [a-h]?[1-8]? portion of the regex below handles moves that may be + * overly disambiguated (e.g. Nge7 is unnecessary and non-standard when + * there is one legal knight move to e7). In this case, the value of + * 'from' variable will be a rank or file, not a square. + */ + + matches = cleanMove.match( + /([pnbrqkPNBRQK])?([a-h]?[1-8]?)x?-?([a-h][1-8])([qrbnQRBN])?/ + ); + + if (matches) { + piece = matches[1]; + from = matches[2] as Square; + to = matches[3] as Square; + promotion = matches[4]; + + if (from.length == 1) { + overlyDisambiguated = true; + } + } + } + + pieceType = inferPieceType(cleanMove); + moves = this._moves({ + legal: true, + piece: piece ? (piece as PieceSymbol) : pieceType, + }); + + for (let i = 0, len = moves.length; i < len; i++) { + if (from && to) { + // hand-compare move properties with the results from our permissive regex + if ( + (!piece || piece.toLowerCase() == moves[i].piece) && + Ox88[from] == moves[i].from && + Ox88[to] == moves[i].to && + (!promotion || + promotion.toLowerCase() == moves[i].promotion) + ) { + return moves[i]; + } else if (overlyDisambiguated) { + /* + * SPECIAL CASE: we parsed a move string that may have an unneeded + * rank/file disambiguator (e.g. Nge7). The 'from' variable will + */ + + const square = algebraic(moves[i].from); + if ( + (!piece || piece.toLowerCase() == moves[i].piece) && + Ox88[to] == moves[i].to && + (from == square[0] || from == square[1]) && + (!promotion || + promotion.toLowerCase() == moves[i].promotion) + ) { + return moves[i]; + } + } + } + } + + return null; + } + + ascii() { + let s = " +------------------------+\n"; + for (let i = Ox88.a8; i <= Ox88.h1; i++) { + // display the rank + if (file(i) === 0) { + s += " " + "87654321"[rank(i)] + " |"; + } + + if (this._board[i]) { + const piece = this._board[i].type; + const color = this._board[i].color; + const symbol = + color === WHITE ? piece.toUpperCase() : piece.toLowerCase(); + s += " " + symbol + " "; + } else { + s += " . "; + } + + if ((i + 1) & 0x88) { + s += "|\n"; + i += 8; + } + } + s += " +------------------------+\n"; + s += " a b c d e f g h"; + + return s; + } + + perft(depth: number) { + const moves = this._moves({ legal: false }); + let nodes = 0; + const color = this._turn; + + for (let i = 0, len = moves.length; i < len; i++) { + this._makeMove(moves[i]); + if (!this._isKingAttacked(color)) { + if (depth - 1 > 0) { + nodes += this.perft(depth - 1); + } else { + nodes++; + } + } + this._undoMove(); + } + + return nodes; + } + + // pretty = external move object + private _makePretty(uglyMove: InternalMove): Move { + const { color, piece, from, to, flags, captured, promotion } = uglyMove; + + let prettyFlags = ""; + + for (const flag in BITS) { + if (BITS[flag] & flags) { + prettyFlags += FLAGS[flag]; + } + } + + const fromAlgebraic = algebraic(from); + const toAlgebraic = algebraic(to); + + const move: Move = { + color, + piece, + from: fromAlgebraic, + to: toAlgebraic, + san: this._moveToSan(uglyMove, this._moves({ legal: true })), + flags: prettyFlags, + lan: fromAlgebraic + toAlgebraic, + before: this.fen(), + after: "", + }; + + // generate the FEN for the 'after' key + this._makeMove(uglyMove); + move.after = this.fen(); + this._undoMove(); + + if (captured) { + move.captured = captured; + } + if (promotion) { + move.promotion = promotion; + move.lan += promotion; + } + + return move; + } + + turn() { + return this._turn; + } + + board(): (false | { square: Square; type: PieceSymbol; color: Color })[][] { + const output: ( + | false + | { + square: Square; + type: PieceSymbol; + color: Color; + } + )[][] = []; + let row: ( + | false + | { + square: Square; + type: PieceSymbol; + color: Color; + } + )[] = []; + + for (let i = Ox88.a8; i <= Ox88.h1; i++) { + if (!this._board[i]) { + row.push(false); + } else { + row.push({ + square: algebraic(i), + type: this._board[i].type, + color: this._board[i].color, + }); + } + if ((i + 1) & 0x88) { + output.push(row); + row = []; + i += 8; + } + } + + return output; + } + + squareColor(square: Square): Color { + if (square in Ox88) { + const sq = Ox88[square]; + return (rank(sq) + file(sq)) % 2 === 0 ? "w" : "b"; + } + + return null; + } + + history(): string[]; + history({ verbose }: { verbose: true }): Move[]; + history({ verbose }: { verbose: false }): string[]; + history({ verbose }: { verbose: boolean }): string[] | Move[]; + history({ verbose = false }: { verbose?: boolean } = {}) { + const reversedHistory = []; + const moveHistory = []; + + while (this._history.length > 0) { + reversedHistory.push(this._undoMove()); + } + + while (true) { + const move = reversedHistory.pop(); + if (!move) { + break; + } + + if (verbose) { + moveHistory.push(this._makePretty(move)); + } else { + moveHistory.push(this._moveToSan(move, this._moves())); + } + this._makeMove(move); + } + + return moveHistory; + } + + private _pruneComments() { + const reversedHistory = []; + const currentComments: Record = {}; + + const copyComment = (fen: string) => { + if (fen in this._comments) { + currentComments[fen] = this._comments[fen]; + } + }; + + while (this._history.length > 0) { + reversedHistory.push(this._undoMove()); + } + + copyComment(this.fen()); + + while (true) { + const move = reversedHistory.pop(); + if (!move) { + break; + } + this._makeMove(move); + copyComment(this.fen()); + } + this._comments = currentComments; + } + + getComment() { + return this._comments[this.fen()]; + } + + setComment(comment: string) { + this._comments[this.fen()] = comment + .replace("{", "[") + .replace("}", "]"); + } + + deleteComment() { + const comment = this._comments[this.fen()]; + delete this._comments[this.fen()]; + return comment; + } + + getComments() { + this._pruneComments(); + return Object.keys(this._comments).map((fen: string) => { + return { fen: fen, comment: this._comments[fen] }; + }); + } + + deleteComments() { + this._pruneComments(); + return Object.keys(this._comments).map(fen => { + const comment = this._comments[fen]; + delete this._comments[fen]; + return { fen: fen, comment: comment }; + }); + } +} diff --git a/chessfont.png b/chessfont.png new file mode 100755 index 0000000..7d175b9 Binary files /dev/null and b/chessfont.png differ diff --git a/favicon.ico b/favicon.ico new file mode 100644 index 0000000..72ca802 Binary files /dev/null and b/favicon.ico differ diff --git a/favicon.png b/favicon.png new file mode 100644 index 0000000..b8d5c33 Binary files /dev/null and b/favicon.png differ diff --git a/index.html b/index.html new file mode 100644 index 0000000..be0d5f9 --- /dev/null +++ b/index.html @@ -0,0 +1,122 @@ + + + + Elo Worldle + + + + + + + + + + + + +

+

+        
+        
+

Players: (click name to toggle strikethrough)

+
+ + diff --git a/main.css b/main.css new file mode 100644 index 0000000..e69de29 diff --git a/main.js b/main.js new file mode 100644 index 0000000..6285886 --- /dev/null +++ b/main.js @@ -0,0 +1,706 @@ +var _a; +import { Chess, Ox88, DEFAULT_POSITION, SQUARES, rank, file, WHITE, BLACK, KING, } from "./chess.js"; +function with_move(board, move) { + let new_board = new Chess(board.fen()); + new_board.move(move); + return new_board; +} +// function max_move_by(board: Chess, score: (_: Chess) => number): string { +// let best_score = 0; +// let best_move = ""; +// for (const move in board.moves()) { +// let new_board = with_move(board, move); +// let new_score = score(new_board); +// if ( +// new_score > best_score || +// (new_score == new_score && Math.random() > 0.5) +// ) { +// best_score = new_score; +// best_move = move; +// } +// } +// return best_move; +// } +// could return early if zero but meh +function min_move_by(board, score) { + let best_score = Infinity; + let best_move = ""; + let moves = board.moves(); + // console.log(moves); + for (const i in moves) { + let move = moves[i]; + try { + let new_board = with_move(board, move); + let new_score = score(new_board); + // console.log({ move, best_score, new_score, best_move }); + if (new_score < best_score || + (new_score == best_score && Math.random() > 0.5)) { + console.log("New best (or equal): ", new_score, move); + best_score = new_score; + best_move = move; + } + } + catch (e) { + console.error(e); + continue; + } + } + return best_move; +} +// D --> movelist users (bad name whatever) +const random_move = board => { + const moves = board.moves(); + const move = moves[Math.floor(Math.random() * moves.length)]; + return move; +}; +function make_lexo(m) { + let { rank: src_row, file: src_col } = rank_and_file(m.from); + let { rank: dst_row, file: dst_col } = rank_and_file(m.to); + let promote_to = m.promotion; + return [src_row, src_col, dst_row, dst_col, promote_to]; +} +function lexo_sort_moves(a, b) { + let al = make_lexo(a); + let bl = make_lexo(a); + for (const i in al) { + if (al[i] < bl[i]) { + return -1; + } + else if (al[i] > bl[i]) { + return 1; + } + } + return 0; +} +const first_move = board => { + const moves = board.moves({ verbose: true }).sort(lexo_sort_moves); + return moves[0].san; +}; +const alphabetical = board => { + const moves = board.moves(); + moves.sort(); + return moves[0]; +}; +// i believe the actual one tracks things better (pawns are treated as different) +// yeah this version sucks butttttt uh +// yeah +// prettier-ignore +var equalizer_state = { + piece_moves: { + p: 0, + b: 0, + n: 0, + r: 0, + q: 0, + k: 0, + }, + // bad + square_visits: { + a8: 0, b8: 0, c8: 0, d8: 0, e8: 0, f8: 0, g8: 0, h8: 0, + a7: 0, b7: 0, c7: 0, d7: 0, e7: 0, f7: 0, g7: 0, h7: 0, + a6: 0, b6: 0, c6: 0, d6: 0, e6: 0, f6: 0, g6: 0, h6: 0, + a5: 0, b5: 0, c5: 0, d5: 0, e5: 0, f5: 0, g5: 0, h5: 0, + a4: 0, b4: 0, c4: 0, d4: 0, e4: 0, f4: 0, g4: 0, h4: 0, + a3: 0, b3: 0, c3: 0, d3: 0, e3: 0, f3: 0, g3: 0, h3: 0, + a2: 0, b2: 0, c2: 0, d2: 0, e2: 0, f2: 0, g2: 0, h2: 0, + a1: 0, b1: 0, c1: 0, d1: 0, e1: 0, f1: 0, g1: 0, h1: 0 + } +}; +const equalizer = board => { + let best_move; + let least_moved_found = Infinity; + let least_visited_found = Infinity; + let piece_moving = "k"; + let square_visiting = "a1"; + // let least_moved = PIECE_SYMBOLS.sort( + // (a, b) => + // equalizer_state.piece_moves[a] - equalizer_state.piece_moves[b] + // )[0]; + // let least_visited = SQUARES.sort( + // (a, b) => + // equalizer_state.square_visits[a] - equalizer_state.square_visits[b] + // )[0]; + // cbb to do the proper randomness (23:41) + for (const move of board.moves({ verbose: true })) { + if (equalizer_state.piece_moves[move.piece] < least_moved_found || + (equalizer_state.piece_moves[move.piece] == least_moved_found && + equalizer_state.square_visits[move.to] < least_visited_found)) { + best_move = move; + least_moved_found = equalizer_state.piece_moves[move.piece]; + least_visited_found = equalizer_state.square_visits[move.to]; + piece_moving = move.piece; + square_visiting = move.to; + } + } + equalizer_state.piece_moves[piece_moving] += 1; + equalizer_state.square_visits[square_visiting] += 1; + return best_move.san; +}; +// D --> min-maxxing some score of the board after moving +const min_oppt_move = board => { + let num_moves = b => b.moves().length; + return min_move_by(board, num_moves); +}; +function num_pieces_on_own_color(b) { + let count = 0; + for (const square of SQUARES) { + let piece = b.get(square); + if (typeof piece == "boolean") { + continue; + } + if (piece.color == b.squareColor(square)) { + count += 1; + } + } + return count; +} +const same_color = board => { + return min_move_by(board, b => 64 - num_pieces_on_own_color(b)); +}; +const opposite_color = board => { + return min_move_by(board, num_pieces_on_own_color); +}; +function rank_and_file(s) { + return { rank: rank(Ox88[s]), file: file(Ox88[s]) }; +} +function chebyshev_distance(a, b) { + let { rank: r1, file: f1 } = rank_and_file(a); + let { rank: r2, file: f2 } = rank_and_file(b); + // forgot the abs UGH + return Math.max(Math.abs(r2 - r1), Math.abs(f2 - f1)); +} +const START_BOARD = new Chess(DEFAULT_POSITION); +// good enough +function move_distance(piece) { + let rank = rank_and_file(piece.square).rank; + let file = rank_and_file(piece.square).file; + switch (piece.type) { + case "k": + return chebyshev_distance(piece.square, find({ color: HUMAN_COLOR, type: "k" }, START_BOARD)); + case "p": + return Math.abs(rank - 6); + case "r": + return (Math.abs(rank - 7) + + Math.min(Math.abs(file - 7), Math.abs(file - 0))); + case "n": + // inauthentic + return pieces_of_color(START_BOARD, HUMAN_COLOR) + .filter(p => p.type == "k") + .map(p => chebyshev_distance(piece.square, p.square)) + .reduce((a, b) => Math.max(a, b)); + case "b": + let is_black = START_BOARD.squareColor(piece.square) == "b"; + let dest_col = is_black ? 2 : 5; + let dr = Math.abs(rank - 7); + let dc = Math.abs(file - dest_col); + return Math.max(dr, dc); + case "q": + return Math.max(Math.abs(rank - 7), Math.abs(file - 3)); + } +} +// oh gosh i can do symmetry by making the "distance" just a score fn which +// would... work but dang so many things have done something similar in hindsight +// actually hm symmetry is weird +function minimize_distances(distance_fn) { + const player_score = (board) => { + let total_distance = 0; + for (const piece of pieces_of_color(board, ROBOT_COLOR)) { + total_distance += distance_fn(piece); + } + return total_distance; + }; + return b => min_move_by(b, player_score); +} +const reverse_starting = minimize_distances(move_distance); +// or lens :] +function mirror_player(mirror_fn) { + let player_score = (b) => { + // it's worrying how the strategies have shifted, before it was more + // common for them to weigh your pieces equally, meaning they might take + // them to make the score better; silver lining: a bit easier to tell + // apart potentially + // the penalties are taken from the og code (the last four are the ones + // where i finally figured out where to find the players (curse_you + // UpperCamelCase)) + // the behavior is likely still slightly different + let total = 0; + for (const square of SQUARES) { + let reflected = mirror_fn(square); + console.log(square, reflected); + let piece = b.get(square); + let reflection = b.get(reflected); + if (typeof piece == "boolean" && typeof reflection == "boolean") { + continue; + } + if (typeof piece == "boolean") { + total += 10; + continue; + } + if (typeof reflection == "boolean") { + total += 10; + continue; + } + if (piece.color == reflection.color) { + total += 5; + continue; + } + if (piece.type != reflection.type) { + total += 1; + continue; + } + } + return total; + }; + return b => min_move_by(b, player_score); +} +function rank_and_file_to_algebraic(rf) { + let r = "8"; + let f = "h"; + // vim's was very helpful here :] + // I WAS MIRRORING AND THEN MIRRORING AGAIN OH MY GOOOOOSH + // prettier-ignore + switch (rf.rank) { + case 0: + r = "8"; + break; + case 1: + r = "7"; + break; + case 2: + r = "6"; + break; + case 3: + r = "5"; + break; + case 4: + r = "4"; + break; + case 5: + r = "3"; + break; + case 6: + r = "7"; + break; + case 7: + r = "1"; + break; + } + // prettier-ignore + switch (rf.file) { + case 0: + f = "a"; + break; + case 1: + f = "b"; + break; + case 2: + f = "c"; + break; + case 3: + f = "d"; + break; + case 4: + f = "e"; + break; + case 5: + f = "f"; + break; + case 6: + f = "g"; + break; + case 7: + f = "h"; + break; + } + return `${f}${r}`; +} +function mirror_y(s) { + let rf = rank_and_file(s); + rf.rank = 7 - rf.rank; + return rank_and_file_to_algebraic(rf); +} +const sym_mirror_y = mirror_player(mirror_y); +function mirror_x(s) { + let rf = rank_and_file(s); + rf.file = 7 - rf.file; + return rank_and_file_to_algebraic(rf); +} +const sym_mirror_x = mirror_player(mirror_x); +function flip(s) { + let rf = rank_and_file(s); + rf.rank = 7 - rf.rank; + rf.file = 7 - rf.file; + return rank_and_file_to_algebraic(rf); +} +const sym_180 = mirror_player(flip); +function find(p, b) { + for (const square of SQUARES) { + let got = b.get(square); + if (typeof got == "boolean") { + continue; + } + if (got.color == p.color && got.type == p.type) { + return square; + } + } + console.log(`didn't find this :O ${p}`); + return null; +} +// maybe a find function would be useful Piece -> Board -> Square | null +const suicide_king = board => { + let distance_between_kings = (b) => { + var _a, _b; + return chebyshev_distance((_a = find({ color: WHITE, type: KING }, b)) !== null && _a !== void 0 ? _a : "a1", (_b = find({ color: BLACK, type: KING }, b)) !== null && _b !== void 0 ? _b : "a1"); + }; + return min_move_by(board, distance_between_kings); +}; +// cccp and pacifist are basically opposites +// ugh not really +function pieces_of_color(b, color) { + let flat_board = b.board().flat(); + let non_empties = []; + for (const s of flat_board) { + if (typeof s == "boolean") { + continue; + } + non_empties.push(s); + } + return non_empties.filter(p => p.color == color); +} +function num_pieces_of_color(b, color) { + return pieces_of_color(b, color).length; +} +// see generous in http://tom7.org/chess/weak.pdf +function value_piece(type) { + switch (type) { + case "p": + return 1; + case "b": + case "n": + return 3; + case "r": + return 5; + case "q": + return 9; + case "k": + // impossible (mostly) + // idk why i said this it's really not impossible lol + return 413; + } +} +function value_of_pieces_of_color(b, color) { + return pieces_of_color(b, color) + .map(p => value_piece(p.type)) + .reduce((a, b) => a + b); +} +// hm +const HUMAN_COLOR = WHITE; +const ROBOT_COLOR = BLACK; +// DONE: I THINK: UGH piece value +const cccp = board => { + let cccp_score = (b) => { + if (b.isCheckmate()) { + console.log("Found checkmate! :D"); + return 0; + } + if (b.isCheck()) { + console.log("Found check! :T"); + return 1; + } + // maximize the difference in value + let prev_value = value_of_pieces_of_color(board, HUMAN_COLOR); + let new_value = value_of_pieces_of_color(b, HUMAN_COLOR); + if (new_value < prev_value) { + console.log("There's less human-colored pieces now! :)"); + return 10 * (6 - (prev_value - new_value)); + } + // sum the ranks of the robot pieces (brittle with piece colors changing which uhh just don't do that :)) + // they are zero based oopsie + return (100 * + pieces_of_color(b, ROBOT_COLOR) + .map(b => 8 - rank_and_file(b.square).rank) + .reduce((a, b) => a + b)); + }; + return min_move_by(board, cccp_score); +}; +// FIXME: function name is TOO short FIX +function total_chebyshev_distances_of_pieces_of_color_to_square(board, color, square) { + return pieces_of_color(board, color) + .map(p => chebyshev_distance(p.square, square)) + .reduce((a, b) => a + b); +} +const huddle = board => { + return min_move_by(board, b => { + var _a; + return total_chebyshev_distances_of_pieces_of_color_to_square(b, ROBOT_COLOR, (_a = find({ color: ROBOT_COLOR, type: KING }, b)) !== null && _a !== void 0 ? _a : "a1"); + }); +}; +const swarm = board => { + return min_move_by(board, b => { + var _a; + return total_chebyshev_distances_of_pieces_of_color_to_square(b, ROBOT_COLOR, (_a = find({ color: HUMAN_COLOR, type: KING }, b)) !== null && _a !== void 0 ? _a : "a1"); + }); +}; +function sum_of_possible_capture_value(b) { + let prev_value = value_of_pieces_of_color(b, ROBOT_COLOR); + let sum = 0; + for (const move of b.moves()) { + let new_board = with_move(b, move); + let new_value = value_of_pieces_of_color(new_board, ROBOT_COLOR); + // value only goes down..... pretty much + // but the negation is now done by the guys so + sum += prev_value - new_value; + } + return sum; +} +// surprisingly not too difficult +const generous = board => { + // sum of the difference in ROBOT_COLOR piece value of all moves + // but like uhh negative + let generous_score = (b) => { + return -sum_of_possible_capture_value(b); + }; + return min_move_by(board, generous_score); +}; +const no_i_insist = board => { + let no_i_insist_score = (b) => { + if (b.isCheckmate()) { + return 612; + } + if (b.isCheck()) { + return 413; + } + let prev_value = value_of_pieces_of_color(b, ROBOT_COLOR); + return -(sum_of_possible_capture_value(b) / b.moves().length); + }; + return min_move_by(board, no_i_insist_score); +}; +const pacifist = board => { + let pacifist_score = b => { + if (b.isCheckmate()) { + return 612; + } + if (b.isCheck()) { + return 413; + } + let prev_value = value_of_pieces_of_color(board, HUMAN_COLOR); + let new_value = value_of_pieces_of_color(b, HUMAN_COLOR); + if (new_value < prev_value) { + return prev_value - new_value; + } + return 0; + }; + return min_move_by(board, pacifist_score); +}; +const players = [ + { + f: random_move, + name: "random_move", + description: "Moves randomly, believe it or not.", + }, + { + f: same_color, + name: "same_color", + description: "Makes the move that maximizes the number of pieces on their own color", + }, + { + f: opposite_color, + name: "opposite_color", + description: "Behavior left as an exercise to the reader", + }, + { + f: pacifist, + name: "pacifist", + description: "Avoids checkmate, then avoids checks, then avoids captures, if forced, captures the lowest value piece it can", + }, + { + f: first_move, + name: "first_move", + description: "Makes the lexicographically first move based on [source_row, source_col, dest_row, dest_col, promotion]", + }, + { + f: alphabetical, + name: "alphabetical", + description: "Makes the first move asciilphabetically (based on algebraic notation)", + }, + { + f: huddle, + name: "huddle", + description: "Makes the move that minimizes the total Chebyshev distances from their pieces to their king", + }, + { + f: swarm, + name: "swarm", + description: "Makes the move that minimizes the total Chebyshev distances from their pieces to YOUR king", + }, + { + f: generous, + name: "generous", + description: "Maximizes the number of YOUR moves that take their pieces, weighting by value", + }, + { + f: no_i_insist, + name: "no_i_insist", + description: "Maximizes the proportion of potential capture value of YOUR moves to the number of YOUR moves; very weird the way i've done it", + }, + { + f: reverse_starting, + name: "reverse_starting", + description: "Makes the move that minimizes the number of moves it takes to move their pieces to the opposite end", + }, + { + f: cccp, + name: "cccp", + description: "First checkmates, then checks, then captures (the best piece it can), then pushes", + }, + { + f: suicide_king, + name: "suicide_king", + description: "Makes the move that minimizes the Chebyshev distance between the two kings", + }, + { + f: sym_mirror_y, + name: "sym_mirror_y", + description: "Tries to make the board as vertically symmetric as possible (basically copies your moves)", + }, + { + f: sym_mirror_x, + name: "sym_mirror_x", + description: "Tries to make the board as horizontally symmetric as possible (basically doesn't copy your moves or do anything useful)", + }, + { + f: sym_180, + name: "sym_180", + description: "Tries to make the board as symmetric as possible when flipped around", + }, + { + f: min_oppt_move, + name: "min_oppt_move", + description: "Does the move that leaves the least moves for YOU", + }, + { + f: equalizer, + name: "equalizer", + description: "Moves the least moved piece (actually piece type, e.g. moving a pawn counts for all pawns; it sucks, i know), breaking ties by moving to the least visited square", + }, + // alphabetical is fine i guess, since the checklist order has little to do with the og paper + // ehhh nvm +]; //.sort((a, b) => a.name.localeCompare(b.name)); +// https://stackoverflow.com/questions/12739171/javascript-epoch-time-in-days +function days_since_epoch() { + var now = new Date().getMilliseconds(); + return Math.floor(now / 8.64e7); +} +function find_specified_in_hash() { + return players.find(p => `#${p.name}` == window.location.hash); +} +// bad +// const todays_player = players[days_since_epoch() % players.length]; +const todays_player = (_a = find_specified_in_hash()) !== null && _a !== void 0 ? _a : players[Math.floor(Math.random() * players.length)]; +console.log(`SPOILER: today's player is ${todays_player.name}`); +// const todays_player = min_oppt_move; +const board = document.getElementById("board"); +const game = new Chess(); +function computer_move() { + num_moves++; + console.log(num_moves); + return todays_player.f(game); +} +// might want to change this when it's more wordly +function show_game_over() { + let game_over = document.getElementById("game-over"); + game_over.style.display = "block"; + game_over.innerText = `GAME OVER; player was ${todays_player.name}`; + console.log("GAME OVER"); +} +function show_win() { + let game_over = document.getElementById("game-over"); + game_over.style.display = "block"; + game_over.innerText = "YOU WIN YOU WIN YOU WIN YOU WIN HOLY CRAP"; + let stats = document.getElementById("stats"); + stats.style.display = "block"; + let stats_text = `#EloWorldle413\nGuesses: ${num_guesses}\nMoves: ${num_moves}`; + stats.innerText = stats_text; + let copy_stats = document.getElementById("copy-stats"); + copy_stats.style.display = "block"; + copy_stats.addEventListener("click", _ => navigator.clipboard.writeText(stats_text)); + console.log("PLAYER IS WIN"); +} +var num_guesses = 0; +var num_moves = 0; +function append_players_to(n) { + for (const player of players) { + let child = document.createElement("div"); + child.classList.add("player"); + let child_name = document.createElement("h1"); + child_name.classList.add("player-name"); + child_name.innerText = player.name; + let child_desc = document.createElement("p"); + child_desc.classList.add("player-desc"); + child_desc.innerText = player.description; + let guess_button = document.createElement("button"); + guess_button.innerText = "^ guess ^"; + guess_button.onclick = _ => { + num_guesses++; + if (todays_player.name == player.name) { + show_win(); + child.classList.add("correct"); + } + else { + child.classList.add("wrong"); + } + guess_button.onclick = () => { }; + }; + child.appendChild(child_name); + child.appendChild(child_desc); + child.appendChild(guess_button); + child_name.addEventListener("click", _ => child.classList.toggle("strikethrough")); + n.appendChild(child); + } +} +window.addEventListener("DOMContentLoaded", () => { + board.addEventListener("movestart", (e) => { + console.log(`Move started: ${e.detail.from}, ${e.detail.piece.color} ${e.detail.piece.pieceType}`); + e.detail.setTargets( + // This produces a list like ["e3", "e5"] + game.moves({ square: e.detail.from, verbose: true }).map(m => m.to)); + if (game.isGameOver()) { + show_game_over(); + } + }); + board.addEventListener("moveend", (e) => { + console.log(`Move ending: ${e.detail.from} -> ${e.detail.to}, ${e.detail.piece.color} ${e.detail.piece.pieceType}`); + const move = game.move({ + from: e.detail.from, + to: e.detail.to, + promotion: "q", + }); + if (move === null) { + e.preventDefault(); + } + if (game.isGameOver()) { + show_game_over(); + } + }); + board.addEventListener("movefinished", (e) => { + board.fen = game.fen(); + board.turn = game.turn() === "w" ? "white" : "black"; + board.interactive = game.turn() === "w"; + if (!board.interactive) { + let move = computer_move(); + if (!move) { + console.log("Didn't get a move from the computer (this is fine if the game is over)"); + return; + } + console.log(`Computer move: ${move}`); + game.move(move); + board.fen = game.fen(); + board.turn = "white"; + board.interactive = true; + } + }); + document + .getElementById("finish") + .addEventListener("click", _ => show_game_over()); + append_players_to(document.getElementById("players")); +}); diff --git a/main.ts b/main.ts new file mode 100644 index 0000000..1404c23 --- /dev/null +++ b/main.ts @@ -0,0 +1,858 @@ +import { + Chess, + Move, + Square, + Ox88, + DEFAULT_POSITION, + SQUARES, + rank, + file, + Piece, + WHITE, + BLACK, + KING, + PieceSymbol, + Color, + PIECE_SYMBOLS, +} from "./chess.js"; + +type Player = (_: Chess) => string; + +function with_move(board: Chess, move: string): Chess { + let new_board = new Chess(board.fen()); + new_board.move(move); + return new_board; +} + +// function max_move_by(board: Chess, score: (_: Chess) => number): string { +// let best_score = 0; +// let best_move = ""; + +// for (const move in board.moves()) { +// let new_board = with_move(board, move); +// let new_score = score(new_board); + +// if ( +// new_score > best_score || +// (new_score == new_score && Math.random() > 0.5) +// ) { +// best_score = new_score; +// best_move = move; +// } +// } + +// return best_move; +// } + +// could return early if zero but meh +function min_move_by(board: Chess, score: (_: Chess) => number): string { + let best_score = Infinity; + let best_move = ""; + + let moves = board.moves(); + // console.log(moves); + for (const i in moves) { + let move = moves[i]; + try { + let new_board = with_move(board, move); + let new_score = score(new_board); + // console.log({ move, best_score, new_score, best_move }); + + if ( + new_score < best_score || + (new_score == best_score && Math.random() > 0.5) + ) { + console.log("New best (or equal): ", new_score, move); + best_score = new_score; + best_move = move; + } + } catch (e) { + console.error(e); + continue; + } + } + return best_move; +} + +// D --> movelist users (bad name whatever) +const random_move: Player = board => { + const moves = board.moves(); + const move = moves[Math.floor(Math.random() * moves.length)]; + return move; +}; + +function make_lexo(m: Move): [number, number, number, number, PieceSymbol] { + let { rank: src_row, file: src_col } = rank_and_file(m.from); + let { rank: dst_row, file: dst_col } = rank_and_file(m.to); + let promote_to = m.promotion; + + return [src_row, src_col, dst_row, dst_col, promote_to]; +} + +function lexo_sort_moves(a: Move, b: Move): -1 | 0 | 1 { + let al = make_lexo(a); + let bl = make_lexo(a); + for (const i in al) { + if (al[i] < bl[i]) { + return -1; + } else if (al[i] > bl[i]) { + return 1; + } + } + + return 0; +} + +const first_move: Player = board => { + const moves = board.moves({ verbose: true }).sort(lexo_sort_moves); + return moves[0].san; +}; + +const alphabetical: Player = board => { + const moves = board.moves(); + moves.sort(); + + return moves[0]; +}; + +// i believe the actual one tracks things better (pawns are treated as different) +// yeah this version sucks butttttt uh +// yeah +// prettier-ignore +var equalizer_state: { + piece_moves: Record; + square_visits: Record; +} = { + piece_moves: { + p: 0, + b: 0, + n: 0, + r: 0, + q: 0, + k: 0, + }, + // bad + square_visits: { + a8: 0, b8: 0, c8: 0, d8: 0, e8: 0, f8: 0, g8: 0, h8: 0, + a7: 0, b7: 0, c7: 0, d7: 0, e7: 0, f7: 0, g7: 0, h7: 0, + a6: 0, b6: 0, c6: 0, d6: 0, e6: 0, f6: 0, g6: 0, h6: 0, + a5: 0, b5: 0, c5: 0, d5: 0, e5: 0, f5: 0, g5: 0, h5: 0, + a4: 0, b4: 0, c4: 0, d4: 0, e4: 0, f4: 0, g4: 0, h4: 0, + a3: 0, b3: 0, c3: 0, d3: 0, e3: 0, f3: 0, g3: 0, h3: 0, + a2: 0, b2: 0, c2: 0, d2: 0, e2: 0, f2: 0, g2: 0, h2: 0, + a1: 0, b1: 0, c1: 0, d1: 0, e1: 0, f1: 0, g1: 0, h1: 0 + } +}; + +const equalizer: Player = board => { + let best_move: Move; + let least_moved_found = Infinity; + let least_visited_found = Infinity; + let piece_moving: PieceSymbol = "k"; + let square_visiting: Square = "a1"; + + // let least_moved = PIECE_SYMBOLS.sort( + // (a, b) => + // equalizer_state.piece_moves[a] - equalizer_state.piece_moves[b] + // )[0]; + // let least_visited = SQUARES.sort( + // (a, b) => + // equalizer_state.square_visits[a] - equalizer_state.square_visits[b] + // )[0]; + + // cbb to do the proper randomness (23:41) + for (const move of board.moves({ verbose: true })) { + if ( + equalizer_state.piece_moves[move.piece] < least_moved_found || + (equalizer_state.piece_moves[move.piece] == least_moved_found && + equalizer_state.square_visits[move.to] < least_visited_found) + ) { + best_move = move; + least_moved_found = equalizer_state.piece_moves[move.piece]; + least_visited_found = equalizer_state.square_visits[move.to]; + piece_moving = move.piece; + square_visiting = move.to; + } + } + + equalizer_state.piece_moves[piece_moving] += 1; + equalizer_state.square_visits[square_visiting] += 1; + + return best_move.san; +}; + +// D --> min-maxxing some score of the board after moving +const min_oppt_move: Player = board => { + let num_moves = b => b.moves().length; + return min_move_by(board, num_moves); +}; + +function num_pieces_on_own_color(b: Chess): number { + let count = 0; + for (const square of SQUARES) { + let piece = b.get(square); + if (typeof piece == "boolean") { + continue; + } + if (piece.color == b.squareColor(square)) { + count += 1; + } + } + return count; +} + +const same_color: Player = board => { + return min_move_by(board, b => 64 - num_pieces_on_own_color(b)); +}; + +const opposite_color: Player = board => { + return min_move_by(board, num_pieces_on_own_color); +}; + +function rank_and_file(s: Square): { rank: number; file: number } { + return { rank: rank(Ox88[s]), file: file(Ox88[s]) }; +} + +function chebyshev_distance(a: Square, b: Square): number { + let { rank: r1, file: f1 } = rank_and_file(a); + let { rank: r2, file: f2 } = rank_and_file(b); + // forgot the abs UGH + return Math.max(Math.abs(r2 - r1), Math.abs(f2 - f1)); +} + +const START_BOARD: Chess = new Chess(DEFAULT_POSITION); + +// good enough +function move_distance(piece: { square: Square; type: PieceSymbol }): number { + let rank = rank_and_file(piece.square).rank; + let file = rank_and_file(piece.square).file; + switch (piece.type) { + case "k": + return chebyshev_distance( + piece.square, + find({ color: HUMAN_COLOR, type: "k" }, START_BOARD) + ); + case "p": + return Math.abs(rank - 6); + case "r": + return ( + Math.abs(rank - 7) + + Math.min(Math.abs(file - 7), Math.abs(file - 0)) + ); + case "n": + // inauthentic + return pieces_of_color(START_BOARD, HUMAN_COLOR) + .filter(p => p.type == "k") + .map(p => chebyshev_distance(piece.square, p.square)) + .reduce((a, b) => Math.max(a, b)); + case "b": + let is_black = START_BOARD.squareColor(piece.square) == "b"; + let dest_col = is_black ? 2 : 5; + let dr = Math.abs(rank - 7); + let dc = Math.abs(file - dest_col); + return Math.max(dr, dc); + case "q": + return Math.max(Math.abs(rank - 7), Math.abs(file - 3)); + } +} + +// oh gosh i can do symmetry by making the "distance" just a score fn which +// would... work but dang so many things have done something similar in hindsight +// actually hm symmetry is weird +function minimize_distances( + distance_fn: (piece: { square: Square; type: PieceSymbol }) => number +): Player { + const player_score = (board: Chess) => { + let total_distance = 0; + + for (const piece of pieces_of_color(board, ROBOT_COLOR)) { + total_distance += distance_fn(piece); + } + + return total_distance; + }; + + return b => min_move_by(b, player_score); +} + +const reverse_starting: Player = minimize_distances(move_distance); + +// or lens :] +function mirror_player(mirror_fn: (_: Square) => Square): Player { + let player_score = (b: Chess) => { + // it's worrying how the strategies have shifted, before it was more + // common for them to weigh your pieces equally, meaning they might take + // them to make the score better; silver lining: a bit easier to tell + // apart potentially + + // the penalties are taken from the og code (the last four are the ones + // where i finally figured out where to find the players (curse_you + // UpperCamelCase)) + // the behavior is likely still slightly different + let total = 0; + for (const square of SQUARES) { + let reflected = mirror_fn(square); + console.log(square, reflected); + let piece = b.get(square); + let reflection = b.get(reflected); + + if (typeof piece == "boolean" && typeof reflection == "boolean") { + continue; + } + + if (typeof piece == "boolean") { + total += 10; + continue; + } + + if (typeof reflection == "boolean") { + total += 10; + continue; + } + + if (piece.color == reflection.color) { + total += 5; + continue; + } + + if (piece.type != reflection.type) { + total += 1; + continue; + } + } + + return total; + }; + + return b => min_move_by(b, player_score); +} + +function rank_and_file_to_algebraic(rf: { + rank: number; + file: number; +}): Square { + let r: "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" = "8"; + let f: "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" = "h"; + + // vim's was very helpful here :] + // I WAS MIRRORING AND THEN MIRRORING AGAIN OH MY GOOOOOSH + // prettier-ignore + switch (rf.rank) { + case 0: r = "8"; break; + case 1: r = "7"; break; + case 2: r = "6"; break; + case 3: r = "5"; break; + case 4: r = "4"; break; + case 5: r = "3"; break; + case 6: r = "7"; break; + case 7: r = "1"; break; + } + + // prettier-ignore + switch (rf.file) { + case 0: f = "a"; break; + case 1: f = "b"; break; + case 2: f = "c"; break; + case 3: f = "d"; break; + case 4: f = "e"; break; + case 5: f = "f"; break; + case 6: f = "g"; break; + case 7: f = "h"; break; + } + + return `${f}${r}`; +} + +function mirror_y(s: Square): Square { + let rf = rank_and_file(s); + rf.rank = 7 - rf.rank; + return rank_and_file_to_algebraic(rf); +} + +const sym_mirror_y: Player = mirror_player(mirror_y); + +function mirror_x(s: Square): Square { + let rf = rank_and_file(s); + rf.file = 7 - rf.file; + return rank_and_file_to_algebraic(rf); +} + +const sym_mirror_x: Player = mirror_player(mirror_x); + +function flip(s: Square): Square { + let rf = rank_and_file(s); + rf.rank = 7 - rf.rank; + rf.file = 7 - rf.file; + return rank_and_file_to_algebraic(rf); +} + +const sym_180: Player = mirror_player(flip); + +function find(p: Piece, b: Chess): Square | null { + for (const square of SQUARES) { + let got = b.get(square); + if (typeof got == "boolean") { + continue; + } + if (got.color == p.color && got.type == p.type) { + return square; + } + } + console.log(`didn't find this :O ${p}`); + return null; +} + +// maybe a find function would be useful Piece -> Board -> Square | null +const suicide_king: Player = board => { + let distance_between_kings = (b: Chess) => + chebyshev_distance( + find({ color: WHITE, type: KING }, b) ?? "a1", + find({ color: BLACK, type: KING }, b) ?? "a1" + ); + return min_move_by(board, distance_between_kings); +}; + +// cccp and pacifist are basically opposites +// ugh not really + +function pieces_of_color( + b: Chess, + color: Color +): { square: Square; type: PieceSymbol; color: Color }[] { + let flat_board = b.board().flat(); + let non_empties: { square: Square; type: PieceSymbol; color: Color }[] = []; + for (const s of flat_board) { + if (typeof s == "boolean") { + continue; + } + non_empties.push(s); + } + + return non_empties.filter(p => p.color == color); +} + +function num_pieces_of_color(b: Chess, color: Color): number { + return pieces_of_color(b, color).length; +} +// see generous in http://tom7.org/chess/weak.pdf +function value_piece(type: PieceSymbol): number { + switch (type) { + case "p": + return 1; + case "b": + case "n": + return 3; + case "r": + return 5; + case "q": + return 9; + case "k": + // impossible (mostly) + // idk why i said this it's really not impossible lol + return 413; + } +} +function value_of_pieces_of_color(b: Chess, color: Color): number { + return pieces_of_color(b, color) + .map(p => value_piece(p.type)) + .reduce((a, b) => a + b); +} + +// hm +const HUMAN_COLOR: Color = WHITE; +const ROBOT_COLOR: Color = BLACK; + +// DONE: I THINK: UGH piece value +const cccp: Player = board => { + let cccp_score = (b: Chess) => { + if (b.isCheckmate()) { + console.log("Found checkmate! :D"); + return 0; + } + if (b.isCheck()) { + console.log("Found check! :T"); + return 1; + } + // maximize the difference in value + let prev_value = value_of_pieces_of_color(board, HUMAN_COLOR); + let new_value = value_of_pieces_of_color(b, HUMAN_COLOR); + if (new_value < prev_value) { + console.log("There's less human-colored pieces now! :)"); + return 10 * (6 - (prev_value - new_value)); + } + // sum the ranks of the robot pieces (brittle with piece colors changing which uhh just don't do that :)) + // they are zero based oopsie + return ( + 100 * + pieces_of_color(b, ROBOT_COLOR) + .map(b => 8 - rank_and_file(b.square).rank) + .reduce((a, b) => a + b) + ); + }; + return min_move_by(board, cccp_score); +}; + +// FIXME: function name is TOO short FIX +function total_chebyshev_distances_of_pieces_of_color_to_square( + board: Chess, + color: Color, + square: Square +): number { + return pieces_of_color(board, color) + .map(p => chebyshev_distance(p.square, square)) + .reduce((a, b) => a + b); +} + +const huddle: Player = board => { + return min_move_by(board, b => + total_chebyshev_distances_of_pieces_of_color_to_square( + b, + ROBOT_COLOR, + find({ color: ROBOT_COLOR, type: KING }, b) ?? "a1" + ) + ); +}; + +const swarm: Player = board => { + return min_move_by(board, b => + total_chebyshev_distances_of_pieces_of_color_to_square( + b, + ROBOT_COLOR, + find({ color: HUMAN_COLOR, type: KING }, b) ?? "a1" + ) + ); +}; + +function sum_of_possible_capture_value(b: Chess): number { + let prev_value = value_of_pieces_of_color(b, ROBOT_COLOR); + + let sum = 0; + for (const move of b.moves()) { + let new_board = with_move(b, move); + let new_value = value_of_pieces_of_color(new_board, ROBOT_COLOR); + // value only goes down..... pretty much + // but the negation is now done by the guys so + sum += prev_value - new_value; + } + + return sum; +} + +// surprisingly not too difficult +const generous: Player = board => { + // sum of the difference in ROBOT_COLOR piece value of all moves + // but like uhh negative + let generous_score = (b: Chess) => { + return -sum_of_possible_capture_value(b); + }; + + return min_move_by(board, generous_score); +}; + +const no_i_insist: Player = board => { + let no_i_insist_score = (b: Chess) => { + if (b.isCheckmate()) { + return 612; + } + if (b.isCheck()) { + return 413; + } + let prev_value = value_of_pieces_of_color(b, ROBOT_COLOR); + return -(sum_of_possible_capture_value(b) / b.moves().length); + }; + + return min_move_by(board, no_i_insist_score); +}; + +const pacifist: Player = board => { + let pacifist_score = b => { + if (b.isCheckmate()) { + return 612; + } + if (b.isCheck()) { + return 413; + } + + let prev_value = value_of_pieces_of_color(board, HUMAN_COLOR); + let new_value = value_of_pieces_of_color(b, HUMAN_COLOR); + if (new_value < prev_value) { + return prev_value - new_value; + } + + return 0; + }; + + return min_move_by(board, pacifist_score); +}; + +const players = [ + { + f: random_move, + name: "random_move", + description: "Moves randomly, believe it or not.", + }, + { + f: same_color, + name: "same_color", + description: + "Makes the move that maximizes the number of pieces on their own color", + }, + { + f: opposite_color, + name: "opposite_color", + description: "Behavior left as an exercise to the reader", + }, + { + f: pacifist, + name: "pacifist", + description: + "Avoids checkmate, then avoids checks, then avoids captures, if forced, captures the lowest value piece it can", + }, + { + f: first_move, + name: "first_move", + description: + "Makes the lexicographically first move based on [source_row, source_col, dest_row, dest_col, promotion]", + }, + { + f: alphabetical, + name: "alphabetical", + description: + "Makes the first move asciilphabetically (based on algebraic notation)", + }, + { + f: huddle, + name: "huddle", + description: + "Makes the move that minimizes the total Chebyshev distances from their pieces to their king", + }, + { + f: swarm, + name: "swarm", + description: + "Makes the move that minimizes the total Chebyshev distances from their pieces to YOUR king", + }, + { + f: generous, + name: "generous", + description: + "Maximizes the number of YOUR moves that take their pieces, weighting by value", + }, + { + f: no_i_insist, + name: "no_i_insist", + description: + "Maximizes the proportion of potential capture value of YOUR moves to the number of YOUR moves; very weird the way i've done it", + }, + { + f: reverse_starting, + name: "reverse_starting", + description: + "Makes the move that minimizes the number of moves it takes to move their pieces to the opposite end", + }, + { + f: cccp, + name: "cccp", + description: + "First checkmates, then checks, then captures (the best piece it can), then pushes", + }, + { + f: suicide_king, + name: "suicide_king", + description: + "Makes the move that minimizes the Chebyshev distance between the two kings", + }, + { + f: sym_mirror_y, + name: "sym_mirror_y", + description: + "Tries to make the board as vertically symmetric as possible (basically copies your moves)", + }, + { + f: sym_mirror_x, + name: "sym_mirror_x", + description: + "Tries to make the board as horizontally symmetric as possible (basically doesn't copy your moves or do anything useful)", + }, + { + f: sym_180, + name: "sym_180", + description: + "Tries to make the board as symmetric as possible when flipped around", + }, + { + f: min_oppt_move, + name: "min_oppt_move", + description: "Does the move that leaves the least moves for YOU", + }, + { + f: equalizer, + name: "equalizer", + description: + "Moves the least moved piece (actually piece type, e.g. moving a pawn counts for all pawns; it sucks, i know), breaking ties by moving to the least visited square", + }, + // alphabetical is fine i guess, since the checklist order has little to do with the og paper + // ehhh nvm +]; //.sort((a, b) => a.name.localeCompare(b.name)); + +// https://stackoverflow.com/questions/12739171/javascript-epoch-time-in-days + +function days_since_epoch() { + var now = new Date().getMilliseconds(); + return Math.floor(now / 8.64e7); +} + +function find_specified_in_hash(): null | { + f: Player; + name: string; + description: string; +} { + return players.find(p => `#${p.name}` == window.location.hash); +} + +// bad +// const todays_player = players[days_since_epoch() % players.length]; +const todays_player = + find_specified_in_hash() ?? + players[Math.floor(Math.random() * players.length)]; + +console.log(`SPOILER: today's player is ${todays_player.name}`); +// const todays_player = min_oppt_move; + +const board: any = document.getElementById("board"); + +const game = new Chess(); + +function computer_move() { + num_moves++; + return todays_player.f(game); +} + +// might want to change this when it's more wordly +function show_game_over() { + let game_over = document.getElementById("game-over"); + game_over.style.display = "block"; + game_over.innerText = `GAME OVER; player was ${todays_player.name}`; + + console.log("GAME OVER"); +} + +function show_win() { + let game_over = document.getElementById("game-over"); + game_over.style.display = "block"; + game_over.innerText = "YOU WIN YOU WIN YOU WIN YOU WIN HOLY CRAP"; + + let stats = document.getElementById("stats"); + stats.style.display = "block"; + let stats_text = `#EloWorldle413\nGuesses: ${num_guesses}\nMoves: ${num_moves}`; + stats.innerText = stats_text; + + let copy_stats = document.getElementById("copy-stats"); + copy_stats.style.display = "block"; + copy_stats.addEventListener("click", _ => + navigator.clipboard.writeText(stats_text) + ); + + console.log("PLAYER IS WIN"); +} + +var num_guesses = 0; +var num_moves = 0; + +function append_players_to(n: Node) { + for (const player of players) { + let child = document.createElement("div"); + child.classList.add("player"); + + let child_name = document.createElement("h1"); + child_name.classList.add("player-name"); + child_name.innerText = player.name; + + let child_desc = document.createElement("p"); + child_desc.classList.add("player-desc"); + child_desc.innerText = player.description; + + let guess_button = document.createElement("button"); + guess_button.innerText = "^ guess ^"; + + guess_button.onclick = _ => { + num_guesses++; + if (todays_player.name == player.name) { + show_win(); + child.classList.add("correct"); + } else { + child.classList.add("wrong"); + } + guess_button.onclick = () => {}; + }; + + child.appendChild(child_name); + child.appendChild(child_desc); + child.appendChild(guess_button); + child_name.addEventListener("click", _ => + child.classList.toggle("strikethrough") + ); + n.appendChild(child); + } +} + +window.addEventListener("DOMContentLoaded", () => { + board.addEventListener("movestart", (e: any) => { + console.log( + `Move started: ${e.detail.from}, ${e.detail.piece.color} ${e.detail.piece.pieceType}` + ); + e.detail.setTargets( + // This produces a list like ["e3", "e5"] + game.moves({ square: e.detail.from, verbose: true }).map(m => m.to) + ); + + if (game.isGameOver()) { + show_game_over(); + } + }); + + board.addEventListener("moveend", (e: any) => { + console.log( + `Move ending: ${e.detail.from} -> ${e.detail.to}, ${e.detail.piece.color} ${e.detail.piece.pieceType}` + ); + const move = game.move({ + from: e.detail.from, + to: e.detail.to, + promotion: "q", + }); + if (move === null) { + e.preventDefault(); + } + + if (game.isGameOver()) { + show_game_over(); + } + }); + + board.addEventListener("movefinished", (e: any) => { + board.fen = game.fen(); + board.turn = game.turn() === "w" ? "white" : "black"; + board.interactive = game.turn() === "w"; + + if (!board.interactive) { + let move = computer_move(); + if (!move) { + console.log( + "Didn't get a move from the computer (this is fine if the game is over)" + ); + return; + } + console.log(`Computer move: ${move}`); + game.move(move); + board.fen = game.fen(); + board.turn = "white"; + board.interactive = true; + } + }); + + document + .getElementById("finish") + .addEventListener("click", _ => show_game_over()); + + append_players_to(document.getElementById("players")); +}); diff --git a/paper-ideas.txt b/paper-ideas.txt new file mode 100644 index 0000000..8dbc685 --- /dev/null +++ b/paper-ideas.txt @@ -0,0 +1,16 @@ +* a survery of 10 american high school students (R=0, i don't make mistakes) +* an in-depth analysis of the viewcount of https://www.youtube.com/watch?v=DpXy041BIlA shows that it is less than half the number of students in 'merica + * "ask eliza" which is more: 734k or the num. of highschool students in 'mmmmerica + * sadly, research has shown that we do, in fact, live in a society (see: outside, probably) + * this is worrying as knowledge of bad chess algorithms is projected to be the new literacy by 2013 (citation: Orin Kerr is the Fred C. Stevenson Research Professor at the George Washington University Law School. + 1 See generally Orin S. Kerr, A Theory of Law, 16 G REEN B AG 2 D 111 (2012).) +* teenager-friendly language as an excuse for implementation limitations (toootally is like, really great (anti-pun y'see?)) +* honor system (again, as an excuse for lazy impl) (joke that high schoolers are the most honorable age) +* the reconstruction of many of the algorithms is severely flawed, unfortunately looking at the original code just [isn't possible](svn link) (footnote to svn link). maybe one day all_with_link_and_footnote_to_svn_maybe_specific_files(the code will be released) +* 'merica 'mmerica 'mmmerica 'mmmmerica +* "hashes tag" to maximize rad power and engagementness + +* !!! make sure to give due credit to tom7, so, so much is taken + * good artists copy, great artists steal, other people also steal :T +* make sure licensing is good (gpl should be fine? look at source license) + * very scary ugh diff --git a/paper/paper.aux b/paper/paper.aux new file mode 100644 index 0000000..c806e61 --- /dev/null +++ b/paper/paper.aux @@ -0,0 +1,19 @@ +\relax +\providecommand\hyper@newdestlabel[2]{} +\providecommand\HyperFirstAtBeginDocument{\AtBeginDocument} +\HyperFirstAtBeginDocument{\ifx\hyper@anchor\@undefined +\global\let\oldcontentsline\contentsline +\gdef\contentsline#1#2#3#4{\oldcontentsline{#1}{#2}{#3}} +\global\let\oldnewlabel\newlabel +\gdef\newlabel#1#2{\newlabelxx{#1}#2} +\gdef\newlabelxx#1#2#3#4#5#6{\oldnewlabel{#1}{{#2}{#3}}} +\AtEndDocument{\ifx\hyper@anchor\@undefined +\let\contentsline\oldcontentsline +\let\newlabel\oldnewlabel +\fi} +\fi} +\global\let\hyper@last\relax +\gdef\HyperFirstAtBeginDocument#1{#1} +\providecommand\HyField@AuxAddToFields[1]{} +\providecommand\HyField@AuxAddToCoFields[2]{} +\gdef \@abspage@last{3} diff --git a/paper/paper.log b/paper/paper.log new file mode 100644 index 0000000..57b9833 --- /dev/null +++ b/paper/paper.log @@ -0,0 +1,308 @@ +This is pdfTeX, Version 3.141592653-2.6-1.40.24 (TeX Live 2022/Arch Linux) (preloaded format=pdflatex 2023.3.18) 26 MAR 2023 23:32 +entering extended mode + restricted \write18 enabled. + %&-line parsing enabled. +**paper.tex +(./paper.tex +LaTeX2e <2021-11-15> patch level 1 +L3 programming layer <2022-04-10> +(/usr/share/texmf-dist/tex/latex/base/article.cls +Document Class: article 2021/10/04 v1.4n Standard LaTeX document class +(/usr/share/texmf-dist/tex/latex/base/size10.clo +File: size10.clo 2021/10/04 v1.4n Standard LaTeX file (size option) +) +\c@part=\count185 +\c@section=\count186 +\c@subsection=\count187 +\c@subsubsection=\count188 +\c@paragraph=\count189 +\c@subparagraph=\count190 +\c@figure=\count191 +\c@table=\count192 +\abovecaptionskip=\skip47 +\belowcaptionskip=\skip48 +\bibindent=\dimen138 +) +(/usr/share/texmf-dist/tex/latex/base/inputenc.sty +Package: inputenc 2021/02/14 v1.3d Input encoding file +\inpenc@prehook=\toks16 +\inpenc@posthook=\toks17 +) +(/usr/share/texmf-dist/tex/latex/hyperref/hyperref.sty +Package: hyperref 2022-02-21 v7.00n Hypertext links for LaTeX + +(/usr/share/texmf-dist/tex/generic/ltxcmds/ltxcmds.sty +Package: ltxcmds 2020-05-10 v1.25 LaTeX kernel commands for general use (HO) +) +(/usr/share/texmf-dist/tex/generic/iftex/iftex.sty +Package: iftex 2022/02/03 v1.0f TeX engine tests +) +(/usr/share/texmf-dist/tex/generic/pdftexcmds/pdftexcmds.sty +Package: pdftexcmds 2020-06-27 v0.33 Utility functions of pdfTeX for LuaTeX (HO +) + +(/usr/share/texmf-dist/tex/generic/infwarerr/infwarerr.sty +Package: infwarerr 2019/12/03 v1.5 Providing info/warning/error messages (HO) +) +Package pdftexcmds Info: \pdf@primitive is available. +Package pdftexcmds Info: \pdf@ifprimitive is available. +Package pdftexcmds Info: \pdfdraftmode found. +) +(/usr/share/texmf-dist/tex/latex/graphics/keyval.sty +Package: keyval 2014/10/28 v1.15 key=value parser (DPC) +\KV@toks@=\toks18 +) +(/usr/share/texmf-dist/tex/generic/kvsetkeys/kvsetkeys.sty +Package: kvsetkeys 2019/12/15 v1.18 Key value parser (HO) +) +(/usr/share/texmf-dist/tex/generic/kvdefinekeys/kvdefinekeys.sty +Package: kvdefinekeys 2019-12-19 v1.6 Define keys (HO) +) +(/usr/share/texmf-dist/tex/generic/pdfescape/pdfescape.sty +Package: pdfescape 2019/12/09 v1.15 Implements pdfTeX's escape features (HO) +) +(/usr/share/texmf-dist/tex/latex/hycolor/hycolor.sty +Package: hycolor 2020-01-27 v1.10 Color options for hyperref/bookmark (HO) +) +(/usr/share/texmf-dist/tex/latex/letltxmacro/letltxmacro.sty +Package: letltxmacro 2019/12/03 v1.6 Let assignment for LaTeX macros (HO) +) +(/usr/share/texmf-dist/tex/latex/auxhook/auxhook.sty +Package: auxhook 2019-12-17 v1.6 Hooks for auxiliary files (HO) +) +(/usr/share/texmf-dist/tex/latex/kvoptions/kvoptions.sty +Package: kvoptions 2020-10-07 v3.14 Key value format for package options (HO) +) +\@linkdim=\dimen139 +\Hy@linkcounter=\count193 +\Hy@pagecounter=\count194 + +(/usr/share/texmf-dist/tex/latex/hyperref/pd1enc.def +File: pd1enc.def 2022-02-21 v7.00n Hyperref: PDFDocEncoding definition (HO) +Now handling font encoding PD1 ... +... no UTF-8 mapping file for font encoding PD1 +) +(/usr/share/texmf-dist/tex/generic/intcalc/intcalc.sty +Package: intcalc 2019/12/15 v1.3 Expandable calculations with integers (HO) +) +(/usr/share/texmf-dist/tex/generic/etexcmds/etexcmds.sty +Package: etexcmds 2019/12/15 v1.7 Avoid name clashes with e-TeX commands (HO) +) +\Hy@SavedSpaceFactor=\count195 + +(/usr/share/texmf-dist/tex/latex/hyperref/puenc.def +File: puenc.def 2022-02-21 v7.00n Hyperref: PDF Unicode definition (HO) +Now handling font encoding PU ... +... no UTF-8 mapping file for font encoding PU +) +Package hyperref Info: Hyper figures OFF on input line 4137. +Package hyperref Info: Link nesting OFF on input line 4142. +Package hyperref Info: Hyper index ON on input line 4145. +Package hyperref Info: Plain pages OFF on input line 4152. +Package hyperref Info: Backreferencing OFF on input line 4157. +Package hyperref Info: Implicit mode ON; LaTeX internals redefined. +Package hyperref Info: Bookmarks ON on input line 4390. +\c@Hy@tempcnt=\count196 + +(/usr/share/texmf-dist/tex/latex/url/url.sty +\Urlmuskip=\muskip16 +Package: url 2013/09/16 ver 3.4 Verb mode for urls, etc. +) +LaTeX Info: Redefining \url on input line 4749. +\XeTeXLinkMargin=\dimen140 + +(/usr/share/texmf-dist/tex/generic/bitset/bitset.sty +Package: bitset 2019/12/09 v1.3 Handle bit-vector datatype (HO) + +(/usr/share/texmf-dist/tex/generic/bigintcalc/bigintcalc.sty +Package: bigintcalc 2019/12/15 v1.5 Expandable calculations on big integers (HO +) +)) +\Fld@menulength=\count197 +\Field@Width=\dimen141 +\Fld@charsize=\dimen142 +Package hyperref Info: Hyper figures OFF on input line 6027. +Package hyperref Info: Link nesting OFF on input line 6032. +Package hyperref Info: Hyper index ON on input line 6035. +Package hyperref Info: backreferencing OFF on input line 6042. +Package hyperref Info: Link coloring OFF on input line 6047. +Package hyperref Info: Link coloring with OCG OFF on input line 6052. +Package hyperref Info: PDF/A mode OFF on input line 6057. +LaTeX Info: Redefining \ref on input line 6097. +LaTeX Info: Redefining \pageref on input line 6101. + +(/usr/share/texmf-dist/tex/latex/base/atbegshi-ltx.sty +Package: atbegshi-ltx 2021/01/10 v1.0c Emulation of the original atbegshi +package with kernel methods +) +\Hy@abspage=\count198 +\c@Item=\count199 +\c@Hfootnote=\count266 +) +Package hyperref Info: Driver (autodetected): hpdftex. + +(/usr/share/texmf-dist/tex/latex/hyperref/hpdftex.def +File: hpdftex.def 2022-02-21 v7.00n Hyperref driver for pdfTeX + +(/usr/share/texmf-dist/tex/latex/base/atveryend-ltx.sty +Package: atveryend-ltx 2020/08/19 v1.0a Emulation of the original atveryend pac +kage +with kernel methods +) +\Fld@listcount=\count267 +\c@bookmark@seq@number=\count268 + +(/usr/share/texmf-dist/tex/latex/rerunfilecheck/rerunfilecheck.sty +Package: rerunfilecheck 2019/12/05 v1.9 Rerun checks for auxiliary files (HO) + +(/usr/share/texmf-dist/tex/generic/uniquecounter/uniquecounter.sty +Package: uniquecounter 2019/12/15 v1.4 Provide unlimited unique counter (HO) +) +Package uniquecounter Info: New unique counter `rerunfilecheck' on input line 2 +86. +) +\Hy@SectionHShift=\skip49 +) +Package hyperref Info: Option `colorlinks' set `true' on input line 8. + +(/usr/share/texmf-dist/tex/latex/l3backend/l3backend-pdftex.def +File: l3backend-pdftex.def 2022-04-14 L3 backend support: PDF output (pdfTeX) +\l__color_backend_stack_int=\count269 +\l__pdf_internal_box=\box50 +) (./paper.aux) +\openout1 = `paper.aux'. + +LaTeX Font Info: Checking defaults for OML/cmm/m/it on input line 16. +LaTeX Font Info: ... okay on input line 16. +LaTeX Font Info: Checking defaults for OMS/cmsy/m/n on input line 16. +LaTeX Font Info: ... okay on input line 16. +LaTeX Font Info: Checking defaults for OT1/cmr/m/n on input line 16. +LaTeX Font Info: ... okay on input line 16. +LaTeX Font Info: Checking defaults for T1/cmr/m/n on input line 16. +LaTeX Font Info: ... okay on input line 16. +LaTeX Font Info: Checking defaults for TS1/cmr/m/n on input line 16. +LaTeX Font Info: ... okay on input line 16. +LaTeX Font Info: Checking defaults for OMX/cmex/m/n on input line 16. +LaTeX Font Info: ... okay on input line 16. +LaTeX Font Info: Checking defaults for U/cmr/m/n on input line 16. +LaTeX Font Info: ... okay on input line 16. +LaTeX Font Info: Checking defaults for PD1/pdf/m/n on input line 16. +LaTeX Font Info: ... okay on input line 16. +LaTeX Font Info: Checking defaults for PU/pdf/m/n on input line 16. +LaTeX Font Info: ... okay on input line 16. + +(/usr/share/texmf-dist/tex/latex/graphics/color.sty +Package: color 2021/12/07 v1.3c Standard LaTeX Color (DPC) + +(/usr/share/texmf-dist/tex/latex/graphics-cfg/color.cfg +File: color.cfg 2016/01/02 v1.6 sample color configuration +) +Package color Info: Driver file: pdftex.def on input line 149. + +(/usr/share/texmf-dist/tex/latex/graphics-def/pdftex.def +File: pdftex.def 2020/10/05 v1.2a Graphics/color driver for pdftex + +(/usr/share/texmf-dist/tex/context/base/mkii/supp-pdf.mkii +[Loading MPS to PDF converter (version 2006.09.02).] +\scratchcounter=\count270 +\scratchdimen=\dimen143 +\scratchbox=\box51 +\nofMPsegments=\count271 +\nofMParguments=\count272 +\everyMPshowfont=\toks19 +\MPscratchCnt=\count273 +\MPscratchDim=\dimen144 +\MPnumerator=\count274 +\makeMPintoPDFobject=\count275 +\everyMPtoPDFconversion=\toks20 +))) +Package hyperref Info: Link coloring ON on input line 16. + (/usr/share/texmf-dist/tex/latex/hyperref/nameref.sty +Package: nameref 2021-04-02 v2.47 Cross-referencing by name of section + +(/usr/share/texmf-dist/tex/latex/refcount/refcount.sty +Package: refcount 2019/12/15 v3.6 Data extraction from label references (HO) +) +(/usr/share/texmf-dist/tex/generic/gettitlestring/gettitlestring.sty +Package: gettitlestring 2019/12/15 v1.6 Cleanup title references (HO) +) +\c@section@level=\count276 +) +LaTeX Info: Redefining \ref on input line 16. +LaTeX Info: Redefining \pageref on input line 16. +LaTeX Info: Redefining \nameref on input line 16. + +(./paper.out) (./paper.out) +\@outlinefile=\write3 +\openout3 = `paper.out'. + +LaTeX Font Info: External font `cmex10' loaded for size +(Font) <12> on input line 19. +LaTeX Font Info: External font `cmex10' loaded for size +(Font) <8> on input line 19. +LaTeX Font Info: External font `cmex10' loaded for size +(Font) <6> on input line 19. +LaTeX Font Info: External font `cmex10' loaded for size +(Font) <9> on input line 25. +LaTeX Font Info: External font `cmex10' loaded for size +(Font) <5> on input line 25. +LaTeX Font Info: External font `cmex10' loaded for size +(Font) <7> on input line 34. + +Overfull \hbox (1.49698pt too wide) in paragraph at lines 49--49 +[]\OT1/cmtt/m/n/10 * Given that Youtube Video has less views than half the popu +lation[] + [] + + +Overfull \hbox (6.74693pt too wide) in paragraph at lines 49--49 +[]\OT1/cmtt/m/n/10 of the 'Ted 'Tes, is it possible that every 'Mmmmerican high + school[] + [] + +[1 + +{/var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map}] +pdfTeX warning (ext4): destination with the same identifier (name{page.}) has b +een already used, duplicate ignored + + \relax +l.78 \end{document} + [2] +pdfTeX warning (ext4): destination with the same identifier (name{page.}) has b +een already used, duplicate ignored + + \relax +l.78 \end{document} + [3] (./paper.aux) +Package rerunfilecheck Info: File `paper.out' has not changed. +(rerunfilecheck) Checksum: D41D8CD98F00B204E9800998ECF8427E;0. + ) +Here is how much of TeX's memory you used: + 7873 strings out of 478238 + 123244 string characters out of 5850456 + 427050 words of memory out of 5000000 + 26024 multiletter control sequences out of 15000+600000 + 475142 words of font info for 48 fonts, out of 8000000 for 9000 + 1141 hyphenation exceptions out of 8191 + 60i,8n,63p,427b,462s stack positions out of 5000i,500n,10000p,200000b,80000s +{/usr/share/texmf-dist/fonts/enc/dvips/cm-super/cm-super-ts1.enc} +Output written on paper.pdf (3 pages, 175758 bytes). +PDF statistics: + 159 PDF objects out of 1000 (max. 8388607) + 124 compressed objects within 2 object streams + 24 named destinations out of 1000 (max. 500000) + 1 words of extra memory for PDF output out of 10000 (max. 10000000) + diff --git a/paper/paper.out b/paper/paper.out new file mode 100644 index 0000000..e69de29 diff --git a/paper/paper.pdf b/paper/paper.pdf new file mode 100644 index 0000000..26fdd55 Binary files /dev/null and b/paper/paper.pdf differ diff --git a/paper/paper.tex b/paper/paper.tex new file mode 100644 index 0000000..9aadcdf --- /dev/null +++ b/paper/paper.tex @@ -0,0 +1,80 @@ +\documentclass[a4paper,10pt]{article} +\usepackage[utf8]{inputenc} +\usepackage[hidelinks]{hyperref} +\hypersetup{ + colorlinks, + urlcolor = blue, + linkcolor = black, +} + +%opening +\title{Elo Worldle, a framework for teaching the children about weak chess engines} +\author{Clark Levi Jones} +\date{} +\pagenumbering{gobble} + +\begin{document} + +\maketitle + +\begin{abstract} +I see what I infer to be a mountain. In the center of the mountain, I infer that there is something. In the spirit of, I go to check my inferences. The mountain grows farther. I turn again. The mountain grows closer. I infer that a smile grows across my face. There is a tree. I infer that there is a tree. I am wrong. +\end{abstract} + +\begin{abstract} +Numerous studies\footnote{TODO: academic integrity, citations, not-lies, etc are valuable\footnotemark}\footnotetext{\url{https://www.marxists.org/archive/marx/works/1867-c1/appendix.htm}} +have shown that it is impossible to learn without video games. +Many of the children know little about bad chess engines. +There is no videogame. +The author seeks to rectify this. +\end{abstract} + +\section*{Motivation} + +Before the advance of the action-packed, educational digigame Wordle\footnote{\url{https://www.nytimes.com/games/wordle/index.html}}, the vast majority of 'Merican highschool students were unaware that words even were. +Similarly, Worldle\footnote{\url{https://worldle.teuteuf.fr/}} ushered in a new age of international politics, as now the world's elite ('Mmerican highschool students) were aware of nations. +Most famously, LFMan helped the kids to learn.\footnote{\url{http://spacebar.org/lfman/}} +Time and time again, video game makes the kids know. + +Most people believe vocabulary, geography, and dependent lambda calculus are the only things that the children need to know, but this is not the case; knowledge of bad chess algorithms is projected to be the new literacy by 2011.\footnote{See generally Orin S. Kerr, A Theory of Law, 16 G REEN B AG 2 D 111 (2012).} + +To assess the current literacy rates in the 'Nited 'Tates, we\footnote{I} performed a survey of ten random 'Mmmerican highschool students\footnote{$R=0$, I don't make mistakes.} and found them all to be illiterate. +In addition, we\footnote{I} did an in-depth analysis of the view count of \url{https://www.youtube.com/watch?v=DpXy041BIlA} and found it to be less than half the population of the 'Ited 'Ates! +We asked a sentient chatbot\footnote{\url{https://pyrope.net/2023.pdf}} for its analysis on the matter: +\begin{verbatim} +* Given that Youtube Video has less views than half the population +of the 'Ted 'Tes, is it possible that every 'Mmmmerican high school +student has watched it? +> It is nice to be chatting with you. +\end{verbatim} +It is clear that a Video Game is needed. +However, terrifyingly, in my extensive research,\footnote{} I was unable to find a single game that taught the children how to recognize what bad chess engine they are playing against? Whaaaat!? + +\section*{Implementation} +After a few hours of frustration, implementation went relatively smoothly. +Each engine was implemented as a Typescript\footnote{\url{https://isocpp.org}} function, using the laziest possible interpretations of the descriptions in \url{http://tom7.org/chess/weak.pdf}.\footnote{For example, `equalizer' is complete garbage because it is based on piece \emph{type} instead of the actual piece, which makes it completely boring and extremely difficult to identify.} +An ideal implementation would simply port the original, but \href{https://sourceforge.net/p/tom7misc/svn/HEAD/tree/trunk/chess/}{there is no way to do that}.\footnote{\url{https://sourceforge.net/p/tom7misc/svn/HEAD/tree/trunk/chess}} +\href{https://sourceforge.net/p/tom7misc/svn/HEAD/tree/trunk/chess/player.cc}{It's impossible}.\footnote{\url{https://sourceforge.net/p/tom7misc/svn/HEAD/tree/trunk/chess/player.cc}} +The Javascript ecosystem, notorious for it's lack of libraries, did have a chess library\footnote{\url{https://www.npmjs.com/package/chess.js}} and a chessboard library\footnote{\url{https://www.npmjs.com/package/gchessboard}} both of which the author (ab)used greatly. + +\section*{Color Pickings} +As is standard practice\footnote{\url{https://en.wikipedia.org/wiki/Standards_\%26_Practices_(album)}}, what colors were picked and from where are listed below: +\begin{itemize} + \item \#86A666 ``Dark Square Color'': \url{http://tom7.org/chess/} + \item \#FFFFDD ``Light Square Color'': \url{http://tom7.org/chess/} + \item \#3A3A3C ``FAIL Color: Rad Variation'': \url{https://www.nytimes.com/games/wordle/index.html} + \item \#538D4E ``WIN Color: Rad Variation'': \url{https://www.nytimes.com/games/wordle/index.html} +\end{itemize} + +\section*{Conclusion} +Having made a game that will the children the learn, my life is complete. +I can now choose to roam the earth as an empty husk, searching eternally and pointlessly for some new purpose, or I can become a robot ghost. + +Oh, you want to actually play the game? +Are the numerous, gorgeous screenshots I have provided simply not enough? +Fine, but you're going to have to work for it. +In this sentence, there is a hidden link to the game \url{https://elo-worldle.pyrope.net}. +And, in this sentence, there is a hidden link to the source code (which is technically also in the last link but it would be annoying to find everything) \url{https://git.pyrope.net/mbk/elo-worldle/}. +\end{document} + + diff --git a/piece-bb.png b/piece-bb.png new file mode 100644 index 0000000..2f61d43 Binary files /dev/null and b/piece-bb.png differ diff --git a/piece-bk.png b/piece-bk.png new file mode 100644 index 0000000..c2377e8 Binary files /dev/null and b/piece-bk.png differ diff --git a/piece-bn.png b/piece-bn.png new file mode 100644 index 0000000..017317c Binary files /dev/null and b/piece-bn.png differ diff --git a/piece-bp.png b/piece-bp.png new file mode 100644 index 0000000..a562e5a Binary files /dev/null and b/piece-bp.png differ diff --git a/piece-bq.png b/piece-bq.png new file mode 100644 index 0000000..b132444 Binary files /dev/null and b/piece-bq.png differ diff --git a/piece-br.png b/piece-br.png new file mode 100644 index 0000000..273dd65 Binary files /dev/null and b/piece-br.png differ diff --git a/piece-wb.png b/piece-wb.png new file mode 100644 index 0000000..9cf8b3e Binary files /dev/null and b/piece-wb.png differ diff --git a/piece-wk.png b/piece-wk.png new file mode 100644 index 0000000..dd5c72a Binary files /dev/null and b/piece-wk.png differ diff --git a/piece-wn.png b/piece-wn.png new file mode 100644 index 0000000..3fc751e Binary files /dev/null and b/piece-wn.png differ diff --git a/piece-wp.png b/piece-wp.png new file mode 100644 index 0000000..24c42b0 Binary files /dev/null and b/piece-wp.png differ diff --git a/piece-wq.png b/piece-wq.png new file mode 100644 index 0000000..2c56f30 Binary files /dev/null and b/piece-wq.png differ diff --git a/piece-wr.png b/piece-wr.png new file mode 100644 index 0000000..6fb283c Binary files /dev/null and b/piece-wr.png differ diff --git a/players.md b/players.md new file mode 100644 index 0000000..4ab0e30 --- /dev/null +++ b/players.md @@ -0,0 +1,36 @@ +[x] random_move +[x] same_color +[x] opposite_color +[x] pacifist +[x] first_move +[x] alphabetical +[x] huddle +[x] swarm +[x] generous +[x] no_i_insist +[x] reverse_starting +[x] cccp +[x] suicide_king +[x] sym_mirror_y +[x] sym_mirror_x +[x] sym_180 +[x] min_oppt_moves* +[x] equalizer + +the last 4 unchecked (reverse_starting, sym_mirror_y, sym_mirror_x, and sym_180 for posterity) can likely use a similar function (the easiest possible interpretation of the og is that they minimize the total distance of pieces to some target, will probably be easiest to just manually although hmmmm reverse_starting + find + start_board could be clever) +reading is helpful apparently: (in reverse_starting) "Since here we have +a specific configuration in mind, we can produce a distance metric by computing the total distance from each piece to its desired destination." + +oh boy: *** Each piece uses a different distance metric; Chebyshev distance for the King, Manhattan distance for the Rook, and a pretty weird function for the Knight [3]. *** + +the player descriptions are too much about the specifics ("reverse_starting: Makes the move that minimizes the number of moves it takes to move their pieces to the opposite end" is particularly egregious) which is more honest but eh + +# fate-based players are going to be unreasonable +## JUST KIDDING: all-fate-data.cc thank you tom7 +### but maybe they won't be funny +#### i meant funny +##### i don't know why i'm doing org-mode nesting +###### i meant FUN +####### why do i keep doing funny +######## anyway what i meant to mention is laziness duh +[ ] diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..6dcc0db --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "target": "ES6", + "module": "ES6", + "moduleResolution": "node", + "esModuleInterop": true + } +}