Block Battleship(Check the source code of block Battleship)

encoding of the Battleship puzzle

@block Battleship
  |_@block Guess
  |_@block OccupiedSpace
  |_@block Water
  |_@block Check
    |_@block Hints
  |_@block Output

Term Descriptions

  • X: X (Y) is a row (column) index ranging from 1 to 10
    • Described as integer(#V), #V > 0
  • Y: X (Y) is a row (column) index ranging from 1 to 10
    • Described as integer(#V), #V > 0
  • X1: further row and column indices
    • With same range as X
  • Y1: further row and column indices
    • With same range as X
  • X2: further row and column indices
    • With same range as X
  • Y2: further row and column indices
    • With same range as X
  • H: a hint which ranges from 0 to 10
    • Described as integer(#V)
  • O: orientation is either vertical or horizontal
    • In interval h, v
  • N: the name of a ship
    • In interval one1, one2, one3, one4, two1, two2, two3, three1, three2, four1
  • L: the length of a ship
    • Described as integer(#V), #V >= 1, #V <= 4

Input Atoms

  • water(X, Y)
    there is no ship at position (X,Y)
    • X: X (Y) is a row (column) index ranging from 1 to 10
    • Y: X (Y) is a row (column) index ranging from 1 to 10
  • ship(X, Y)
    some ship is occupying field (X,Y)
    • X: X (Y) is a row (column) index ranging from 1 to 10
    • Y: X (Y) is a row (column) index ranging from 1 to 10
  • rowHint(X, H)
    in row X, H squares are occupied
    • X: X (Y) is a row (column) index ranging from 1 to 10
    • H: a hint which ranges from 0 to 10
  • colHint(Y, H)
    in column Y, H squares are occupied
    • Y: X (Y) is a row (column) index ranging from 1 to 10
    • H: a hint which ranges from 0 to 10

Output Atoms

  • ship(X1, Y1, X2, Y2)
    a ship is occupying position (X1,Y1) to (X2,Y2)
    • X1: further row and column indices
    • Y1: further row and column indices
    • X2: further row and column indices
    • Y2: further row and column indices

Hidden Atoms

  • row(X)
    there is a row with index X
    • X: X (Y) is a row (column) index ranging from 1 to 10
  • col(X)
    there is a column with index X
    • X: X (Y) is a row (column) index ranging from 1 to 10
  • orientation(O)
    possible orientations of ships on the grid
    • O: orientation is either vertical or horizontal
  • shipInst(N, L)
    a ship with name N is of length L
    • N: the name of a ship
    • L: the length of a ship
  • shipPos(N, X, Y)
    ship with name N starts at postion (X,Y)
    • N: the name of a ship
    • X: X (Y) is a row (column) index ranging from 1 to 10
    • Y: X (Y) is a row (column) index ranging from 1 to 10
  • shipOrient(N, O)
    orientation of ship N is O
    • N: the name of a ship
    • O: orientation is either vertical or horizontal

Subblocks

guess startin position and orientation of every ship on the grid

@block Battleship
  |_@block Guess
  |_@block OccupiedSpace
  |_@block Water
  |_@block Check
    |_@block Hints
  |_@block Output


there is water iff there is no ship and each ships is surrounded by water

@block Battleship
  |_@block Guess
  |_@block OccupiedSpace
  |_@block Water
  |_@block Check
    |_@block Hints
  |_@block Output

check if configuration of ships is admissible and if all hints are
satisfied

@block Battleship
  |_@block Guess
  |_@block OccupiedSpace
  |_@block Water
  |_@block Check
    |_@block Hints
  |_@block Output

Subblocks

check if all hints are satisfied

@block Battleship
  |_@block Guess
  |_@block OccupiedSpace
  |_@block Water
  |_@block Check
    |_@block Hints
  |_@block Output

Hidden Atoms

  • rowShips(Y, H)
    number of occupied fields in row Y is H
    • Y: X (Y) is a row (column) index ranging from 1 to 10
    • H: a hint which ranges from 0 to 10
  • colShips(X, H)
    number of occupied fields in column X is H
    • X: X (Y) is a row (column) index ranging from 1 to 10
    • H: a hint which ranges from 0 to 10