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.58 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.57 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.56 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.55 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.54 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.53 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.52 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.51 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.50 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.49 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.48 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.47 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.46 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.45 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.44 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.43 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.42 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.41 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.40 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.39 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs