ddugovic / Stockfish

Retired multi-variant fork of popular UCI chess engine; please use Fairy-Stockfish instead
https://github.com/ianfab/Fairy-Stockfish
GNU General Public License v3.0
132 stars 44 forks source link

Seirawan chess #426

Closed ianfab closed 6 years ago

ianfab commented 7 years ago

If anyone is interested, I have uploaded a first version for an implemenation of Seirawan chess in Stockfish: https://github.com/ianfab/Seirawan-Stockfish. Only the rules are implemented without any evaluation or search changes compared to standard chess (apart from introducing piece values for hawk and elephant), so it might not be that strong, and there might still be bugs. Nevertheless, in a first test with XBoard/Winboard it seemed to work fine (and of course it defeated me :-D ).

I have not implemented it in multi-variant Stockfish for a couple of reasons:

I still think it should be possible to somehow make it work in multi-variant Stockfish, but for the reasons mentioned above I think it is better to keep it separate from the variants without fairy pieces.

HGMuller commented 6 years ago

Sure, I don't want to change the move format in the engine protocols. This is purely for in the PGN. Rxe1/E, what it does now, is just awful.

alwey commented 6 years ago

No change requested, I just asked stockfish, too.

On the interface the engines will transmit h1e1h and h1e1e?

It answered: yes ;-)

alwey commented 6 years ago

@HGMuller

Sure, I don't want to change the move format in the engine protocols. This is purely for in the PGN. Rxe1/E, what it does now, is just awful.

+1

alwey commented 6 years ago

FYI: I opened a PR for seirawan support in cutechess. Comments, questions and suggestions are welcome.

ianfab commented 6 years ago

@alwey That is awesome news.The PR sounds like there are no bugs/limitations, so have you managed to solve the issues you mentioned before?

By the way, I implemented Makruk (Thai chess) in Stockfish recently (again as a separate repository due to the fairy pieces). Makruk is not very different from Shatranj, so starting from a similar implementation was much less work, but still a bit tricky due to the promotion on the 6th rank and the "silver general" moves.

HGMuller commented 6 years ago

How are you going to handle the counting rules? Do you think they are important for an engine, which would try to win in the shortest possible number of moves anyway? Should the engine just be biased against capturing the opponent's last Pawn?

ianfab commented 6 years ago

@HGMuller I am not sure. For now I left them out for simplicity, because I think it would require an extended FEN to be able to fully support counting rules, but workarounds like the one you suggested are also an option or to only support them for positions where the move history is given with the position command. Do you know whether or how they are implemented in other Makruk engines?

alwey commented 6 years ago

@ianfab Thank you. There are certainly bugs in it, but none that I am aware of. Regarding the castling moves, the choices presented in the UI do not have special graphics for insertion at the rook square. Currently, the choice for gating at a rook square is presented to the left of the respective choice for gating at the king square. I was too lazy to change this and I trust the community to make suggestions. I would like to finish the work on shatranj and courier.

I implemented Makruk (Thai chess) in Stockfish recently

Great to hear, I just cloned and compiled it. I will use the Makruk-Stockfish with Xboard and PyChess. Makruk for Cutechess is something I would like to attack in 2018. Currently, among others, I have branches for Grand Chess and Alice Chess. For the latter I am using Looking Glass 4.8S by @HGMuller for testing.

So far the award for most difficult implementation (most stupid developer) goes to seirawan and me. grand has been more work than the other variants but considerably less than seirawan. alice is a good candidate for causing headache, too.

ianfab commented 6 years ago

@alwey It's amazing how many variants you have already implemented and are implementing. The progress of multi-variant Stockfish would certainly not be as fast if we could not use fishtest (i.e., cutechess) for some variants.

Alice chess sounds like a big challenge, but also like a lot of fun. Now that you mentioned it I am wondering if that could also be implemented in Stockfish. Not that I am going to implement it any time soon, but it would certainly be interesting to at least try it some time.

@HGMuller I thought a bit about how to deal with the counting rules and came up with the following idea:

