Answers.Body: <p>FEN is fine for unambiguous communication of a position (if you include castling and e.p. state too) but the internal representation should be as a board, with some kind of movement so you can efficiently check for legal moves, blocks, checks etc. Would hate to do all that with regex!</p>
  <p>This quite a well-travelled area, and there must be much material online. You have made the choice to use Haskell here: what is the motivation for this? Are you trying to learn Haskell, or do you think it’s appropriate for certain aspects of a chess engine.</p>
  <p>Chess is a finite directed binary graph, with each position just a node. There is certain machinery to reach that level of abstraction, but ultimately I would think a functional language like Haskell might really begin to show its worth when you have reached that conceptual level.</p>
  <p>Depends also what you want your engine to do: find good moves, solve problems, analyse endgames, tablebases, retrograde analysis, support fairy chess. So please say more! :)</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-02-16T07:48:56.580Z
Answers.Text: First of all thanks for the answer ;) What I'm trying to describe here is only a part of the engine, which is only supposed to handle the computing of possible/legal moves for a given player/game state. I should also mention that I'm implementing here a slightly different version of chess(Crazyhouse) with no castling or en passant capturing. As to why I've decided on Haskell, the main requirement of the project is that I do this functionally, so there really isn't much wiggle room there :)
Answers.UserDisplayName: httplease
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-02-16T09:13:36.480Z
Answers.Text: Hi httplease thanks for the classification. Leaving castling & en passant out for the first pass seems like a sensible approach, but you may want to leave the conceptual hooks in to add them later if necessary. The notion of state is even more essential to crazyhouse because each player has a handful of pieces to throw onto the board at any point. The main thing that strikes me about crazyhouse is that you can easily have 200 legal moves, most of which are trivially legal (unless there is a check). Orthodox chess is the hardest subset: might as well do that before adding the crazy stuff, imho
Answers.UserDisplayName: Laska
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-02-16T10:51:53.270Z
Answers.Text: That's true, I didn't realize that the extra moves(due to the crazyhouse concept) would add that much to the complexity.
Answers.UserDisplayName: httplease
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-02-16T04:44:54.780Z
Answers.LastActivityDate: 2021-02-16T05:34:12.477Z
Answers.LastEditDate: 2021-02-16T05:34:12.477Z
Answers.UserDisplayName: Laska
Body: <p>I'm trying to implement a function in Haskell that returns a list containing all possible moves for the player who's up. The function's only argument is a String composed of an actual state of the board (in <a href="https://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation" rel="nofollow noreferrer">Forsyth-Edwards Notation</a>) followed by the moving player(b/w).</p>
  <p>Notation example : rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w (starting board state)</p>
  <p>So far I used a function to split the string into ranks, but I'm having a hard time coming up with an implementation.</p>
  <p>Any tips?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-02-15T23:32:46.103Z
