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.180 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.179 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.178 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.177 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.176 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.175 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.174 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.173 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.172 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.171 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.170 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.169 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.167 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.166 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.165 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.164 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.163 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.162 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.161 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs
trackler-2.2.1.160 tracks/haskell/exercises/queen-attack/examples/success-standard/src/Queens.hs