alexobviously / bishop

A chess logic package for Dart with flexible variant support
https://pub.dev/packages/bishop
Other
19 stars 8 forks source link

BUG Grand Chess: A pawn can only turn into a picked up piece #12

Closed malaschitz closed 1 year ago

malaschitz commented 1 year ago

There are actually two errors here:

  1. The pawn can only promote into a picked up piece.
  2. The pawn does not have to be knocked on the 8th rank. It can move to 8 or 9 rank without promoting. It must be transformed on row 10.

Wikipedia: A pawn that reaches a player's eighth or ninth ranks can elect to either promote or remain a pawn, but it must promote upon reaching the tenth rank. Unlike standard chess, a pawn may be promoted only to a captured piece of the same colour. (So, it is impossible for either side to own two queens, or two marshals, or three rooks, etc.) If, and for as long as, no captured piece is available to promote to, a pawn on a player's ninth rank must stay on the ninth rank, but it can still give [check](https://en.wikipedia.org/wiki/Check(chess))._

Problem 1 I can probably fix, but problem 2 probably requires some new parameter for Variant (or change promotion to enum) ?

malaschitz commented 1 year ago

Problem 2 is not a problem of library bishop. It is problem of square or square_bishop. I have created a test https://github.com/malaschitz/bishop/blob/master/test/grand_test.dart and it is correctly generated move f7e8 without promotion.

malaschitz commented 1 year ago

There are two problems here. The first is that in the GrandChess variant only the conversion of a pawn to an already taken piece should be generated. I've made a fix at https://github.com/malaschitz/bishop/commit/37c5e0ff3b1f4d65b9374248724bf0e4d1858451 but it's just such a nasty workaround. Probably it should be made that the variant is promotion enum, and has a third option and that is conversion to already taken pieces. At the same time, Game.state should maintain what is already taken (some chess servers do this as well, showing discarded pieces in addition to the chess board). But he didn't want to change the promotion and state.hands properties without the library author.

Moreover, maybe the solution is incorrect, because for shogi it is often the case that some stones change to other stones. Perhaps the simplest solution would be if the variant had a method that, for a particular move and game, returned a list of possible promotion moves. GrandChess would have it implemented differently.

The second problem, is in the square library - the solution is here: https://github.com/malaschitz/squares/commit/5f84857011eec415007e1c49f44f91ac0d7e1703 - it will add a null piece in the specific case.

alexobviously commented 1 year ago

Okay so I think for this I'm going to basically do something like your suggestion: a function in the variant that returns possible promotion pieces given the current state of the game, which can be overridden.

The squares component (missing no-promo option in grand chess on 8th and 9th ranks) is fixed in 1.1.2 https://github.com/alexobviously/squares/commit/94e02176417183567c0a328331be59894b07f071

alexobviously commented 1 year ago

Fixed in https://github.com/alexobviously/bishop/commit/bd71ef9f008eca02190acec775f029ac002600a8 as part of #26

@malaschitz would you mind having a quick look and checking if this fulfills all the requirements of grand chess as you understand them? Just run the development branch. I wrote some tests but maybe you can think of cases they don't cover.

btw this solution doesn't exactly 'track' captured pieces - instead it compares the number of pieces present (available in BishopState.pieces) to a limit defined for the variant.

I also wrote a lot of other logic that should cover Shogi and similar when that's added.

Closing this issue but if you find a fault just comment here and I'll reopen.