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
615 stars 192 forks source link

Janggi repetition handling #142

Closed ghost closed 3 years ago

ghost commented 4 years ago

Hello? Developer. I am very grateful for the Fairy Stockfish you created. I'm curious how you set Janggi repetition rules in the latest compilation of Fairy Stockfish. It was valid in Kakao Janggi when you set it to not be repeated more than 3 times. In modern Janggi, such as the current town of Janggi, the rules for a draw or a player with a high score have been eliminated when repetitions occur. If you repeat the same number in the Wiki Korea Janggi Association, you can score the same number only if the total score of each item is less than 30 points, and if you score the same number, it also wins or loses with the score (same number as the number of repetitions) (There is a concept difference in ), so it is a rule that is not applicable in general Janggi.

ianfab commented 4 years ago

The problem with repetition rules in Janggi is that they are not well defined. The rules say that it is prohibited to repeat three times, but in a concrete position this rule is highly subjective and is usually interpreted in the way that chasing pieces of the opponent is prohibited, so the one that forces the repetition is at fault, even if he did not start the repetition.

As long as the room for interpretation is so big, the rule can not be implemented consistently. Therefore, after collecting some feedback I decided to implement a rule that is natural, consistent, and easy to understand: Perpetual check is prohibited, and in all other cases repetitions are adjudicated by material counting (since after endless repetitions the game would finally be adjudicated by material counting anyway). If at a later point a consistent definition of chasing rules for Janggi is available, I can try to add this on top. However, the official Xiangqi rules show how complex the definition of chasing rules can be.

The old implementation only was seemingly working. It implemented the prohibition of repetitions in a very literal sense, so the first player to cause a repetition would lose even if he was forced to do so. This was very difficult to understand and explain, and in some cases it lead to weird behavior of the engine since it tried to exploit this rule by transpositions or intermediate moves.

ianfab commented 4 years ago

Does anyone know if there somewhere is a precise definition of how Kakao determines whether a repetition is illegal?

ghost commented 4 years ago

Hello? Developer. First of all, thank you very much for your development. First, I will explain the concept of the same number and repetition number of Korea Janggi. The same number refers to the act of repeating the same number only on one side, and can be infinite unless it is a jang-gun. The number of repetitions refers to when the number of repetitions from each side comes out, and the person who executed the first repetition in the repetition process must leave a different number unconditionally in the situation of using the repetition number three times because of the regulations that cannot be repeated three or more times. For example, let's say that player A is in prisoner's car in prisoner B, and there is a yarn next to the palace that is straight in that direction. Player B opened his pawn to save the car. Player A moves the sol to the siege. In this situation, if Player B eats the pawn on Player A's gun, Player A can pass the gun forward and place it next to the player B's player to wrap it and catch Player A's car. So player B moves his pawn over the car. If the situation continues to repeat, the B player closes the sol at the time of the repetition first, so the B player needs to put another number at the repetition number of times to get the car caught. In Korea Janggi, the same number can be infinite, and the rule for prohibiting the number of repetitions more than 3 times is common. If the number of repetitions continues, the rule to be a draw or a person with a high score win is the previous 2000year rule. I would be grateful for your reference.

ianfab commented 4 years ago

Thanks. However, this description does not seem to exactly define whether the position or the moves need to repeat three times, whether it has to occur in subsequent moves or whether there can be intermediate moves, and whether the repeat cycle can be more than 4 moves or not. E.g., in the example https://www.pychess.org/jxofROzz the cannon can choose between going back to 29 and 39 (when being on the 59 square), so what happens if Han alternately goes 39->59->29->59->39->...?

ghost commented 4 years ago

Good morning? Developer. Sorry for the inconvenience. I always feel very grateful to the developer. The general Korea Janggi repetition rule is that the same number cannot be repeated more than 3 times. If you get an error when you set the number of repetitions to 3 or more times before, do you have to take into account that the error will occur even if you set it again now? If you play as you set it now, the rule that a draw with a repetition or a person with a high score wins is a very unreasonable rule in the typical modern Janggi, and it has long since disappeared. You can't do it again if there is an error or your skills are lost, but if you can, please return it. The previous setting was valid in Kakao Janggi. However, you do not have to accept this request unconditionally, just for reference. If you have a big influence on the engine's mechanical power or errors, I would appreciate it if you just refer to it. It seems to be because the international and systematic rules of Korean chess have not been made yet. The current setting is also a pretty good one. Developers, thank you for your great response to my suggestions. In the future, I would like to thank you for your hard work.

ianfab commented 4 years ago

There is no problem with this rule in itself, it would still work, the issue is that it is not well-defined. As long as I do not have a clear algorithmic definition of when to prohibit repetition, it can at best by coincidence somehow match the behavior in Kakao in most cases. As a compromise I can re-enable the old behavior for the "janggimodern" variant, since that should be the one that can be used for Kakao. However, it would still be nice to know how repetition detection exactly works in Kakao.

If you want to support my work, contributions are always welcome.

cjssh1002 commented 4 years ago

I opened the issue. Let's discuss the problem together here. I am "Janggi korea"

https://github.com/gaintpd/cutechess/issues

HGMuller commented 4 years ago

Note I just added Janggi as a new standard variant to XBoard/WinBoard. I don't really favor the principle of standard variants, compared to engines defining the rules through selecting generally supported rule aspects. But Janggi has a number of very idiosyncratic rules (such as the topologically inhomogeneous board) that need support and would never be used in any other game. Besides, it is one of the world's major versions of chess, so it made sense to make an exception for it. So I added a 'variant janggi'.

For now I only implemented the piece moves; adjudications, including mate detection, probably won't work and should be switched off. That also applies to the Bikjang rule. I did not forbid Kings to face each other, but there are no consequences when they do. I also did not allow turn passing; it is not clear to me how this rule works, so stalemate would probably be adjudicated as a draw. If turn passing is only allowed when stalemated, it can be automatic, and would not need any user interface. How does Stockfish handle this?

It seems to me this game is very drawish; because of Bikjang and turn passing not even a Rook can force checkmate.

ianfab commented 4 years ago

Thanks for starting to explicitly support Janggi. In my experience, in principle Janggi mostly works fine as an engine defined variant, apart from a few details:

Passing is always allowed in Janggi except when in check(-mate). When playing with bikjang, passing is however even allowed when in check and bikjang. In tournament play draws are non-existent in Janggi, because draws (bikjang, insufficient material) are adjudicated via material as a tie-breaker, and a normal win counts as 7-0, while winning with a tie-break counts as 4-2.

HGMuller commented 4 years ago

Points 1 and 2 should be solved now when playing this as a standard variant. XBoard now has all the moves hard-coded.

I don't understand point 3. CECP prescribes the use of @@@@ in engine-GUI communication. 'pass' is basically a SAN notation. (But XBoard does understand SAN also from an engine, as it uses the same move parser whatever the source.) e1e1 is not a valid encoding for a turn pass, and it should never be generated by a GUI, nor by a CECP engine.