With these changes only the case where a piece is captured after counting has started might be evaluated incorrectly, e.g., if the stronger side sacrifices a rook in K+2R vs. K. In order to avoid extending the FEN, one could increase the half move clock to take account of the changed upper limit. E.g., if the rook is captured in the above example, then we add 16 [= [16 (1R) - 8 (2R)] * 2 (half moves)] to the half move clock, so that the effective number of remaining moves is the same as if we would remember that counting started from a situation with two rooks. That would also make sure that transpositions from different endgames can easily be compared.

I am relatively new to Makruk (learned the rules a few days ago), so I do not have much knowledge about endgames. I have tried to incorporate knowledge about all basic endgames (including 3 met, ma+2 met, khon + ma, khon + met, etc.), but I basically had to make educated guesses and let Stockfish figure out the correct result by letting it solve them. Does anyone of you have a table of material configurations that are known wins/draws? I would also be interested to know which kind of endgames are very common or important in Makruk, e.g., something similar to rook and pawn endgames in chess.

I also do not know much about other Makruk engines. Does anyone have a rough estimate of the relative and/or absolute playing strength of Makruk engines? I only tested Stockfish against Sjaak II and fairymax, where Stockfish finished first slightly in front of Sjaak II.

HGMuller commented 6 years ago

A good way to present Alice Chess is to super-impose the boards, displaying pieces in the 'non-current layer' with a high degree of transparency. And as soon as the user clicks a piece, make the layer that contains it current.

alwey commented 6 years ago

@ianfab ; Thank you. I have been aware this (Multi Variant Stockfish) project for about 16 months now. I admit that together with lichess.org it has had a major influence and inspired my participation in the cutechess project. Other major influences are from Xboard, Fairymax, and Sjaak II, and the literature about variants and the history of chess. HGM.

@HGMuller:

A good way to present Alice Chess is to super-impose the boards, displaying pieces in the 'non-current layer' with a high degree of transparency.

Thank you. I think this is indeed a good way for presentation in the GUI. This will be a thing to work on at a second stage. Currently, I am only using a plain board representation of 16 files and 8 ranks without any indentations, markings or eye guides (the A board is the left part, the B board the right part).

In the first phase I am trying to get the machine interface right, the legality of moves and positions, game adjudication, input/output of positions and game notation and a basic GUI representation. I am glad to have Looking Glass to help me.

alwey commented 6 years ago

@ianfab : First light with Cutechess and Makruk:

Rank Name                          Elo     +/-   Games   Score   Draws
   1 stockfish-mak-f364111         512     179      60   95.0%   10.0%
   2 sjaakii-1.4.1                 -53      78      60   42.5%   25.0%
   3 sjaakii (1.3.1 xboard)       -120      77      60   33.3%   30.0%
   4 shamax-5.0b                  -154      86      60   29.2%   21.7%

120 of 120 games finished.

All games (30 s + 0.3 spm, 1 Thread on a core-i5 laptop) from starting position and with Shatranj adjudication rules. There were no duplicate games.

I had detected some issues within cutechess /wrt pieces with lower move symmetry, here Khon (Silver General) and found a provisional solution. This is not quite ready for the big stage.

ianfab commented 6 years ago

@alwey Thanks. Looks like the evaluation improvements since the first version has given SF quite an edge over Sjaak. I can imagine that the asymmetric piece movements cause some issues. For SF that was luckily not that problematic as I could mostly simply copy&paste the logic from the pawns and only change the list of possible relative square differences. Would this be the first variant with asymmetric piece moves (apart from pawns) in cutechess?

alwey commented 6 years ago

@ianfab :

Would this be the first variant with asymmetric piece moves (apart from pawns) in cutechess?

Exactly. I must talk to Ilari and Arto about how we should generalise the move generation in the base classes.

HGMuller commented 6 years ago

Note that Ferdinand Mosca also made a Makruk engine (Bilis), and that his engines tend to be pretty strong compared to Fairy-Max and Sjaak II.

alwey commented 6 years ago

@HGMuller : Thank you for the hint. I got Bilis and indeed it turned out to be significantly stronger than Sjaak II and Fairy-Max:

Rank Name                          Elo     +/-   Games   Score   Draws
   1 stockfish-mak-f364111         359     103      80   88.8%   15.0%
   2 Bilis_v1.0                    127      65      80   67.5%   32.5%
   3 sjaakii-1.4.1                 -61      60      80   41.2%   40.0%
   4 fairymax-5.0b                -174      62      80   26.9%   38.8%
   5 NebiyuAlien                  -185      55      80   25.6%   46.2%

