fairy-stockfish / Fairy-Stockfish

chess variant engine supporting Xiangqi, Shogi, Janggi, Makruk, S-Chess, Crazyhouse, Bughouse, and many more
https://fairy-stockfish.github.io/
GNU General Public License v3.0
620 stars 197 forks source link

Cambodian chess (Ouk Chatrang) #39

Closed thaichessswinboard closed 5 years ago

thaichessswinboard commented 5 years ago

Can you make variant cambodian (Oak khmer chess) and please see this video explain how cambodian variants https://www.youtube.com/watch?v=RD91zLPxTmI many thanks if you make this variants many khmer player will likes and have strong engine to play this games. I hope you interesting to do.

Regard.

Makruk and khmer player fan club.

ianfab commented 5 years ago

Cambodian chess definitely is among the list of variants I want to implement, but it is unclear at the moment when it will happen, because I am not sure yet how to implement the special moves of the king and the queen.

Links for future reference: https://en.wikipedia.org/wiki/Makruk#Cambodian_chess http://www.khmerinstitute.com/culture/ok.html

@thaichessswinboard By the way, are you aware that you can now play Makruk against Fairy-Stockfish and human players online at https://pychess-variants.herokuapp.com/ and even let your games be analyzed by the engine?

ianfab commented 5 years ago

By the way, does anyone know other variants with such kinds of one-time moves?

alwey commented 5 years ago

