Code Monkey home page Code Monkey logo

pawn's Introduction

pawn

A UCI alpha-beta chess engine, largely inspired by Stockfish.

As with most UCI chess engines, pawn should be used with a compatible graphical user interface (such as CuteChess). It plays both standard chess and Chess960.

The engine uses an efficiently updatable neural network (NNUE) for evaluation. Currently, the net is shallow with a single 256-neuron layer and 4 output buckets (selected according to the number of pieces on the board). A separate set of PSQ tables is directly propagated to the output, which is also initialised using the material values of each piece. All training data has been generated in self-play at low depth using the tools in the branch data_gen. The training scripts can also be found in that branch, which use a PyTorch backend. The default network is embedded in the binary file with incbin.

Getting pawn

The latest official version can be downloaded in the Releases tab. Binaries for both Windows and Linux are available. For each platform, two 64-bit versions are provided: a generic version for most x86 processors (slower) and one with the instruction set from haswell (faster with BMI2, AVX2 and POPCNT, but may not be supported for older CPUs).

For the most up-to-date (and likely stronger) version, it is recommended to compile directly from sources for the target architecture, as described below.

Compiling from sources

To compile under Linux or Windows with MSYS2, simply call

make

in the root directory to generate an executable optimised for the building machine. The resulting binary and object files can be found in the build directory. Verify the signature of the binary by running the bench command and checking if the number of nodes searched matches the Bench field of the last commit message.

To compile generic binaries or to a specific architecture, use

make ARCH=target

where target is the target passed to -march=.

Progress

The progression of pawn in self-play since the first public version is illustrated in the table below. The ratings are computed with ordo (anchored at zero for the first commit and with errors relative to pool average) using the noob_3moves book under LTC conditions (single-thread with TC 60+0.6 and 64MB hash).

Date Commit Elo Error(+/-)
24/01/12 3.0 349.8 19.8
23/11/30 e276c44 296.8 19.7
23/10/31 795d3c0 288.2 19.5
23/10/06 2.0 235.2 15.2
23/08/31 5a5ea8a 169.9 15.8
23/06/30 b68c1df 163.4 15.7
23/04/24 c777eef 121.7 14.6
23/03/12 1.0 0.0 14.0
23/02/11 527fe63 -17.5 15.0
23/01/31 d7b26dc -36.5 15.0
22/12/20 ecf549f -226.0 14.2
22/11/18 c22a7e5 -240.1 13.8
22/10/06 567797f -360.4 14.3
22/09/23 132140b -370.2 16.9
22/08/30 25607d9 -404.3 17.1
22/07/30 638dc4c -463.1 17.5
22/06/27 069e93a -562.0 18.4
22/05/27 78c2f15 -755.4 19.6
22/04/27 5fd6e1d -1004.7 22.6
22/03/18 fa8e828 -1040.8 22.6
22/02/28 0a131bd -1062.2 22.7
21/10/29 61edb2a -1073.7 22.6
21/09/28 cadf61b -1193.2 24.8
21/08/31 056c448 -1387.1 30.4

UCI Options

The following UCI options are supported:

  • Hash

    Size of the Hash Table, in MB (defaults to 16).

  • Threads

    The number of threads to use during search (defaults to 1).

  • MultiPV

    The number of principal variations (PV) to search (defaults to 1). This should be kept at 1 for best performance.

  • Ponder

    Allow the engine to think during the opponent's move (defaults to false). This requires the GUI to send the appropriate go ponder.

  • Move Overhead

    Extra time to reserve for each move (defaults to 0). Increase if the engine flags due to communication delays.

  • Clear Hash

    Button to clear the hash table.

  • NNUE_File

    Path to the NNUE net file to use (empty by default). If empty falls back to the embedded network file.

  • SyzygyPath

    Path to the directory containing the Syzygy endgame tablebases.

  • SyzygyProbeDepth

    Minimum depth to probe the endgame tablebases during the search.

  • SyzygyProbeLimit

    Maximum number of pieces to allow probing the table.

Furthermore, the following non-standard commands are available:

  • board - show a representation of the current board;
  • eval - print some of the evaluation terms;
  • test - test the move generation, transposition tables, move orderers and legality checks of the engine;
  • bench - search a set of positions to obtain a signature. Optionally, the following syntax is available: bench depth threads hash. By default, calling bench is equivalent to bench 13 1 16.
  • go perft depth - do the perft node count for the current position at depth depth.

Main Features

Syzygy endgame tablebases

The Syzygy endgame tablebases support uses Fathom for probing the WDL and DTZ tables. Similarly to the original implementation in Stockfish, pawn has two modes of operation:

  • If the root position is not on the tablebase, pawn will probe the WDL tables during the search (only after a move that resets the 50-move rule counter);
  • If the root position is on the tablebase, then only the moves that preserve the root's WDL score are searched. The engine will continue to search on these moves, but the reported score is derived from the tablebase (unless a mate score is found). To avoid wasting moves in long conversions or possibly drawing by repetition, DTZ tables are used to make progress whenever two-fold repetitions may arise. When using go searchmoves, the move selection is ignored, but TB scores are still returned.

Board representation

  • Bitboard representation (with GCC builtin bitscan and popcount)
  • Magic numbers for slider move generation
  • Staged move generation for captures and quiet moves

Evaluation

  • Efficiently updatable neural network (NNUE):
    • Combined PSQ and layer contributions
    • HalfKP_hm feature set
    • Four output buckets, selected according to the number of pieces on the board

Search

  • Principal Variation Search in a negamax framework
  • Quiescence search with SEE
  • MultiPV search
  • Transposition Tables
  • Aspiration Windows
  • Late move reductions
  • Null-move pruning
  • Singular and check extensions
  • Futility pruning
  • Mate distance pruning
  • Basic Lazy SMP threading

Move Ordering

  • MVV move ordering for captures
  • Killer moves
  • Quiet move ordering
    • History heuristic with butterfly and 3-ply continuation piece-to boards

pawn's People

Contributors

ruicoelhopedro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

styxdoto

pawn's Issues

Pawn is 2700 !?

Your new Pawn version plays very well, congrats! Not long ago i wrote several issues while testing Pawn .. it seems evolved ! Remember, in those days i made a script to estimate its strength, which was about 2350 .. lately i tested again, with your newest version (compiled by git clone), and it seems over 2700 !? I attached a ZIPped pgn file Pawn_games_10min3sec.zip with 12 games, 10 minutes + 3 sec, against some engines with rating about 2700, according to the list http://ccrl.chessdom.com/ccrl/4040/rating_list_all.html -- there you can find links to those engines and their source code.

Pawn plays White in all games. It wins almost all battles in a style i admire : gladly sacrificing material for initiative and attack !

  1-0   K2 v0.992 dev           2716
  1-0   Payfleens v1.86         2600
1/2-1/2 Frozenight v6.0.0-dev   3086
  1-0   Leorik v2.2             2690
1/2-1/2 Knightx v3.4            2699
  1-0   Knightx v3.5            2672
  1-0   Booot v4.15.1           2696
  1-0   Lozza v2.4              2682
  1-0   Cheese v3.01            2850
  1-0   Weiawaga v5.0.0 NNUE    2844
  1-0   Fridolin v4.0           2759
  1-0   Spike v1.2 Turin        2745

i want to show one example position, to illustrate Pawn style :

chess_diagram_Rxd5

Pawn 221103 -vs- Weiawaga v5.0.0 NNUE
White to move
position after 20...Nh4
7r/1pp1kpp1/2p4p/3bP3/6Pn/1PR4P/r1P2P2/2BRN1K1 w - - 0 21

here Pawn played Rxd5! after 20 seconds with eval +0.88

i was wondering if other (very strong) engines would give the same best move .. well, it seems only Pawn STRONGLY prefers this exchange sacrifice .. when i let Pawn think for a very long time (in SCID or Nibbler) using many MPV, it keeps prefering Rxd5 but not thAt strong .. this position seems a nice test case concerning playing style (thus pruning mechanism, PSTs .. i guess).

here are some statistics:

Rxd5_pawn-221103


Rxd5_komodo_v12


Rxd5_Berserk_v10_NN


Rxd5_SF_v15_noNNUE

no clue how this could help you improve Pawn, but i can pick other positions like this from the pgn ..
what do you say ?
sure, all this is just an indication .. maybe let Pawn play more and other games, with different (time) settings, to better determine its rating .. also my hardware must be considered : i use just a notebook, rather modern, and i set 128 Mb Hash and 2 threads for an engine, but i have no clue about optimal performance settings ..

trained PSQT for all piece types ?

trained PSQT depending on king position

this idea seems unique !? Regarding other chess engines, i never saw any function like that .. Pawn is "an experimental chess engine" isn't it ? Can such be applied to all pieces ?! I once wrote about "dynamic PSQTs" ..

contempt is agressive ?

the current Pawn version plays agressive !
it gladly sacrifices pawns and pieces for attack and complications, i like that !
i see Pawn does not go into great depth quickly, but often such sharp continuations require precise calculations ?

i did games in CuteChess against several engines, with 8 minutes per game : 4 games see Pawn_4_agressive_games.zip


sac1 : DeepBrutePos v2.4 (rating?) - Pawn
position below

sac1

15...Bxe3 ! and Pawn won.
FEN after 15.e3 : r2q1rk1/1b1n1ppp/pb6/1p6/P5n1/1QN1PN2/1PP2PPP/3RKB1R b K - 0 15


sac2 : CaffeinatedPawn f54f165 (rating?) - Pawn
position below

sac2

Pawn plays 3...e6! after 11 sec : the Icelandic gambit, agressive! I guess Pawn does not have an internal openingbook .. this gambit is sharp with precise deep variations .. Pawn won the game in great agressive style ! (but the strength of CaffeinatedPawn is unknown to me ..)
FEN after 3.c4 : rnbqkb1r/ppp1pppp/5n2/3P4/2P5/8/PP1P1PPP/RNBQKBNR b KQkq - 0 3
FEN after 10.d5 : 2kr3r/ppp1qppp/2n1bn2/3P4/2P5/5N2/PP2QPPP/RN2KB1R b KQ - 0 10


sac3 : Eden v0.0.13 (1405) - Pawn
position below

sac3

Pawn let White capture a pawn by Qxb7 and now Pawn plays Nd4! and wins quickly with a nice mate attack. Agressive !
FEN after 9.Qxb7 : r3kb1r/1Qp2ppp/p1n1pn2/3q4/6b1/4PN2/PP1PBPPP/RNB2RK1 b kq - 0 9


sac4 : Flux v2.2.2 (2357) - Pawn
position below

sac4

Pawn has expanded the pawns on the Kingside while having castled (!) and now Pawn even plays 16...b5! , leaving no shelter for the King with still many pieces on the board .. however, White can hardly move and Pawn wins nicely. Agressive ! And Flux is rather strong! (however, Flux also can win..)
FEN after 16.Qb3 : r3k2r/1p2qp2/p1p2n1p/2bpn1p1/8/1QN1P2P/PPP1BPP1/R1BR2K1 b kq - 0 16


so, Pawn sometimes loses with this agressive strategy : its 'contempt' seems high, and stronger engines resist this 'force' ..?!

here more recent Pawn games (while testing several found java .jar engines) : Pawn_games1.zip
times per move are included by CuteChess.


YOUR VIDEO BONUS TODAY
Chess Fuga
https://www.bitchute.com/video/g83R4hXKoMe0/

ELO strength ?

hi, i successfully compiled your Pawn code on Linux (Xubuntu 21.10) and run it in CuteChess.
The engine seems rather strong, but it has no version number !? What's its rating ?

strategical & tactical moves

recently i reached this position in one of my (tissatussa) recent online games :

r2q1rk1/5ppp/p1pbpn2/2pp1b2/8/1P1PPN1P/PBPN1PP1/R2Q1RK1 w - - 3 11

play chess puzzle = white to move2

position after 10... O-O : White to move.

chess strategy vs tactics

[ spoiler ]
the best move is e4, which i failed to play ..
SF and clones see this continuation as best from low depth and up, but Pawn thinks e4 is 2nd or 3rd best only at high depth AND with MPV more then 7 :

pawn leo puzzle MPV 7

pawn leo puzzle MPV 15

it seems Pawn is not looking for such strategical-&-tactical moves ? Or do we call this a 'positional' move ?


[Event "Rated Rapid game"]
[Site "@ https://lichess.org/y2BVx0oZ "]
[Date "2022.05.02"]
[White "tissatussa"]
[Black "janstahlberg"]
[Result "1-0"]
[WhiteElo "2005"]
[BlackElo "2132"]
[TimeControl "900+10"]
[ECO "A04"]
[Opening "Zukertort Opening: Sicilian Invitation"]

1. Nf3 c5 { A04 Zukertort Opening: Sicilian Invitation } 2. b3 d5 3. e3 Nf6 4. Bb2 Nc6 5. h3 Bf5 6. Bb5 a6 7. Bxc6+ bxc6 8. O-O e6 9. d3 Bd6 10. Nbd2 O-O 11. c4 Bxd3 12. Re1 h6 13. Ne5 Bxe5 14. Bxe5 Nd7 15. Bd6 Re8 16. Nf3 Bh7 17. Qc1 Rc8 18. Qa3 Qb6 19. Red1 e5 20. cxd5 Re6 21. dxe6 { Black resigns. } 1-0

dynamic PST

recently i let Pawn play against many (weak) engines, just to see how it plays (agressive!) and to determine its rating; at this moment i guess it's around 2300 .. sometimes Pawn draws or even wins a game against a much stronger engine !?

you seem to have knowledge about the general search & pruning and 'LMR research ratio' etc .. i'm not very familiar with all those concepts, but i can imagine and read some texts about it .. but i was wondering : i guess you're using a PST(s) ? As i understand, these hold some basic reference values for all squares regarding the pieces and their (optimal) movement, and these PSTs are fixed .. what if certain aspects of the position determine a 'custum PST' to use ? Such determining process might even be recursive ?

this is my idea in short, i can elaborate.
just thinking out of the box :-)

King_move

calculate rating of Pawn

Pawn has no rating .. i developed a method to calculate this : 2374
i've attached some files to reproduce this.

recently i did a lot of test games in CuteChess, after installing many (Linux based) engines, (very) weak and (very) strong. To see if an engine runs properly in CuteChess, i let it play against Pawn, from start position, with (mostly) 8 minutes per player plus 3 seconds bonus. In CuteChess all played games were saved in a PGN file, including their thinking time per move and its evaluation value, but not their rating : CuteChess has no data field for it .. so i added the fields 'WhiteElo' and 'BlackElo' to the PGN of each game (using the CCRL rating lists), where Pawn has an unknown rating by "?".

Then i created a simple Python terminal script which reads all results and thus calculates the rating of Pawn, as if the game list was a tournament with many (105) rounds and after each game the rating is updated. I used the official ELO calculation definition, which i found at https://herculeschess.com/how-chess-rating-is-calculated/ - it's all about the "expected score" due to the rating difference of the players.

the game result list is the output of the script when Pawn has a start rating of 2374 : (only then) its final rating is the same.
you can change this start rating at the top of the script .. eg. 1000 gives a final rating of 2087 and 2000 gives 2312 .. so, by doing this recusively (now give start rating 2312, etc) i calculated that Pawn has rating 2375. My first guess was 2300 .. not too bad !

i'm not sure i did the calculation the right way.
can anybody confirm or give a link to more / better info about this ?

Note 1: the K-factor depends on a 'masterrating' : above it K=16, under it K=32 .. i set this rating to 2400 (you can change this in the script) because i found no info about its real value.
Note 2: by changing the order of the games, Pawn's final new rating will also change (a bit).

Pawn_games2.pgn.zip
ratingcalc.py.zip
games_105_scores.txt.zip
How Chess Rating Is Calculated_ Crunching The Numbers - herculeschess.com.pdf

about forked version

