WandererXII / lishogi

☗ lishogi.org: the forever free, adless and open source shogi server forked from lichess.org ☗
https://lishogi.org
GNU Affero General Public License v3.0
261 stars 40 forks source link

Chu Shogi counter-strike not being invoked when a Lion is locust-captured and the final destination is not a Lion square #830

Closed amdewitt closed 3 weeks ago

amdewitt commented 2 months ago

Explanation - This is due to the code not preserving the counter-strike square after the second Lion move if it moves the moving piece to another square that is not a Lion square.

To fix, simply add a block of code that preserves the counter-strike square even if the victim on the second square is not a Lion.

Your best bet for reproduction is https://lishogi.org/analysis/chushogi

This is an implementaton bug, which can be seen at the Chu Shogi Analysis board or when playing Chu Shogi on Lishogi.

Steps to reproduce the bug I. I have prepared an example position with the help of Github user maconard. Put the following FEN Code in the Chu Shogi Analysis Board:

lfcsgekgscfl/a1b1txot1b1a/mvrhdqn1hrvm/ppppp+Dp1pppp/3i3pi3/12/12/3IP3I3/PPPP1P+dPPPPP/MVRH1NQDHRVM/A1B1TOXT1B1A/LFCSGKEGSCFL b - 9

II. Capture White's Lion with Black's Soaring Eagle, then move the just-moved Eagle to another square (the bug will not occur if it stops on the spot) III. Select White's Eagle or Queen on rank i. You should see that a capture of Black's Lion is possible even though a Lion was just captured on the last turn.

More explicitly, from position: lfcsgekgscfl/a1b1txot1b1a/mvrhdqn1hrvm/ppppp+Dp1pppp/3i3pi3/12/12/3IP3I3/PPPP1P+dPPPPP/MVRH1NQDHRVM/A1B1TOXT1B1A/LFCSGKEGSCFL b - 9

After taking the opponent's lion with 7d6c (non-double move), Lion counterstrike on the next turn is prevented

Expected Outcome - After taking the opponent's lion with 7d6c7d (igui double move) or 7d6c5b (hit and run double move), Lion counterstrike on the next turn is not allowed

What happened instead? - After taking the opponent's lion with 7d6c7d (igui double move) or 7d6c5b (hit and run double move), Lion counterstrike on the next turn is allowed

However, none of these three captures should be permitted.

Note that if the second part of a Lion move captures two Lions simultaneously, the bug does not occur. For example in this position if a Horned Falcon captures two Lions at once the bug does not occur:

lfcsgekgscfl/a1b1tx1t1b1a/mvr1dqndhrvm/pppp1p+oppppp/4p1+H1i3/12/12/3I1+h1P4/PPPPP+OP1PPPP/MVRHDNQD1RVM/A1B1T1XT1B1A/LFCSGKEGSCFL b - 2

Note: I asked H. G. Muller (Author of HaChu) via the CVP Comments what he thought since he was an authority on the subject I could reach out to personally. He said that the general consensus among players, the historical sources, and all the authorities on the subject, including the Chu Shogi Renmei, is that the term "non-Lion" means a piece type, not a move type. This means that in the situation given above, the counter-strike rule should be invoked regardless of where Black's Eagle ends up.

Operating system and browser version: Any that supports Chu Shogi

Soaring Eagle Counter-Strike

Soaring Eagle Counter-Strike-2

daxx00 commented 2 months ago

I was able to duplicate the implementation error. After a lion is captured in the first step of a double-move by a falcon or eagle, lishogi currently allows immediate capture of a lion (by a non-lion) in return, which should not happen. I tested multiple non-lion piece types, and all were able to complete the erroneous capture.

maconard commented 2 months ago

More explicitly, from position: lfcsgekgscfl/a1b1txot1b1a/mvrhdqn1hrvm/ppppp+Dp1pppp/3i3pi3/12/12/3IP3I3/PPPP1P+dPPPPP/MVRH1NQDHRVM/A1B1TOXT1B1A/LFCSGKEGSCFL b - 9

However, none of these three captures should be permitted.

amdewitt commented 2 months ago

Note that if you capture two lions at once, the bug will not occur. I have added screenshots and the appropriate FEN for this.

maconard commented 2 months ago

Pull request to fix this issue submitted here: https://github.com/WandererXII/shogiops/pull/8

WandererXII commented 1 month ago

Applying the fix would mean the games where the illegal move occurred will get cut off at that move, this will affect old games and also currently played ones. Is this something I should try to remedy?

daxx00 commented 1 month ago

Applying the fix would mean the games where the illegal move occurred will get cut off at that move, this will affect old games and also currently played ones. Is this something I should try to remedy?

It's highly unlikely even a single game will be affected. The odds someone managed to promote a falcon/eagle, (in all likelihood) captured a piece next to a lion with it where the double-step threat would be applicable, the opponent not knowing the lion rules and in a position to counterattack the lion (and doing so instead of just taking the falcon/eagle)... It'll be fine.

amdewitt commented 1 month ago

I concur with daxx00.

WandererXII commented 3 weeks ago

Thank you for the detailed bug report, the fix is live now. If you find any other bug, please let me know!

amdewitt commented 3 weeks ago

I did find a bug involving the counter-strike rule not being invoked on the second part of a multi-move. I have posted a separate issue to explain, which is Issue #846.