Comments.Text: Are you asking for specifically Haskell tips, or just general implementation tips? Naively, I would first create a function taking as input a piece type, coordinate and colour and outputting the "target" coordinates to which it can move, along with the coordinates traversed along the route. Input the FEN notation into a matrix of 1s for occupied cells and 0s for empty ones. Then loop over the players' pieces, calling this function and ruling out those "target" coordinates for which one of the cells "en route" is occupied (i.e has a 1 in the matrix).
Comments.UserDisplayName: Mark Butler
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-02-15T23:32:48.703Z
Comments.Text: You'll have to deal with a lot of cases separately - pawns capturing diagonally, en passant, castling (and no castling when under attack), checks and checkmates etc.
Comments.UserDisplayName: Mark Butler
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-02-16T08:02:42.253Z
Comments.Text: I was mainly asking for general tips, and this actually looks like a good place to start. Fyi this is a slightly simplified version of chess, so I don't have to tackle castling or en passant.
Comments.UserDisplayName: httplease
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-02-16T11:22:14.367Z
Comments.Text: This is an open-ended question, but that's why OP has posed it. Not all questions are factual. If OP had more "focus", the question would not need to be asked. There is certainly enough here to begin a useful dialogue, and I think the discussion already might be useful to others. The all-too-familiar knee-jerk closing of a perfectly ok question is unhelpful and is also unwelcoming to the a newcomer.
Comments.UserDisplayName: Laska
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-02-19T22:42:15.250Z
Comments.Text: @httplease to add to my comment, you might find this recent YouTube video "coding a Chess AI" very useful. It begins with a relatively sensible approach to listing legal moves. Implementation is Python not Haskell, but it is written functionally so should translate.
Comments.UserDisplayName: Mark Butler
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-02-19T22:42:21.280Z
Comments.Text: https://www.youtube.com/watch?v=U4ogK0MIzqk&ab_channel=SebastianLague
Comments.UserDisplayName: Mark Butler
Tags: <software><computer-chess>
Title: List possible moves for player - Haskell implementation
ThreadText: # List possible moves for player - Haskell implementation
  
  (Asked by: username_0 on 2021-02-15)
  
  I'm trying to implement a function in Haskell that returns a list containing all possible moves for the player who's up. The function's only argument is a String composed of an actual state of the board (in [Forsyth-Edwards Notation](https://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation)) followed by the moving player(b/w).
  
  Notation example : rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w (starting board state)
  
  So far I used a function to split the string into ranks, but I'm having a hard time coming up with an implementation.
  
  Any tips?
  
  **Tags:** software, computer-chess
  
  > **Comments:**
  > **username_1**: Are you asking for specifically Haskell tips, or just general implementation tips? Naively, I would first create a function taking as input a piece type, coordinate and colour and outputting the "target" coordinates to which it can move, along with the coordinates traversed along the route. Input the FEN notation into a matrix of 1s for occupied cells and 0s for empty ones. Then loop over the players' pieces, calling this function and ruling out those "target" coordinates for which one of the cells "en route" is occupied (i.e has a 1 in the matrix).  
  > **username_1**: You'll have to deal with a lot of cases separately - pawns capturing diagonally, en passant, castling (and no castling when under attack), checks and checkmates etc.  
  > **username_0**: I was mainly asking for general tips, and this actually looks like a good place to start. Fyi this is a slightly simplified version of chess, so I don't have to tackle castling or en passant.  
  > **username_2**: This is an open-ended question, but that's why OP has posed it. Not all questions are factual. If OP had more "focus", the question would not need to be asked. There is certainly enough here to begin a useful dialogue, and I think the discussion already might be useful to others. The all-too-familiar knee-jerk closing of a perfectly ok question is unhelpful and is also unwelcoming to the a newcomer.  
  > **username_1**: @username_0 to add to my comment, you might find this recent YouTube video "coding a Chess AI" very useful. It begins with a relatively sensible approach to listing legal moves. Implementation is Python not Haskell, but it is written functionally so should translate.  
  > **username_1**: https://www.youtube.com/watch?v=U4ogK0MIzqk&ab_channel=SebastianLague  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2021-02-16. Score: 2
  
  FEN is fine for unambiguous communication of a position (if you include castling and e.p. state too) but the internal representation should be as a board, with some kind of movement so you can efficiently check for legal moves, blocks, checks etc. Would hate to do all that with regex!
  
  This quite a well-travelled area, and there must be much material online. You have made the choice to use Haskell here: what is the motivation for this? Are you trying to learn Haskell, or do you think it’s appropriate for certain aspects of a chess engine.
  
  Chess is a finite directed binary graph, with each position just a node. There is certain machinery to reach that level of abstraction, but ultimately I would think a functional language like Haskell might really begin to show its worth when you have reached that conceptual level.
  
  Depends also what you want your engine to do: find good moves, solve problems, analyse endgames, tablebases, retrograde analysis, support fairy chess. So please say more! :)
  
  > **Comments:**
  > **username_0**: First of all thanks for the answer ;) What I'm trying to describe here is only a part of the engine, which is only supposed to handle the computing of possible/legal moves for a given player/game state. I should also mention that I'm implementing here a slightly different version of chess(Crazyhouse) with no castling or en passant capturing. As to why I've decided on Haskell, the main requirement of the project is that I do this functionally, so there really isn't much wiggle room there :)  
  > **username_2**: Hi username_0 thanks for the classification. Leaving castling & en passant out for the first pass seems like a sensible approach, but you may want to leave the conceptual hooks in to add them later if necessary. The notion of state is even more essential to crazyhouse because each player has a handful of pieces to throw onto the board at any point. The main thing that strikes me about crazyhouse is that you can easily have 200 legal moves, most of which are trivially legal (unless there is a check). Orthodox chess is the hardest subset: might as well do that before adding the crazy stuff, imho  
  > **username_0**: That's true, I didn't realize that the extra moves(due to the crazyhouse concept) would add that much to the complexity.  
  
  ---
  
  