battleship-combinatorics-0.0.0.1: Compute number of possible arrangements in the battleship game

Safe HaskellNone
LanguageHaskell98

Combinatorics.Battleship.Count.Frontier

Synopsis

Documentation

data T w Source #

Efficient representation of a (Map Position Use).

We need it for description of a cut of a board with ships.

   ....#.....
   ....#.....
   ..........
   ####......
   ..........
___...#...#..___
   ##.#...#..
   ...#......
   ...#..###.
   ..........

Say, we are constructing the board with ships beginning from the bottom. Using information from the cut, we want to know at what positions in the upper plane are ships allowed. In the example the frontier at the cut would be

fromString "xxx3x.x1x."

The numbers 3 and 1 denotes lengths of the parts of vertical ships below the cut. The x's denote blocked columns, i.e. in these columns it is not allowed to place ships immediately above the cut.

Instances

Eq (T w) Source # 

Methods

(==) :: T w -> T w -> Bool #

(/=) :: T w -> T w -> Bool #

Ord (T w) Source # 

Methods

compare :: T w -> T w -> Ordering #

(<) :: T w -> T w -> Bool #

(<=) :: T w -> T w -> Bool #

(>) :: T w -> T w -> Bool #

(>=) :: T w -> T w -> Bool #

max :: T w -> T w -> T w #

min :: T w -> T w -> T w #

Nat w => Show (T w) Source # 

Methods

showsPrec :: Int -> T w -> ShowS #

show :: T w -> String #

showList :: [T w] -> ShowS #

Nat w => Arbitrary (T w) Source # 

Methods

arbitrary :: Gen (T w) #

shrink :: T w -> [T w] #

Storable (T w) Source # 

Methods

sizeOf :: T w -> Int #

alignment :: T w -> Int #

peekElemOff :: Ptr (T w) -> Int -> IO (T w) #

pokeElemOff :: Ptr (T w) -> Int -> T w -> IO () #

peekByteOff :: Ptr b -> Int -> IO (T w) #

pokeByteOff :: Ptr b -> Int -> T w -> IO () #

peek :: Ptr (T w) -> IO (T w) #

poke :: Ptr (T w) -> T w -> IO () #

data Use Source #

Constructors

Free 
Blocked 
Vertical Int 

Instances

Eq Use Source # 

Methods

(==) :: Use -> Use -> Bool #

(/=) :: Use -> Use -> Bool #

Show Use Source # 

Methods

showsPrec :: Int -> Use -> ShowS #

show :: Use -> String #

showList :: [Use] -> ShowS #

blockBounded :: Nat w => Size w -> Position -> T w -> T w Source #

Inserts at positions outside of the bounds are ignored. You may overwrite Free or Blocked fields, but not Vertical ones.

insertNew :: Nat w => Position -> Use -> T w -> T w Source #

Only allowed at positions containing Free.

isFree :: Nat w => T w -> Position -> Bool Source #

dilate :: Size w -> T w -> T w Source #

lookup :: Nat w => T w -> Position -> Use Source #

reverse :: Nat w => T w -> T w Source #

foldMap :: Monoid m => (Use -> m) -> T w -> m Source #

Can be faster than toList since it does not build a list. It ignores Free squares at the end of the frontier.

toList :: Nat w => T w -> [Use] Source #

mapToVector :: (Nat w, Storable a) => Size w -> (Use -> a) -> T w -> Vector a Source #

fromList :: [Use] -> T w Source #