Answers.Body: <p>For queens, bishops and rooks moving from square A to square B there is only one way that move can be made and all the squares in between must be empty for that move to be legal.</p>
  <p>For a knight moving from square A to square there are generally two ways but that is irrelevant because knights can jump over pieces in the way.</p>
  <p>For castling there is only one way the king can move from A to B and the intervening square must be empty for that move to be legal and the king must be moved first. For castling there is only one way the rook can move from A to B and all the squares in between must be empty apart from the king for that move to be legal.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-12-05T21:59:44.660Z
Answers.Text: so it means, i can safely assume that if there has been a move from position A to position B then there is only one way to do so regardless of piece.The intermediate positions, used in moving from A to B by a piece will be same regardless of piece,say A->X->Y->B, then regardless of piece, the intermediate positions from A to B remain X and Y in sequence?
Answers.UserDisplayName: rahul sharma
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-12-05T22:12:52.393Z
Answers.Text: @rahulsharma If a piece moves A->X->Y->B then that is 3 moves not 1. It is A->X then X->Y then Y->B. If a piece moves from A to B in one move then at the start of the move it is on square A then it is picked up and placed on square B. The piece never occupies any of the squares in between but for pieces other than knights those intervening squares must be empty otherwise the move is blocked and cannot be made.
Answers.UserDisplayName: Brian Towers
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-12-05T22:33:33.433Z
Answers.Text: yes i agree, I will give you a little context here. There is one part of my game that will just tell me that move is allowed by piece X from  A to B. Now once i got confirmation , i need to make sure that in the path from A to B, there should be no other piece. The problem here is that once i got confirmation, I dont have access to the piece now(the way it is done as of now). So now i will generate path from A to B and check that all intermediate squares should be empty.So i got here like will there be always unique path regardless from A to B if i dont have access to piece that made this move
Answers.UserDisplayName: rahul sharma
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-12-06T08:30:24.907Z
Answers.Text: 1/2: @rahulsharma it that case indeed, there is only one way to do this. But I think you might want to clarify your question to explain what exactly you are planning to do, then people can give better answers. "tell me that move is allowed", what tells you that a move is allowed? Presumably some move generator, i.e. a function that returns legal moves? Legality checking should happen in that function. Then for instance you don't check each origin-destination pair independently but many at once. E.g. you check can the queen move one square in this direction? Yes, then that's a legal move.
Answers.UserDisplayName: koedem
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-12-06T08:33:03.710Z
Answers.Text: 2/2: Was that first generated move not a capture and is two squares into that direction not a friendly piece? Then that move is legal too, since the first move not being a capture means the previous square was empty. Now was the previous generated move not a capture and the square three into that direction is not a friendly piece? Then this is a legal move too. As you can see you can use the previous generated moves to help generate new ones. (sorry for the not so clear explanation, it's hard in a comment :D )
Answers.UserDisplayName: koedem
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-12-06T09:26:14.497Z
Answers.Text: @BrianTowers Under FIDE rules (I am not familiar with USCF rules), when castling, the first *touch* (done with the intention of moving) must be on the king. The actual moves may then be done in any order. In particular, it is legal to move the rook to its final square first, then move the king over a square that is no longer empty.
Answers.UserDisplayName: Brian Drake
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-12-06T13:11:24.310Z
Answers.Text: i have update code to give more idea about what i am trying to do
Answers.UserDisplayName: rahul sharma
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-12-07T03:40:02.020Z
Answers.Text: @BrianTowers I think that what they are sayin is that if a queen moves from a1 to a4, they are treating that as moving a1->a2->a3->a4, and checking whether each move is legal.
Answers.UserDisplayName: Acccumulation
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-12-05T21:55:07.793Z
Answers.LastActivityDate: 2020-12-05T21:55:07.793Z
Answers.UserDisplayName: Brian Towers
Answers.Body: <p>No. It's a matter of taste how the knight travels from the start square to the end square, but nothing is written on how it gets to the final square. The same for castling, of how the rook arrives at the destination square, since it has to get there by moving past the king that's just made a two square move.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-12-05T21:42:51.617Z
Answers.LastActivityDate: 2020-12-05T21:42:51.617Z
Answers.UserDisplayName: MikeD
Answers.Body: <p>The special cases to consider are knight moves, castling, and pawn moves. Knights don't really have a path; you can think of them as teleporting to their destination. Pawns and castling have to follow the same restrictions on moving through occupied squares (they have same squares they &quot;go through&quot; as any other material with the same source and destination squares), but also have additional restrictions. Whenever a king moves other than castling, it doesn't &quot;go through&quot; any squares, so your question doesn't really appy.</p>
  <p>Every other move is either a rook move or a bishop move. Whenever a queen moves, it makes either a rook move or a bishop move. When a queen makes a bishop move, it follows the same rules as moving a bishop, and the path it takes is the same as a bishop. When it makes a rook move, it follows the same rules as a rook (other than the aforementioned castling).</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-12-07T04:04:45.503Z
Answers.LastActivityDate: 2020-12-07T04:04:45.503Z
Answers.UserDisplayName: Acccumulation
Answers.Body: <p>For pieces which are not the knight, there indeed is only one path to check. For rook, bishop and queen you trace out a &quot;ray&quot;, a king only moves one square and the knight does not care about other pieces being in the way so there the path does not matter. So to check you would have to verify that the destination square is not a friendly piece (as you can't capture friendly pieces) and for the ray moving pieces that all squares in between are empty.</p>
  <p>The pawn of course is a special case since it captures differently than it moves, I hope you are aware of that. :) (and it has further complications like the double step and en passant rule)</p>
  <p>NOTE: For a move to be legal the moving player must not be in check after the move. So you also have to verify that. One possible way to do that is pretend that the king of the moving player is a rook and see if it could capture an enemy rook, then that enemy rook is in fact giving check. (same for the other pieces and of course be careful with the pawns once again)</p>
  <p>I will also note that I would implement this a lot differently but I assume it's a learning project, so should be fine.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-12-07T18:58:27.073Z
Answers.LastActivityDate: 2020-12-07T18:58:27.073Z
Answers.UserDisplayName: koedem
Body: <p>I am implementing a chess game. I am aware of the rules but I have not played it much. I need clarification on a small point.</p>
  <p>Suppose a player legally moves a piece from square A to square B. Consider the path this piece followed during this move. Can it be different based on the type of piece?</p>
  <p>I am not able to find such a case.</p>
  <p>Edit :- I am adding the interface code that I am dealing with to make it more clear as asked by some people to give more context.</p>
  <pre><code>public class Chess {
  
      ChessBoard chessBoard;
      Player[] player;
      Player currentPlayer;
      List&lt;Move&gt; movesList;
      GameStatus gameStatus;
  
      public boolean playerMove(CellPosition fromPosition, CellPositionb toPosition, Piece piece); 
      public boolean endGame();
      private void changeTurn();
  
  }
  public abstract class Piece {
  
  Color color;
  public boolean validate(CellPosition fromPosition, CellPositionb toPosition);
  }
  
  public class Knight extends Piece {
  public boolean validate(CellPosition fromPosition, CellPositionb toPosition);
  
  }
  </code></pre>
  <p>Similarly there will be classes for other pieces as Knight. Now if a player want to move in chess from some position X to another position Y, the validate() method of the Piece will be called by playerMove() of chess,validate() can only check whether the move is valid or not.Like for the given pieces,say knight, it will check that from given location,the destination is one of 8 valid moves.For Rook it can be any one of four directions and so on.</p>
  <p>The playerMove() function makes a call the the Piece.validate() function and then it gets to know that it is a valid move.The problem that I am trying to address, now once playerMove function in chess, knows that it is valid move, it does not know that whether there is any piece in between from given location to destination?Because the piece dont have context of Board,it cannot detect it thing and it has to be done in playerMove() function of chess.So i will write a code here to generate the list of possible squares that are involved from source to destination. Will that list of squares will always be unique ?or can it be different for diffeent piece? Because apart from knight ,all moves in straight or diagonal so it should be unique ,so I want to clarify on this .If still question not clear, please let me know.but</p>
  
Tags: <rules><software>
Title: Can pieces follow different paths from one square to another in a single move?
ThreadText: # Can pieces follow different paths from one square to another in a single move?
  
  (Asked by: username_0 on 2020-12-05)
  
  I am implementing a chess game. I am aware of the rules but I have not played it much. I need clarification on a small point.
  Suppose a player legally moves a piece from square A to square B. Consider the path this piece followed during this move. Can it be different based on the type of piece?
  I am not able to find such a case.
  Edit :- I am adding the interface code that I am dealing with to make it more clear as asked by some people to give more context.
  public class Chess {
  
      ChessBoard chessBoard;
      Player[] player;
      Player currentPlayer;
      List movesList;
      GameStatus gameStatus;
  
      public boolean playerMove(CellPosition fromPosition, CellPositionb toPosition, Piece piece); 
      public boolean endGame();
      private void changeTurn();
  
  }
  public abstract class Piece {
  
  Color color;
  public boolean validate(CellPosition fromPosition, CellPositionb toPosition);
  }
  
  public class Knight extends Piece {
  public boolean validate(CellPosition fromPosition, CellPositionb toPosition);
  
  }
  
  Similarly there will be classes for other pieces as Knight. Now if a player want to move in chess from some position X to another position Y, the validate() method of the Piece will be called by playerMove() of chess,validate() can only check whether the move is valid or not.Like for the given pieces,say knight, it will check that from given location,the destination is one of 8 valid moves.For Rook it can be any one of four directions and so on.
  The playerMove() function makes a call the the Piece.validate() function and then it gets to know that it is a valid move.The problem that I am trying to address, now once playerMove function in chess, knows that it is valid move, it does not know that whether there is any piece in between from given location to destination?Because the piece dont have context of Board,it cannot detect it thing and it has to be done in playerMove() function of chess.So i will write a code here to generate the list of possible squares that are involved from source to destination. Will that list of squares will always be unique ?or can it be different for diffeent piece? Because apart from knight ,all moves in straight or diagonal so it should be unique ,so I want to clarify on this .If still question not clear, please let me know.but
  
  **Tags:** rules, software
  
  
  ---
  
  ## 4 answers
  
  ### Answer by username_1 on 2020-12-05. Score: 4
  
  For queens, bishops and rooks moving from square A to square B there is only one way that move can be made and all the squares in between must be empty for that move to be legal.
  
  For a knight moving from square A to square there are generally two ways but that is irrelevant because knights can jump over pieces in the way.
  
  For castling there is only one way the king can move from A to B and the intervening square must be empty for that move to be legal and the king must be moved first. For castling there is only one way the rook can move from A to B and all the squares in between must be empty apart from the king for that move to be legal.
  
  > **Comments:**
  > **username_0**: so it means, i can safely assume that if there has been a move from position A to position B then there is only one way to do so regardless of piece.The intermediate positions, used in moving from A to B by a piece will be same regardless of piece,say A->X->Y->B, then regardless of piece, the intermediate positions from A to B remain X and Y in sequence?  
  > **username_1**: @rahulsharma If a piece moves A->X->Y->B then that is 3 moves not 1. It is A->X then X->Y then Y->B. If a piece moves from A to B in one move then at the start of the move it is on square A then it is picked up and placed on square B. The piece never occupies any of the squares in between but for pieces other than knights those intervening squares must be empty otherwise the move is blocked and cannot be made.  
  > **username_0**: yes i agree, I will give you a little context here. There is one part of my game that will just tell me that move is allowed by piece X from  A to B. Now once i got confirmation , i need to make sure that in the path from A to B, there should be no other piece. The problem here is that once i got confirmation, I dont have access to the piece now(the way it is done as of now). So now i will generate path from A to B and check that all intermediate squares should be empty.So i got here like will there be always unique path regardless from A to B if i dont have access to piece that made this move  
  > **username_2**: 1/2: @rahulsharma it that case indeed, there is only one way to do this. But I think you might want to clarify your question to explain what exactly you are planning to do, then people can give better answers. "tell me that move is allowed", what tells you that a move is allowed? Presumably some move generator, i.e. a function that returns legal moves? Legality checking should happen in that function. Then for instance you don't check each origin-destination pair independently but many at once. E.g. you check can the queen move one square in this direction? Yes, then that's a legal move.  
  > **username_2**: 2/2: Was that first generated move not a capture and is two squares into that direction not a friendly piece? Then that move is legal too, since the first move not being a capture means the previous square was empty. Now was the previous generated move not a capture and the square three into that direction is not a friendly piece? Then this is a legal move too. As you can see you can use the previous generated moves to help generate new ones. (sorry for the not so clear explanation, it's hard in a comment :D )  
  > **username_3**: @BrianTowers Under FIDE rules (I am not familiar with USCF rules), when castling, the first *touch* (done with the intention of moving) must be on the king. The actual moves may then be done in any order. In particular, it is legal to move the rook to its final square first, then move the king over a square that is no longer empty.  
  > **username_0**: i have update code to give more idea about what i am trying to do  
  > **username_4**: @BrianTowers I think that what they are sayin is that if a queen moves from a1 to a4, they are treating that as moving a1->a2->a3->a4, and checking whether each move is legal.  
  
  ---
  
  ### Answer by username_5 on 2020-12-05. Score: 3
  
  No. It's a matter of taste how the knight travels from the start square to the end square, but nothing is written on how it gets to the final square. The same for castling, of how the rook arrives at the destination square, since it has to get there by moving past the king that's just made a two square move.
  
  
  ---
  
  ### Answer by username_4 on 2020-12-07. Score: 1
  
  The special cases to consider are knight moves, castling, and pawn moves. Knights don't really have a path; you can think of them as teleporting to their destination. Pawns and castling have to follow the same restrictions on moving through occupied squares (they have same squares they "go through" as any other material with the same source and destination squares), but also have additional restrictions. Whenever a king moves other than castling, it doesn't "go through" any squares, so your question doesn't really appy.
  
  Every other move is either a rook move or a bishop move. Whenever a queen moves, it makes either a rook move or a bishop move. When a queen makes a bishop move, it follows the same rules as moving a bishop, and the path it takes is the same as a bishop. When it makes a rook move, it follows the same rules as a rook (other than the aforementioned castling).
  
  
  ---
  
  ### Answer by username_2 on 2020-12-07. Score: 0
  
  For pieces which are not the knight, there indeed is only one path to check. For rook, bishop and queen you trace out a "ray", a king only moves one square and the knight does not care about other pieces being in the way so there the path does not matter. So to check you would have to verify that the destination square is not a friendly piece (as you can't capture friendly pieces) and for the ray moving pieces that all squares in between are empty.
  
  The pawn of course is a special case since it captures differently than it moves, I hope you are aware of that. :) (and it has further complications like the double step and en passant rule)
  
  NOTE: For a move to be legal the moving player must not be in check after the move. So you also have to verify that. One possible way to do that is pretend that the king of the moving player is a rook and see if it could capture an enemy rook, then that enemy rook is in fact giving check. (same for the other pieces and of course be careful with the pawns once again)
  
  I will also note that I would implement this a lot differently but I assume it's a learning project, so should be fine.
  
  
  ---
  
  