3 kyu
Battleship field validator
5,086 of 15,223romanzes
Description:
Write a method that takes a field for well-known board game "Battleship" as an argument and returns true if it has a valid disposition of ships, false otherwise. Argument is guaranteed to be 10*10 two-dimension array. Elements in the array are numbers, 0 if the cell is free and 1 if occupied by ship.
Battleship (also Battleships or Sea Battle) is a guessing game for two players. Each player has a 10x10 grid containing several "ships" and objective is to destroy enemy's forces by targetting individual cells on his field. The ship occupies one or more cells in the grid. Size and number of ships may differ from version to version. In this kata we will use Soviet/Russian version of the game.

Before the game begins, players set up the board and place the ships accordingly to the following rules:
- There must be single battleship (size of 4 cells), 2 cruisers (size 3), 3 destroyers (size 2) and 4 submarines (size 1). Any additional ships are not allowed, as well as missing ships.
- Each ship must be a straight line, except for submarines, which are just single cell.
- The ship cannot overlap or be in contact with any other ship, neither by edge nor by corner.
Games
Arrays
Algorithms
Similar Kata:
Stats:
Created | Dec 25, 2013 |
Published | Dec 26, 2013 |
Warriors Trained | 46852 |
Total Skips | 9851 |
Total Code Submissions | 168183 |
Total Times Completed | 15223 |
JavaScript Completions | 5086 |
CoffeeScript Completions | 69 |
Python Completions | 5805 |
PHP Completions | 396 |
C++ Completions | 1195 |
Java Completions | 1426 |
C# Completions | 1333 |
Ruby Completions | 201 |
Total Stars | 2359 |
% of votes with a positive feedback rating | 94% of 2208 |
Total "Very Satisfied" Votes | 1984 |
Total "Somewhat Satisfied" Votes | 191 |
Total "Not Satisfied" Votes | 33 |