Sha256: 017a346eb2dc34342c2cf9d1af3b1b806d8c5ae369829bd23eeca68417cef19e

Contents?: true

Size: 665 Bytes

Versions: 396

Compression:

Stored size: 665 Bytes

Contents

module Queens (boardString, canAttack) where

type Position = (Int, Int)

boardString :: Maybe Position -> Maybe Position -> String
boardString w b = concatMap rowString [0..7]
  where
    rowString row = concatMap (tileString row) [0..7]
    tileString row col = [tileChar (row, col), tileSep col]
    tileSep 7 = '\n'
    tileSep _ = ' '
    tileChar pos
      | w == Just pos = 'W'
      | b == Just pos = 'B'
      | otherwise     = '_'

canAttack :: Position -> Position -> Bool
canAttack (wr, wc) (br, bc) = sameRow || sameCol || diagonal
  where
    dr = wr - br
    dc = wc - bc
    sameRow  = dr == 0
    sameCol  = dc == 0
    diagonal = abs dr == abs dc

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.2.1.98 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.97 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.96 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.95 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.94 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.93 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.92 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.91 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.90 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.89 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.88 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.87 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.86 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.85 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.84 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.83 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.82 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.81 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.80 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.79 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs