I've put out a new version of my little python chess engine at https://github.com/thomasahle/sunfish .
I think I have managed to remove all of the search instabilities of the previous version, while still keeping an efficient null-move and transposition table. This, together with much better testing code, has allowed me to fix bugs more efficiently and the new version beats the old one in 95% of games.
I have also changed the transposition table to 'dual score', which seems to make more sense for MTD.
The total number of code lines should not have changed. Hopefully this one will fare well in Ruxy's 'exotic languages' category :)
New version of Sunfish
Moderators: hgm, Rebel, chrisw
-
- Posts: 2204
- Joined: Sat Jan 18, 2014 10:24 am
- Location: Andorra
-
- Posts: 4607
- Joined: Wed Oct 01, 2008 6:33 am
- Location: Regensburg, Germany
- Full name: Guenther Simon
Re: New version of Sunfish
Thanks! It would be nice if it would show thinking output under WB.thomasahle wrote:I've put out a new version of my little python chess engine at https://github.com/thomasahle/sunfish .
I think I have managed to remove all of the search instabilities of the previous version, while still keeping an efficient null-move and transposition table. This, together with much better testing code, has allowed me to fix bugs more efficiently and the new version beats the old one in 95% of games.
I have also changed the transposition table to 'dual score', which seems to make more sense for MTD.
The total number of code lines should not have changed. Hopefully this one will fare well in Ruxy's 'exotic languages' category :)
Below is an example of the raw output logged with Inbetween.
The first column for the eval clearly is not standard and I suppose
WB stops parsing and shows nothing then.
Guenther
Code: Select all
ping 1
Error (unkown command): easy
pong 1
time 30000
otim 30000
usermove c2c4
# 1 79:79 5 25 g8f6
# 2 -20:-10 40 120 g8f6 b1c3
# 3 59:79 78 336 g8f6
# 4 -20:-5 237 1447 g8f6 g1f3
# 5 0:20 751 5954 g8f6 b1c3 d7d5 c3d5 f6d5 c4d5 d8d5
move g8f6
score before -20 after +99
time 29249
otim 1889
usermove g1f3
# 1 79:79 2 27 b8c6
# 2 -20:-5 15 79 b8c6
# 3 38:53 41 385 d7d5 c4d5 f6d5
# 4 0:5 142 1535 b8c6 b1c3 d7d5 c3d5 f6d5 c4d5 d8d5
# 5 0:9 678 7529 b8c6 b1c3 d7d5 c3d5 f6d5 c4d5 d8d5
# 6 0:14 2638 31212 b8c6 b1c3 d7d5 c3d5 f6d5 c4d5 d8d5
# 7 0:14 10010 119946 b8c6 b1c3 e7e6 d2d4 d7d5 c4d5 f6d5 c3d5 e6
d5
-
- Posts: 94
- Joined: Thu Feb 27, 2014 8:19 pm
Re: New version of Sunfish
That makes sense. Sunfish only calculates the score down to a certain coarseness (currently 20cp), which is why a lower:upper format is used.Guenther wrote: Thanks! It would be nice if it would show thinking output under WB.
Below is an example of the raw output logged with Inbetween.
The first column for the eval clearly is not standard and I suppose
WB stops parsing and shows nothing then.
I wonder what would be a good format for this? Just writing out the average?
-
- Posts: 4607
- Joined: Wed Oct 01, 2008 6:33 am
- Location: Regensburg, Germany
- Full name: Guenther Simon
Re: New version of Sunfish
You mean lower/upper bound difference of your given 'dual' score is always inbetween 20cp?thomasahle wrote:That makes sense. Sunfish only calculates the score down to a certain coarseness (currently 20cp), which is why a lower:upper format is used.Guenther wrote: Thanks! It would be nice if it would show thinking output under WB.
Below is an example of the raw output logged with Inbetween.
The first column for the eval clearly is not standard and I suppose
WB stops parsing and shows nothing then.
I wonder what would be a good format for this? Just writing out the average?
I guess an average value should be good enough then for displaying in a GUI.
-
- Posts: 4468
- Joined: Fri Apr 21, 2006 4:19 pm
- Location: IASI - the historical capital of MOLDOVA
- Full name: SilvianR
Re: New version of Sunfish
WOW ! THANK YOU A LOT !thomasahle wrote:
The total number of code lines should not have changed. Hopefully this one will fare well in Ruxy's 'exotic languages' category
-
- Posts: 94
- Joined: Thu Feb 27, 2014 8:19 pm
Re: New version of Sunfish
Yes, the two numbers should never be more than 20 apart. I'd still like a format which would allow me to show both. It's quite interesting related to how sure sunfish is on its result. Do you have any ideas?Guenther wrote: You mean lower/upper bound difference of your given 'dual' score is always inbetween 20cp?
I guess an average value should be good enough then for displaying in a GUI.
-
- Posts: 4052
- Joined: Thu May 15, 2008 9:57 pm
- Location: Berlin, Germany
- Full name: Sven Schüle
Re: New version of Sunfish
To match the standard format for WB thinking output you would have to omit the "#" at the beginning of each line of thinking output. Then the format would be "depth score time nodes PV" where score must be numeric, which is not the case if it contains a ":".thomasahle wrote:That makes sense. Sunfish only calculates the score down to a certain coarseness (currently 20cp), which is why a lower:upper format is used.Guenther wrote: Thanks! It would be nice if it would show thinking output under WB.
Below is an example of the raw output logged with Inbetween.
The first column for the eval clearly is not standard and I suppose
WB stops parsing and shows nothing then.
I wonder what would be a good format for this? Just writing out the average?
-
- Posts: 4607
- Joined: Wed Oct 01, 2008 6:33 am
- Location: Regensburg, Germany
- Full name: Guenther Simon
Re: New version of Sunfish
Of course Sven is right. I looked it up in the specs.thomasahle wrote:Yes, the two numbers should never be more than 20 apart. I'd still like a format which would allow me to show both. It's quite interesting related to how sure sunfish is on its result. Do you have any ideas?Guenther wrote: You mean lower/upper bound difference of your given 'dual' score is always inbetween 20cp?
I guess an average value should be good enough then for displaying in a GUI.
Here is some more info about the way the thinking output
in the XB/WB protocol is expected and/or handled:
The full specs are here (I guess this is a current version):
https://www.gnu.org/software/xboard/engine-intf.html
It seems the PV field can be 'abused' for other infos as its format is
freeform text. In this case you should be able to send your current eval
together with the PV, but you should change the format for the score info.
Code: Select all
10. Thinking Output
If the user asks your engine to "show thinking", xboard sends your engine the "post" command. It sends "nopost" to turn thinking off. In post mode, your engine sends output lines to show the progress of its thinking. The engine can send as many or few of these lines as it wants to, whenever it wants to. Typically they would be sent when the PV (principal variation) changes or the depth changes. The thinking output should be in the following format:
ply score time nodes pv
Where:
ply Integer giving current search depth.
score Integer giving current evaluation in centipawns.
time Current search time in centiseconds (ex:1028 = 10.28 seconds).
nodes Nodes searched.
*selective depth Maximium length of any branch in the current search.
*speed Nodes per second in last measured time interval.
* Reserved for future extensions.
*tbhits Number of tablebase probes made in the current search.
pv Freeform text giving current "best" line. You can continue the pv onto another line if you start each continuation line with at least four space characters.
The items marked with * are optional. If any of these items is present, the pv field must be preceeded directly by a tab character; if no tab character preceeds the first non-integer token, the pv field will start at the first non-blank character after nodes. Otherwise it will start after the last tab that is not behind any non-integer token. Of all integers between nodes and pv the last one is intepreted as tbhits. Of any remaining ones the first is interpreted as selective depth, and a second as speed. More infos could be added to this in the future. Note that older interfaces might consider the optional infos to be part of the pv field, and display them exactly as sent. It is therefore encouraged that engines use tabs or spaces to format this optional info so that it will display nicely in (not too wide) columns.
A question mark as the last character in the pv field should be used to indicate the reported score is from a fail low, and thus represents an upper bound only. Similarly, an exclamation point should be used to indicate a fail high / lower bound.
Mate scores should be indicated as 100000 + N for "mate in N moves", and -100000 - N for "mated in N moves".
Example:
9 156 1084 48000 Nf3 Nc6 Nc3 Nf6
Meaning:
9 ply, score=1.56, time = 10.84 seconds, nodes=48000, PV = "Nf3 Nc6 Nc3 Nf6"
Longer example from actual Crafty output:
4 109 14 1435 1. e4 d5 2. Qf3 dxe4 3. Qxe4 Nc6
4 116 23 2252 1. Nf3 Nc6 2. e4 e6
4 116 27 2589 1. Nf3 Nc6 2. e4 e6
5 141 44 4539 1. Nf3 Nc6 2. O-O e5 3. e4
5 141 54 5568 1. Nf3 Nc6 2. O-O e5 3. e4
You can use the PV to show other things; for instance, while in book, Crafty shows the observed frequency of different reply moves in its book. In situations like this where your engine is not really searching, start the PV with a '(' character:
0 0 0 0 (e4 64%, d4 24%)
-
- Posts: 4607
- Joined: Wed Oct 01, 2008 6:33 am
- Location: Regensburg, Germany
- Full name: Guenther Simon
Side note on Pypy
After I successfully installed pypy on my machine I thought why not generalize my other python program installed,
which is Shatranj in a few versions. Before it was linked to a Python 2.7 installation which worked.
With pypy 3.21 I get the error below. Any idea? Or do I need an earleir pypy?
which is Shatranj in a few versions. Before it was linked to a Python 2.7 installation which worked.
With pypy 3.21 I get the error below. Any idea? Or do I need an earleir pypy?
Code: Select all
0.000: - Starting server: C:/pypy321/pypy.exe -u C:/Engines/WB/Shatranj_117/Shatranj.py -xboard
0.016: - Priority class set to 16384
0.016: - Thread priority set to normal
0.250: < File "C:/Engines/WB/Shatranj_117/Shatranj.py", line 71
0.250: < print "Move: from square = %s to square = %s name = %s" % \
0.250: < ^
0.250: < SyntaxError: invalid syntax