200 of 200 games finished.

Again, Tc = 30 s + 0.3 spm, 1 Thread. This time Standard Chess adjudication was used.

@ianfab : I implemented a solution for Khon move offsets without changes to the base classes, so I can move on to the next topic: adjudication rules.

ianfab commented 6 years ago

I have implemented a first version of support for counting rules, but it can still be turned off via a UCI option. I have not made any evaluation adjustments yet, so it can only find the draw by resolving it in the search. In an example with two rooks (8/8/5k2/7p/8/6RR/3K4/8 w 0 1), it took about 0.1s for it to find that capturing the last pawn leads to a draw. For material configurations with higher move counts, that might not work that well.

HGMuller commented 6 years ago

Indeed, the draws will be very hard to recogize by search, as you basically have to search every possible branch to the available number of moves before you can conclude it is a draw. Any reduced branch would still have the huge material advantage.

A first approximation would be to consider any end-game against a bare King as drawish, and apply a hefty reduction to the score (like a factor 8). This should strongly bias the engine against capturig the last piece, if it is significantly ahead in the presence of that piece. End-games like KRPPKR could still be a problem, and allow f.e. rabid-Rook defense because you canot afford to take the Rook. But in general this would probably work much better than not discounting any end-game at all.

Op 1/1/2018 om 6:40 PM schreef Fabian Fichter:

I have implemented a first version of support for counting rules https://github.com/ianfab/Makruk-Stockfish/commit/8ae928d54cd93492be9adb25f06e7b0e7a6f1974, but it can still be turned off via a UCI option. I have not made any evaluation adjustments yet, so it can only find the draw by resolving it in the search. In an example with two rooks (8/8/5k2/7p/8/6RR/3K4/8 w 0 1), it took about 0.1s for it to find that capturing the last pawn leads to a draw. For material configurations with higher move counts, that might not work that well.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ddugovic/Stockfish/issues/426#issuecomment-354665645, or mute the thread https://github.com/notifications/unsubscribe-auth/AVNwNjDB-2XfA0XopdM3H2vtk7F8Gcd1ks5tGRikgaJpZM4P_yPM.

http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient Virus-free. www.avg.com http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient

<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

ianfab commented 6 years ago

@HGMuller Only reducing the evaluation for endgames against the bare king would not work well in Stockfish without applying further changes since it only follows the strategy of driving the king to the corner if the weaker side has no material left and for a few specific material configurations. So it would fail to make progress in situations like 2 khon vs. pawn (e.g., 8/8/5k2/7p/6SS/8/3K4/8 w 0 1) if it does not capture the pawn.

I have written an experimental change where the evaluations of positions against the bare king are scaled by "number of remaining half-moves in counting" / 128, and where the general "KXK" endgame evaluation function is also applied to cases where the weaker side still has a pawn or a met. This seems to work well even in cases where it can not resolve mate from the initial position, e.g., the aforementioned 2 khon vs. pawn. It first drives the king towards the corner and only takes the pawn as soon as it finds mate within the required number of moves. So the first results look good, but I have not done much testing yet.

ianfab commented 6 years ago