i just discovered a fork of your engine here: https://github.com/FireFather/pawn .. i know this is legal, but can you tell me how links to forks are arranged on GitHub ? I mean you could have a link in your README to such forks, the fork page DOES show a link to its original!

this version has your name as author .. and it has no version number either .. so how can we know the creator of the (forked) engine ? Btw. that GitHub page doesn't have an Issues menu item, it's disabled, so i can not communicate with this coder, can i ? I want to found out why he (she) forked your Pawn .. 'cause it's an awesome engine ?

test for Pawn : the Scotch Gambit

For a long time i was not able to play chess at my club, due to the CV19 restrictions .. however, last Friday i played some games there and i spoke with friends, etc. .. we discussed a typical agressive opening, the Scotch Gambit, which has a good reputation for attacking players : Black should know the lines, otherwise Black will lose quickly .. so, i analysed this position with several engines :

Pawn_xd4-or-xe4

r1b1kb1r/ppp2ppp/2n5/q7/3pn3/2N2N2/PPP2PPP/R1BQR1K1 w kq - 0 9

this position is the result of the following Scotch Gambit moves :
1.e4 e5 2.Nf3 Nc6 3.d4 exd4 4.Bc4 Nf6 5.O-O Nxe4 6.Re1 d5 7.Bxd5 Qxd5 8.Nc3 Qa5 *

White sacrificed a piece and a pawn, but has a strong attack .. in this position only 1 move is best, according to SF 14 and many other strong engines : 9. Nxe4

You see the analysis in SCID of SF 14 NNUE and Pawn : the move 9. Nxe4 is clearly best, after letting SF 14 run for some time .. however, even after a long thinking time Pawn finds Nxd4 best move !? This way Pawn sacrifices more material, but this is certainly NOT the right approach .. i tested many other engines in this position, and ALL (!) do NOT find Nxd4 best move, Pawn is the only one ..

i just stumbled upon this position, it may suit you to develop Pawn and make it play more sane ?

Pawn connection stalls in CuteChess

hi, Pawn loses in CuteChess against several engines due to a "connection stalls" issue .. here's an example :

adachess_pawn_log

In a few other games Pawn also had this issue, see the PGNs, screenshots and logs in this ZIP :
Pawn_connection_stalls.zip

Btw. this "connection stalls" problem does not occur in all Pawn games. I used the existing Pawn version (which fixes the "Scid-MPV-order bug"), not the newest source "Big rework on the threading model" ..

I'm testing in CuteChess v1.2.0 on Xubuntu 21.10

wrong MPV order in Scid

hi,

i use Pawn to examine its playing style & approach in unbalanced positions eg. this one in Scid :

chess_engine_Pawn_to_move

r4rk1/pQpp1ppp/1b3q2/4p3/8/2P2N2/PP2KnPP/RNB2BR1 w - - 0 1

here, at first Pawn thinks Be3 is best, but later (using mpv 7 in Scid) it comes up with other best moves. Pawn often has a hard time winning this position with White, but so are many other engines ..

in Scid we see its mpv moves in some random order, not by eval value !?
so Scid shows "best move" is Ke1 with eval -1.0, but we also see Nbd2 with a better eval ..
i encounter only a few engines 'behave' like this in Scid : the sorting order is wrong.
i don't know how you, as a programmer, can 'feed' the mpv moves so this ordering is good.
it's annoying though, i call this a bug, can you fix it ?

Btw. Pawn seems to evaluate all mpv moves and output all their eval values and pv lines ONLY when the concerning depth is finished .. that's OK, although some engines (like SF) output each mpv line realtime, while maintaining a proper sort order, which i prefer (but might be difficult to implement).

-- i'm on Xubuntu 21.10 --

PSQT .dat file has pawn structure patterns ?

i was wondering .. your pawn is the only engine i know which has a (.dat) file concerning Piece-SQuare-Tables .. and i don't remember previous pawn versions had such .. i guess it's part of a next version.

the .dat file is no plain text - it will contain those tables .. or does pawn have some NN now ? Or pawn structure patterns and such ?

you might not want to fully tell us your code ideas, i know ..

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.