Answers.Body: <p>Well, you could generate all possible positions, and draw arrows between two positions A and B, if B can be reached from A in a single move.</p>
  <p>Then use Dijkstra to see whether there is a finite-length path between the starting position, and the position you want to determine whether it is illegal or not.</p>
  <p>But that's just a theoretical exercise. The shear amount of possible positions makes this unfeasible to use this in practice.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-12-08T00:32:54.470Z
Answers.LastActivityDate: 2023-12-08T00:32:54.470Z
Answers.UserDisplayName: Abigail
Body: <p>There are many positions in chess that are illegal in the sense that they cannot be reached by legal moves.</p>
  <p>Is there an algorithm to detect if a position is illegal or not?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-12-05T10:57:17.837Z
Comments.Text: If you do a search I think you may find that this has been asked before.
Comments.UserDisplayName: Brian Towers
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-12-06T08:38:16.387Z
Comments.Text: There is no general algorithm, however quite some illegal positions can be identified. I think most recent work in this field was done through this project: https://github.com/tromp/ChessPositionRanking , goal of which was determining number of legal positions.
Comments.UserDisplayName: Matija Sirk
Tags: <illegal-move>
Title: How to detect an illegal position?
ThreadText: # How to detect an illegal position?
  
  (Asked by: username_0 on 2023-12-05)
  
  There are many positions in chess that are illegal in the sense that they cannot be reached by legal moves.
  
  Is there an algorithm to detect if a position is illegal or not?
  
  **Tags:** illegal-move
  
  > **Comments:**
  > **username_1**: If you do a search I think you may find that this has been asked before.  
  > **username_2**: There is no general algorithm, however quite some illegal positions can be identified. I think most recent work in this field was done through this project: https://github.com/tromp/ChessPositionRanking , goal of which was determining number of legal positions.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_3 on 2023-12-08. Score: 0
  
  Well, you could generate all possible positions, and draw arrows between two positions A and B, if B can be reached from A in a single move.
  
  Then use Dijkstra to see whether there is a finite-length path between the starting position, and the position you want to determine whether it is illegal or not.
  
  But that's just a theoretical exercise. The shear amount of possible positions makes this unfeasible to use this in practice.
  
  
  ---
  
  