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

immobilityIllegal not Working Properly #521

Closed PraseodymiumSpike closed 1 year ago

PraseodymiumSpike commented 2 years ago

[cannonshogi:shogi]

shogiPawn = - soldier = p dropNoDoubled = - cannon = u janggiCannon = a customPiece1 = c:mBcpB customPiece2 = i:pB customPiece3 = w:RpRFpA customPiece4 = f:BpBWpD promotedPieceType = u:w a:w c:f i:f startFen = lnsgkgsnl/1rci1uab1/p1p1p1p1p/9/9/9/P1P1P1P1P/1BAU1ICR1/LNSGKGSNL

does not allow 1. I-75 despite the Iron cannon not being immobile in that position (or any position, for that matter, as it can move in any diagonal direction)

PraseodymiumSpike commented 2 years ago

I propose that shogiStyleImmobilityIllegal be added which would follow the following rules to better represent shogi variants' rules:

  1. It should only make a move completely illegal in the case of drops.
  2. It should instead automatically promote the piece if possible in the case of a non-drop move; if promotion is not possible, the move should simply be allowed despite it resulting in the piece being immobile (in shogi, promotion is always possible in such a case).
  3. Only the edge of the board should count as an obstruction for immobility checks. Other pieces should not count.
  4. For hopping-only pieces, automatic promotions and drop bans should also occur on squares where hopping over a piece, no matter how close, in between would result in the end of the board being reached. For example, imagine a piece similar to a cannon from janggi but that can only hop straight backwards, completely unable to move or capture in any other direction. If shogiStyleImmobilityIllegal were set to true, it would be illegal to drop such a piece on the first or second rank. Why would it be illegal to drop it on the second rank? It's simple. A piece for it to hop over would need to be on the first rank, but then, there would be no rank for it to actually hop to! As such, it would also be forced to promote if possible upon moving to the second rank. Of course, it could be dropped on the third rank regardless of if there was actually a piece on the second rank under the assumption that there may be a piece there in the future. Of course, there are no hoppers in shogi, but I think that this is a reasonable extrapolation.
ianfab commented 2 years ago

FYI, I transferred the issue to the Fairy-SF repository, because the game rule logic in all Fairy-SF dependent projects (such as fairyground, fairyfishgui, liground, as well as pychess) uses the Fairy-SF code, so such issues need to be addressed here. I will have a look at a later point. I already pushed some experimental code yesterday related to this: https://github.com/ianfab/Fairy-Stockfish/tree/permanent_immobility