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.78 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.77 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.76 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.75 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.74 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.73 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.72 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.71 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.70 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.69 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.68 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.67 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.66 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.65 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.64 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.63 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.62 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.61 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.60 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.59 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs