trevorbayless / cli-chess

A highly customizable way to play chess in your terminal. Play online (via Lichess.org) and offline against the Fairy-Stockfish engine. All Lichess variants are supported.
GNU General Public License v3.0
190 stars 6 forks source link

Premoves #27

Closed valeratrades closed 5 months ago

valeratrades commented 11 months ago

What feature would you like to see in cli-chess?

Rather a big topic, so let's discuss:

My thinking was to append all moves entered out of turn into a premove table, which is then shown in the bottom right corner. Then attempted to be played automatically when the turn comes. Esc to clear.

Of course, the correct way would be to also mark them with say red on the board, and then check validity of every appended premove with the position of the pieces after the previous premove. But seems like this can be just added later.

If that is in line with your vision, happy to contribute the first part.

trevorbayless commented 11 months ago

I like the idea, but I think it should be limited to one pre-move at this time. Supporting one pre-move will align with Lichess, as well as reduce complication. I'd be happy to review any PR you put out for it!

LKL1235 commented 6 months ago

I would like push this issue but it's seem not function to verify premove legality in python-chess lib? I still dont find a way to verify the next move legality or parse the sort move (e.g.'a4') to chess.move. If there are any way to verify you can tell me and i will finish this part. @valeratrades @trevorbayless

trevorbayless commented 6 months ago

Correct, python-chess does not have any native premove capability. It would be a little involved (and this is just a high level overview to be followed with a grain of salt) but you should be able to store the premove in a custom temporary move list which is checked at the start of your turn. You can validate the move using validate_move in board_model.py but this function would require some tweaking to bypass the move exceptions if invalid. Then if valid, call make_move. There should also be a way from the UI to clear the premove.

LKL1235 commented 6 months ago

Correct, python-chess does not have any native premove capability. It would be a little involved (and this is just a high level overview to be followed with a grain of salt) but you should be able to store the premove in a custom temporary move list which is checked at the start of your turn. You can validate the move using validate_move in board_model.py but this function would require some tweaking to bypass the move exceptions if invalid. Then if valid, call make_move. There should also be a way from the UI to clear the premove.

Yeah, you provided a great idea but if don't validate input content legality when user input, there will There are a lot of crazy inputs, like a8#Q At the beginning of the game. So, I tried copy a board when premove input, use a blink move to change the turn, then I can use the new board to verify the premove input. But, I can't verify the complex premove like take premove e.g. cxd4 when d4 e5 c3. If there some way to handle these situation please tell me.

trevorbayless commented 5 months ago

Closed by #29