Do you mean Makruk variants or in general? Chess ;-), some variants of Chaturanga (King leaps like Knight once), Courier-Spiel (possibly the Medieval Queen does not start at the third rank but on the first rank and can leap to the third, https://www.youtube.com/watch?v=lIgvC4iFtHw), there are certainly more examples.

thaichessswinboard commented 5 years ago

Many Thanks to interesting Cambodian chess (Ouk Chatrang). White King can move to b2 and g2 square and Black King Can move to b7 and g7 for castle only. And White Queen can move in the first opening from d1-d3 and move White Pawn to d4 and Black Queen can move from d8-d6 and Move Black Pawn the same time to d5 that how it the game of Oak play I hope you understand what I mean. And thanks you for suggest how to play makruk on website.

Regard

Makruk and khmer player fan club.

ianfab commented 5 years ago

@alwey Yes, I was actually also even thinking of moves like castling, although I am only interested in really distinct forms of one-time moves, and not of 100 variants that have castling.

The reason why I am asking is that Fairy-Stockfish is feature/rule-centric and variants are just a mere collection of features/rules, so I do not really implement new variants but new features and the variants just emerge as a side effect. Therefore, I am interested in understanding how the feature should be designed to cover as many variants as possible without adding too much complexity.

alwey commented 5 years ago

@ianfab :

The reason why I am asking is that Fairy-Stockfish is feature/rule-centric and variants are just a mere collection of features/rules, so I do not really implement new variants but new features and the variants just emerge as a side effect. Therefore, I am interested in understanding how the feature should be designed to cover as many variants as possible without adding too much complexity.

I guessed so. I am planning to implement and to suggest a GeneralBoard or likewise to the CuteChess team that can be used in connection with description files for game rules. This would be more flexible but slower than the direct implementation of variants.

@ianfab @thaichessswinboard: /Wrt Ouk: It is implemented in cutechess. Here the initial moves of Maiden (Neang, two ranks forward) and Pawn are separate. This is consistent with educational youtube videos made by former Cambodian Chess champion Chheav Bora, e.g. https://www.youtube.com/watch?v=kYQ69kDINHM&list=RDQMHskKKNrnye4&index=4 and https://www.youtube.com/watch?v=KjzKrzYbJag . The Kings may on their first move leap sideways once like a Knight when not in check. All the special moves can not capture.

From oukboard.h:

 * \brief A board for Ouk Chatrang (Ouk Khmer, Cambodian Chess)
 *
 * Ouk Chatrang is a variant of chess popular and with a long tradition
 * in Cambodia. It is closely related to Chaturanga and Makruk.
 *
 * Cambodian Chess (Ouk) and Thai Chess (Makruk) are essentially the same game,
 * but the pieces are named differently.
 *
 * Ouk has additional moves, which have been abandoned in Makruk:
 *
 * The King has the option to make an initial leap sideways like a Horse
 * (Knight), but only if not in check. The Advisor (Maiden, Neang) may leap
 * straight forward two squares on its initial move. These moves cannot capture.
 *
 * \note Rules: http://history.chess.free.fr/cambodian/Cambodian%20Chess%20Games.htm
 *              http://www.khmerinstitute.com/culture/ok.html
ianfab commented 5 years ago

@alwey That sounds awesome.

I am aware of the Ouk and Kar Ouk implementations in cutechess and will of course ensure compatibility (when I finally get to implementing it). The only thing I implemented so far is the possibility to skip the check counts in the FEN (compared to 3/5check) if already the first check wins in order to be compatible with Kar Ouk FENs in cutechess.

thaichessswinboard commented 5 years ago

Fairy-max for winboarrd can move likes Oak but it not strong I think stockfish more strong to move and have skill more than other program that why I ask for stockfish to make engine. Stockfish can make endgames and make program to progess and move like human thinking but endgames of Oak maybe complicate more than chess because Values of pieces nearly the same values but it take time to do program if you can do some example of source code it will be great for players they will learn good move from program more. I hope you understand what I mean. If you have time or somebody interesting edit King and Queen move to variant cambodian it will be good. Or can you suggest what file about King moves and queen moves In source code of stockfish it hard to read where is king moves direction or Queen direction. Thanks for read my explain.

ianfab commented 5 years ago

@thaichessswinboard @alwey I have some questions regarding the rules of the special king and queen moves that are not clear to me yet:

thaichessswinboard commented 5 years ago

you can try play against computer this website but it not strong engine I try long time ago programmer is the real cambodian he know exact rules on this website http://ouk.sourceforge.net/kchess.php you will know the real rules many thanks to interesting

Regards. thaichesswinboard.

alwey commented 5 years ago

Since the special moves can not be used to capture a piece, can the opposing king safely move to these squares (e.g., b2, f2, and e3 for the black king) or is it considered to be in check, i.e., moving there by the king is illegal? In cutechess the latter seems to be the case.

This seems to be a bug. There are contrary rules in the implementation of OakBoard between move generation and check detection.

Can the queen leap over the square right in front of it if it is occupied by a piece? In cutechess it seems to be allowed.

The Neang can leap over a piece in front of it when making its initial move. E.g. https://www.youtube.com/watch?v=yxFXGG1B4wY at 0:25 Min.

Can the queen's move be used to evade a check? Let's say the white king is on e4 and a black rook on e2, can the queen move from e1 to e3? In cutechess it can

I was not sure about this, so I implemented the simplest rule (or rather not implemented a prohibiiton). EDIT: Four sources were used for the rules, see comments in the discussion https://github.com/cutechess/cutechess/pull/348

EDIT: probably the King cannot capture but the Neang can capture on the special move

alwey commented 5 years ago

Cutechess implementation (when bug is removed, comment in header needs update)

SPECIAL MOVES             King not in Check    King in check

King (Sdaach)             no captures          not allowed
Queen (Neang)             all                  all

We need some additional reliable sources.

ianfab commented 5 years ago

Thanks a lot. I also checked in A world of chess, where it is explicitly mentioned that some players allow captures by the special move of the queen/neang and some do not.

alwey commented 5 years ago

Currently the cutechess implementation of rules goes towards that of http://ouk.sourceforge.net but unintentionally. I would really like to understand more of Cheeav Bora's introduction to Ouk Chatrang, because he does discuss some of the tricky cases. But I am not sure whether he says this and that is allowed or not. However sometimes he makes clear gestures so that one understands: this move is not allowed.

alwey commented 5 years ago

I also checked in A world of chess, where it is explicitly mentioned that some players allow captures by the special move of the queen/neang and some do not.

Ah, interesting. so no wonder that there is some confusion.

A World of Chess is written by Jean-Louis Cazaux who also is the editor of http://history.chess.free.fr. This site hosts one of our sources, Cambodian Chess Games by Vuthy Tan

alwey commented 5 years ago

Test positions

  1. rnsmks1r/8/pppppppp/8/3PP3/PPP1nPPP/4N3/RNSKMS1R w DEde 0 0 4
  2. rnsmks1r/8/pppppppp/8/3PP3/PPP1nPPP/8/RNSKMS1R w DEde 0 0 4
  3. rn1mks1r/8/pppppppp/8/3PP3/PPP1sPPP/8/RNSKMS1R w DEde 0 0 4

t1t2t3

When White captures the black Horse with the Advisor (Mxe3), in all three cases Sjaak II 1.4.1 rejects the move but Fairymax 5.0Qaccepts them all.

ianfab commented 5 years ago

I found out that there are a few tricks to massively simplify the implementation (e.g., sharing some code with S-Chess^^), so I actually already have a seemingly working version, see https://github.com/ianfab/Fairy-Stockfish/commit/1c486ed72da75decd73e9fc09db2f726e0b7ac7b. I only did limited testing so far (perft + bench + 2 games in cutechess), but independent testing from your side would anyway be very welcome. The rules that I implemented can be summarized by the aforementioned table:

SPECIAL MOVES             King not in Check    King in check

King (Sdaach)             no captures          not allowed
Queen (Neang)             all                  all

@alwey I have seen difference in perft 6 results that might be due to the bug in the cutechess implementation, but I am not sure yet: https://github.com/cutechess/cutechess/blob/4142aeaab8ae80b0d6b9bf8b2f693af0362e0b0e/projects/lib/tests/chessboard/tst_board.cpp#L1417 states 204755574 Stockfish reports 204757579

alwey commented 5 years ago

I pushed a branch ouk6 with the corrections into my repository. Now perft 6 matches: 204757579.

ianfab commented 5 years ago

That was fast. Thanks for confirming the number.

thaichessswinboard commented 5 years ago

some of example game of fairymax variant cambodia move maybe you interesting

[Event "Computer Chess Game"] [Site "PCST"] [Date "2019.10.16"] [Round "-"] [White "Fairymax 5.0"] [Black "Fairymax 5.0"] [Result "1/2-1/2"] [TimeControl "180/180"] [Variant "cambodian"] [VariantMen "M:FifD;K:KiN"] [FEN "rnsmksnr/8/pppppppp/8/8/PPPPPPPP/8/RNSKMSNR w EDed 0 1"] [SetUp "1"]

{-------------- r n s m k s n r . . . . . . . . p p p p p p p p . . . . . . . . . . . . . . . . P P P P P P P P . . . . . . . . R N S K M S N R white to play --------------}

  1. c4 f5 2. Se2 c5 3. Nc3 Nc6 4. Kf2 Nf6 5. f4 Kg7 6. Nf3 Sd7 7. Sd2 d5 8. d4 Na5 9. dxc5 Nxb3 10. Rb1 Nxc5 11. cxd5 Mc7 12. dxe6=M Nfe4+ 13. Nxe4 Nxe4+ 14. Kg2 Sxe6 15. Sed3 Nf6 16. Sc3 Rb8 17. Md2 Md6 18. Scd4 Se7 19. Mc3 Mc5 20. Se5 Sxe5 21. Nxe5 Se6 22. Nf3 Md6 23. Md4 Rb7 24. Rbc1 Sd5 25. Me5 Mxe5 26. fxe5 Nd7 27. Rhe1 Se4 28. Sxe4 fxe4 29. Nd2 Nc5 30. Red1 Re7
  2. Rc2 Rd8 32. Rb1 b5 33. Nb3 Nxb3 34. Rxb3 Rxe5 35. Rc7+ Kf8 36. Rb2 Red5
  3. Rf2+ Rf5 38. Rfc2 Rf3 39. Rc8 Rxc8 40. Rxc8+ Ke7 41. Rc7+ Kd8 42. Rc3 h5 43. g4 Kd7 44. a4 Kd6 45. Rc8 Rxe3 46. Ra8 Ke5 47. gxh5 gxh5 48. Rxa6 bxa4 49. Rxa4 Kf4 50. h4 Rf3 51. Rb4 Kf5 52. Ra4 Rc3 53. Ra5+ Kg4 54. Ra4 Rc2+ 55. Kg1 Kf3 56. Ra6 e3=M 57. Rf6+ Mf4 58. Rg6 Mg3 59. Rf6+ Kg4 60. Rg6+ Kxh4 61. Kf1 Mf4 62. Ke1 Rh2 63. Kf1 Mg5 64. Rb6 Kg4 65. Rb4+ Mf4 66. Rb8 h4 67. Rd8 h3=M 68. Rd3 Me5 69. Rb3 Kf4 70. Kg1 Rg2+ 71. Kf1 Rg3 72. Rxg3 Kxg3 73. Ke2 Kf4 74. Kd3 Mg4 {User adjudication} 1/2-1/2

at the endgame must move advance more than this but program capture Rook at the End make the game not advance but it ok for beginner If stockfish can do maybe end game advance more than other Engine.

regards.

thaichesswinboard.

thaichessswinboard commented 5 years ago

and another game but must advance more than this at the endgames

[Event "Computer Chess Game"] [Site "PCST"] [Date "2019.10.16"] [Round "-"] [White "Fairymax 5.0"] [Black "Fairymax 5.0"] [Result "0-1"] [TimeControl "180/180"] [Variant "cambodian"] [VariantMen "M:FifD;K:KiN"] [FEN "rnsmksnr/8/pppppppp/8/8/PPPPPPPP/8/RNSKMSNR w EDed 0 1"] [SetUp "1"]

{-------------- r n s m k s n r . . . . . . . . p p p p p p p p . . . . . . . . . . . . . . . . P P P P P P P P . . . . . . . . R N S K M S N R white to play --------------}

  1. Kf2 Kc7 2. f4 f5 3. Nf3 c5 4. Sd2 Nf6 5. c4 Nc6 6. Nc3 Sd7 7. e4 Nd4 8. Nxd4 cxd4 9. Ne2 e5 10. exf5 gxf5 11. Sg2 Me7 12. Sf3 Sf7 13. b4 Sfe6 14. Rc1 Sc6 15. Rc2 b5 16. Rh2 Rab8 17. Rh1 bxc4 18. Rxc4 Nd5 19. Rc2 Mf6 20. Rc4 Rb5 21. g4 Rh7 22. Rg1 Rh8 23. Rh1 a5 24. gxf5 Sxf5 25. fxe5 Mxe5 26. Rg1 axb4 27. Rg7+ Kb6 28. axb4 Nxb4 29. Rf7 Se6 30. Re7 Na6 31. Rc1 Scd5
  2. Rg7 Nc5 33. Ng3 Rf8 34. Rh7 Rb2 35. Ne2 Se4 36. dxe4 Nxe4+ 37. Kg2 Rxf3
  3. Rcc7 Rfb3 39. Rb7+ Kc5 40. Rxb3 Rxb3 41. Rxh6 Sd5 42. Nc1 Rg3+ 43. Kh2 Ra3 44. Rg6 Sc4 45. h4 Nf6 46. Rg5 Sc3 47. Nd3+ Kc4 48. Rg3 Ra2 49. Nc1 Rc2
  4. Rg2 Sxd2 51. Mxd2 Ne4 52. Rg7 d3=M 53. h5 Md4 54. Kh3 Nxd2 55. Rg1 Mc3
  5. Nxd3 Kxd3 57. h6=M Ne4 58. Kg4 Md4 59. Mg5 Me5 60. Kf5 Kd4 61. Rd1+ Rd2
  6. Rxd2+ Nxd2 63. Mh4 Nf3 64. Mg5 Ke3 65. Mh6 d5 66. Mg5 d4 67. Mh6 d3=M
  7. Kg4 Nd4 69. Kg5 Me4 70. Mg7 Nf5 71. Mh6 Kd4 72. Kh5 Mf6 73. Mg5 Mxg5
  8. Kxg5 Ke5 75. Kg4 Nd4 76. Kg3 Kf5 77. Kf2 Kf4 78. Kg2 Nf5 79. Kf2 Mf3
  9. Ke1 Ke3 81. Kd1 Nd4 82. Ke1 Me4 83. Kf1 Nf5 84. Ke1 Md5 85. Kf1 Nh4 86. Ke1 Ng2+ 87. Kd1 Kd3 88. Kc1 Ne3 89. Kb2 Kc4 90. Ka3 Mc6 91. Ka4 Nd5 92. Ka5 Kb3 93. Ka6 Kb4 94. Ka7 Kc4 95. Kb8 Kc5 96. Kc8 Kd6 97. Kd8 Nc7 98. Kc8 Ne6 99. Kb8 Nc5 100. Kc8 Md7+ 101. Kb8 Kc6 102. Ka7 Me6 103. Kb8 Kd7 104. Ka7 Kc7 105. Ka8 Md5 106. Ka7 Mc6 107. Ka8 Nd3 108. Ka7 Nb4 109. Ka8 Mb7+
  10. Ka7 Nc6# {Xboard adjudication: Checkmate} 0-1
alwey commented 5 years ago

@ianfab: FYI: a match of 100 games at 30s+0.3s:

Score of sjaakii (xboard) vs stockfish-cambodian: 0 - 100 - 0 [0.000]
Elo difference: -inf +/- nan, LOS: 0.0 %, DrawRatio: 0.0 %

100 of 100 games finished.

6 Stockfish wins because of a false claim of an illegal move (Neang captures with initial leap) by the opponent, 1 win because of a false repetition claim (Ouk Chatrang has no repetition limit)

ianfab commented 5 years ago

@thaichessswinboard You can now play cambodian chess online against Fairy-Stockfish at https://pychess-variants.herokuapp.com/, see e.g. this test game I played against level 6 (level 6 is not at full strength, level 8 would have won it easily). For offline usage, you need to compile it from the current master branch. If you need help, let me know.

ianfab commented 4 years ago

@thaichessswinboard Referring to your comment https://github.com/thaichessswinboard/Fairy-Stockfish/commit/94bbcffa442cda0cd1d5f1e1a90bb54b1f84f483#commitcomment-36273633, this is the thread where we discussed the rules (including the situation where the queen/neang captures a piece with its leap). If you have new input/sources to clarify the rules where there was some unclarity, please let us know. E.g., are there tournament rules of Ouk that could be used as a reference?

thaichessswinboard commented 4 years ago

This is My code about Fers in Cambodian Chess. That I ask Cambodian people. See attached files please.

Edit: Deleted long code snippet

thaichessswinboard commented 4 years ago

for Cambodian Chess I test with my Engine with your Cambodian Website. IT Draw but My Engine Advancetage more. I will test more and let you know.

https://pychess-variants.herokuapp.com/uCFvh114

thaichessswinboard commented 4 years ago

I test Games 2 level 8 result. My Engine move Black side. It 0-1

https://pychess-variants.herokuapp.com/XTtH4Lse

ianfab commented 4 years ago

@thaichessswinboard Pasting long texts like whole source files or games into comments makes threads hard to read, so please try to only refer to them, e.g., by adding a link to a game (like I edited your comments above) or uploading the PGN file in the comment instead of pasting the content itself. If you would like to share code, please upload it as git commits to github (or at least post a diff/patch), otherwise it is almost impossible for me to work with them, because extracting the code changes from a comment creates a lot of work.

That a locally running engine with sufficient time can defeat level 8 on pychess-variants is not too surprising, since level 8 is limited to 1 second per move and depth 22. Is the engine you used open-source?