Friday, March 24, 2017

Standard Algebraic Notation Headache







In iCE I actually never bothered with the Standard Algebraic Notation described by FIDE. The UCI protocol uses Long Algebaric Notation (LAN) which is much simpler to implement in a chess program.

For SAN you have to implement a move generator, move making code, check and mate detection. And this all to just output a given move on the screen. For LAN output all you need is a table with the square names (0 = A1, 1 = B1, ... 63 = H8) and the piece letters for promotion (n,b,r,q).

The core engine functionality does not require SAN implementation however I have some helper functions e.g. running an EPD test suite or the simple output of the divide function (divide counts the resulting positions that are reached up to a given depth for all legal moves in a position) where it would be nice to have the output correctly.

So to not get out of programming practice I implemented SAN output in iCE. It is still not fully correct as it will include the source file or rank if two pieces can reach a target square even if one of the pieces is pinned. But this will not keep me wake at night.

Here is how it looks now. Probably no one except me will ever see such output but that is the point in chess programming. You mainly do it for yourself.  

position fen b3k1r1/4p3/4K3/8/R5R1/8/8/6R1 w - - 0 1
divide 5
move   divide #
------------------
Rxa8#          0
Rxg8#          0
Ke5      384.173
Kf5      316.308
Rga1     212.167
Rb1      263.331
Rc1      260.142
Rd1      230.933
Re1      235.617
Rf1      233.239
------------------
Rh1      254.486
R1g2     170.818
R1g3     183.832
Raa1     209.972
Ra2      244.058
Ra3      242.493
Rab4     199.705
Rac4     188.081
Rad4     159.635
Rae4      99.606
------------------
Raf4     144.555
Ra5      241.343
Ra6      204.052
Ra7      205.495
R4g2     244.212
R4g3     258.546
Rgb4     294.265
Rgc4     302.132
Rgd4     282.184
Rge4     204.924
------------------
Rgf4     300.731
Rh4      359.710
Rg5      224.460
Rg6      166.798
Rg7      168.936
Total Nodes of 35 moves : 7.690.939, Time : 0.062 sec





No comments:

Post a Comment