I searched for an even stronger opponent than Bilis, so I tried Alisa which claims to be the strongest Makruk AI. I set up different levels in the browser (sharp and disciple) and mirrored the moves in XBoard to let it play against Stockfish (including https://github.com/ianfab/Makruk-Stockfish/commit/d782b1f970b0cc5f041f323f5b98a4a73edf69ef). I tried to use similar thinking times for Stockfish as it took for Alisa to make a move. The actual move times and https://trello.com/c/Ab465qHu/57-alisa-level suggest that the levels do not use any handicap except from the thinking time, but I do not know for sure. To take account of the speed handicap due to Alisa running with javascript in the browser, I gave Stockfish a time handicap in the last game, only using 10s for 40 moves, whereas the opponent used about 1s per move. To my surprise, Stockfish performed incredibly well and won all three games (all three playing white, since I did not find an option to play with black against Alisa in the browser).

Here is the PGN of the games: stockfish-alisa.pgn.txt

In the opening, Stockfish's play looked a bit strange to me and it also was bad at predicting Alisa's opening moves. Starting from the middlegame Stockfish always seemed to outplay the opponent and usually correctly predicted the opponent's moves (apart from blunders).

HGMuller commented 6 years ago

I would take such claims with a grain of salt. I am not aware of any Makruk championship for computers. And I don't recall having ever seen a Makruk competition at the ICGA computer Olympiad. A Thai user of Fairy-Max informed me that it would be the strongest Makruk program if I could only equip it with EGT for some elementary end-games. I would not believe a Thai program is stronger than Bilis without proof. Playing a JavaScript demo probably doesn't mean anything, though.

ianfab commented 6 years ago

I also could not find any engine match results, that is why I wanted to test it. Due to their claim I simply considered it as a interesting candidate to be tested, and I thought that a dedicated Makruk engine that seems to be actively developed might indeed be stronger than Stockfish, since I expect that for a strategic variant like Makruk evaluation is very important, and apart from choosing reasonable piece values (from my almost non-existent experience with Makruk) I did not change much of Stockfish's (not endgame-specific) evaluation code.

I of course can not be sure that the browser version is at full strength, but as I mentioned above the move times and the information I found kind of suggest that this might be the case and that the only limitation of the browser version is that the window of possible move times is restricted from above and below (out of 15 levels/move-times only 5 from the middle seem to be available). A lot of speculation of course, but at least I have the feeling that I have a rough idea of its playing strength, since I played one more game with more significant time handicap where Stockfish lost. Now I can move on to improving Stockfish (if I find the time).

HGMuller commented 6 years ago

Well, as chess variants go, Makruk is quite close to Chess (after tradig Queens). So most of Stockfish' strategic insight should apply. Most obvious difference is that Pawn promotion is hardly worth anything, which reflects back on passer bonuses. The most important term in Pawn evaluation seems to be the distribution over square shades of the promotions. Having two Pawns that promote on different shades can often be better than having 3 Pawns that promote on the same shade.

It is always good to have new opponents, but before spending too much time on Alisa I would first make sure that it is stronger than Bilis, otherwise it would just be a waste of time. The web version seemed to be limited in thinking time (which might be of no importance for the TC you like to test at). There does not seem to exist a native Windows version of Alisa; what they advertize as such turns out to be a .apk file you have to run on an Android emulator. I consider it a virtual certainty that the Alisa developers don't even know Bilis exists, and that even when they did, they would not bother to test against it. But perhaps I am to skeptical.

But if Alisa is available in JavaScript, it is of course available in source code, and it should be comparatively easy to equip it with a standard engine interface, so it could be used in automatic testing.

Op 1/4/2018 om 11:53 PM schreef Fabian Fichter:

I also could not find any engine match results, that is why I wanted to test it. Due to their claim I simply considered it as a interesting candidate to be tested, and I thought that a dedicated Makruk engine that seems to be actively developed might indeed be stronger than Stockfish, since I expect that for a strategic variant like Makruk evaluation is very important, and apart from choosing reasonable piece values (from my almost non-existent experience with Makruk) I did not change much of Stockfish's (not endgame-specific) evaluation code.

I of course can not be sure that the browser version is at full strength, but as I mentioned above the move times and the information I found kind of suggest that this might be the case and that the only limitation of the browser version is that the window of possible move times is restricted from above and below (out of 15 levels/move-times only 5 from the middle seem to be available). A lot of speculation of course, but at least I have the feeling that I have a rough idea of its playing strength, since I played one more game with more significant time handicap where Stockfish lost. Now I can move on to improving Stockfish (if I find the time).

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ddugovic/Stockfish/issues/426#issuecomment-355422483, or mute the thread https://github.com/notifications/unsubscribe-auth/AVNwNkj_ufsZZDLNm8-i3Dt2J5s5n_eGks5tHVZzgaJpZM4P_yPM.

http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient Virus-free. www.avg.com http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient

<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

alwey commented 6 years ago

I am quite confident that Stockfish already is about 200 elos stronger than Bilis 1.0 .

Score of Stockfish 030118 64 BMI2 vs Bilis_v1.0: 134 - 7 - 59  [0.818] 200
Elo difference: 260.49 +/- 44.80

There is a native Windows version of Alisa. The developer calls himself peacedeveloper and older versions of Alisa can be found under different package names., e.g. Peace Thai Chess Master. This is a version from 2007:

ThaiChess/blackbox$ wine Alisa.exe

Alisa Black Box
 - Alice Project -
by
Akkaradech Sujanil
peacedeveloper@yahoo.com
http://www.peacedeveloper.cjb.net
------------------------------
Welcome to Alisa
------------------------------
uci
id name Alisa 1.02
id author Akkaradech Sujanil
uciok
ucinewgame
go movetime 1000
Need Registeration
ianfab commented 6 years ago

Thanks to @alwey's great work cutechess now supports Seirawan chess and Shatranj. @ppigazzini It would be very nice if you could create updated cutechess compiles, because I could then add these variants in fishtest to be able to test the respective Stockfish forks (Seirawan, Shatranj).

ppigazzini commented 6 years ago

@ianfab build & test processes started.

ianfab commented 6 years ago

@ppigazzini Thanks.

ianfab commented 6 years ago

The first tests for Seirawan chess and Shatranj after the worker update are looking good, so feel free to submit tests also for these variants. @ceebo Now that testing is more convenient and reliable, I will perhaps add a few regression tests for our previous development to check again that we did not introduce a regression anywhere.

alwey commented 6 years ago

@ianfab: Please note that cutechess-cli's ShatranjBoard is adjudicating draws after 70, not after 50 reversible moves

ianfab commented 6 years ago

@alwey Thanks for the info. I saw it in your PR, but have not really kept it in mind. I do not have a preference for a certain number here since I guess no such rule (neither 50 nor 70) is historically known for Shatranj, so I will just adapt Stockfish to be consistent with the 70-move rule in cutechess.

alwey commented 6 years ago

@ianfab :The draw rate might drop a bit, because there are many slow-moving pieces. The fifty-move rule of chess is derived from shatranj, which had a seventy-move rule. https://en.wikipedia.org/wiki/Fifty-move_rule#History

ianfab commented 6 years ago

@alwey Oh, I didn't know that. In that case I will certainly change it to 70 moves.

Vinvin20 commented 6 years ago

May be it's time to challenge Yasser Seirawan to a 10 games in his variation :-) Is there a site where one can play Seirawan chess vs Stockfish ? If that doesn't exist, I will be glad to manually operate Stockfish in Winboard and send move on site. Which site does support SChess ? I know some sites where one can play Crazyhouse960 and another one RelayChess ...

HGMuller commented 6 years ago

The Variant ICS (winboard.nl) supports S-Chess, an WinBoard can be used as a client to play an engine on it.

Op 4/18/2018 om 10:12 AM schreef Vinvin20:

May be it's time to challenge Yasser Seirawan to a 10 games in his variation :-) Is there a site where one can play Seirawan chess vs Stockfish ?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ddugovic/Stockfish/issues/426#issuecomment-382303072, or mute the thread https://github.com/notifications/unsubscribe-auth/AVNwNhqGKkcSwoOBQTsE9OzIH9qjsKlXks5tpvV3gaJpZM4P_yPM.

http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient Virus-free. www.avg.com http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient

<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

Vinvin20 commented 6 years ago

One point would be to promote Seirawan Chess with the help of Lichess broadcast.

But is it possible to do that ?

HGMuller commented 6 years ago

I don't think LiChess supports S-Chess (or any variant with unorthodox pieces).

ddugovic commented 6 years ago

winboard.nl works great (I've played on it before) especially using WinBoard/XBoard.

Pity that Tom's Live Chess Viewer (probably) doesn't support variants, so broadcast options (to reach the widest possible audience) would probably be to livestream the games.

HGMuller commented 6 years ago

TLCV is also a dedicated client that has to be downloaded first, just like WinBoard. So in principle there is not much difference between running the game on an ICS and using WinBoard as client to view the games, or using TLSC to relay games played through a GUI and using TLCV to view them. Except that, indeed, TLCV does not support variants. And is almost impossible to set up due to firewalls and such.

I guess that to really reach a large audience you would need to use a browser-based solution; many people dislike having to download dedicated clients. In fact I have been working on the development of such a client, using my turn-based server and its JavaScript/HTML client as a viewing agent. The broadcaster then simply uploads the game move by move to that server (using a special password that allows it to submit moves for both players).