title: Haskell - Chess - which next moves are possible?
body: <p>I want to write a function that takes a chess figure with a position and tell me which moves this figure can make with his next move. </p>
  
  <p>For the king I was able to do this. </p>
  
  <pre><code>type Position = (Int,Int)
  
  data Piece = Piece {
      _position :: Position,
      _color :: String}
  
  nextMoves :: Piece -&gt; [Position]
  nextMoves king = filter (onTheBoard) (filter (/= (xOld,yOld)) 
                          [(x,y) | x &lt;- [(xOld-1)..(xOld+1)], y &lt;- [(yOld-1)..(yOld+1)]])
      where
          xOld = fst(_position king)
          yOld = snd(_position king)
  </code></pre>
  
  <p>He stands on (1,3) and my function gives me [(1,2),(1,4),(2,2),(2,3),(2,4)].</p>
  
  <p>Now I want to do the same for a bishop or a knight. But how can I use filter for this issue? 
  Thanks for a tipp.</p>
  
  <p>//edit: I've changed my check to a help function:</p>
  
  <pre><code>onTheBoard :: Position -&gt; Bool
  onTheBoard (x,y) = elem x [1..8] &amp;&amp; elem y [1..8]
  </code></pre>