0
$\begingroup$

Is it possible to define a 《chess language》: language={alphabet = {(chess pieces, squares of chess board)}, grammar={rules of movement of pieces over the board}}?

I looked online but I cannot find a way to define the grammar. Every way I can think of, is either stupidly long and complicated, or does not cover all the rules.

I presume the hard part is that the grammar has to take in consideration the state of the board before evaluating a move as valid or not.

Do you have insight how to approach this problem i.e: define a grammar that emulates chess rules?

The way chess apps work(not engines), is that at every move they calculate all possible moves and then check if the user's move is among the calculated moves, else it is invalid.

I want to accept the user's move and only then check if it's a valid one.

$\endgroup$
7
  • 2
    $\begingroup$ A grammar is not the way to go. You can write a simple algorithm which checks whether a suggested move is legal. $\endgroup$ Aug 4 '18 at 13:04
  • $\begingroup$ Can you elaborate more please? How to do so without calculating all the possible moves everytime? $\endgroup$ Aug 4 '18 at 18:27
  • $\begingroup$ The first step is to check that the piece moves according to its specific rules, and that there is no other piece in the way. Then other checks are necessary, such as not moving a king in check. Some of the rules also depend on the history, for example en passant and castling, so you will need to maintain a small state as well. $\endgroup$ Aug 4 '18 at 19:44
  • $\begingroup$ By the way, the rules of chess depend on past positions, so a grammar of the form you desire cannot express them. $\endgroup$ Aug 4 '18 at 19:50
  • 1
    $\begingroup$ See the first comment. A grammar is not the way to go. Really, it's not. You will get nowhere trying to use a grammar. $\endgroup$
    – gnasher729
    Aug 5 '18 at 14:45
1
$\begingroup$

"The way chess apps work(not engines), is that at every move they calculate all possible moves and then check if the user's move is among the calculated moves, else it is invalid."

No, no, no, no, that's not how you check if a move is valid.

If you want all possible moves, then you generate all possible moves. If you want to check if a move is valid, then you check if that move is valid, and nothing else. There's no reason to know anything about all the other moves if all you want to know is to check if one move is valid.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.