Refactors Ship.index and improves specs

Signed-off-by: João Soares <jsoaresgeral@gmail.com>
Ship.index support to name symbols and shortnames

Ship.index now supports full ship(undescore separated) names on symbols
like :aircraft_carrier or :patrol_boat and shortnames for the specific
cases of :carrier and :boat.

Signed-off-by: João Soares <jsoaresgeral@gmail.com>
Adds object type verification on Board#add!

Board#add! now raises an InvalidShipArgument error when passed
something other than a Ship object.
For example, if you call Board#add! with a ship identifier as you would
do for Player#place, although the identifier is accepted by Ship.index
Board#add! doesn't allow it.

Signed-off-by: João Soares <jsoaresgeral@gmail.com>
Improves Board#add! with a non modifying Board#add

Adds Board#add as a non modifying alternative to Board#add!
It creates a deep copy by calling the dup method and returns that
copy with the ship added by sending it the add! message.

Signed-off-by: João Soares <jsoaresgeral@gmail.com>
Corrected minor error in specs

Signed-off-by: João Soares <jsoaresgeral@gmail.com>
Adds support to address rows and columns directly

Adds a #row method alias to #[].
Adds a #col method that allows addressing a board column directly.

Signed-off-by: João Soares <jsoaresgeral@gmail.com>
Adds support for addressing a single sector directly

Adds the Board#sector method which receives a board and a column and
returns the specified sector by accepting the arguments in the same
format as .row_to_idx and .col_to_idx.

Signed-off-by: João Soares <jsoaresgeral@gmail.com>
Corrected shadowing of an outer local variable

Signed-off-by: João Soares <jsoaresgeral@gmail.com>
Improves overall specification format and syntax

Improves Board specification format
Improves Ship specification format
Improves Player spec format
Improves Game spec format
Overall syntax improvement for brevity and documentation readability

Signed-off-by: João Soares <jsoaresgeral@gmail.com>
Adds iterator support over board columns and rows

Implements Board#each and its synonym Board#each_sector allowing to
iterate over each sector of the board.
Also implements Board#each_row and Board#each_col to allow iterating
over board columns and board rows.
Since these methods return an enumerator when no block is given, it
also allows the use in conjunction with methods like collect, inject,
select, etc.
This allow uses like:
  board.select { |sector| sector.ship.is_a? Ship }

Signed-off-by: João Soares <jsoaresgeral@gmail.com>
Board#cols and #rows aliases #each_col, #each_row

Adds Board#cols as an alias to Board#each_col and also Board#rows as an
alias to Board#each_row.
This allows to use a more natural language when writing code as
board.rows.select(&has_ship)

Signed-off-by: João Soares <jsoaresgeral@gmail.com>
Refactors Board#to_s method using a Proc

Considerably reduces the amount of code needed to produce the same
result

Signed-off-by: João Soares <jsoaresgeral@gmail.com>
Refactors Board#to_s eliminating code duplication

Replace duplicated line of code by a Proc, exchanging lines of code by
code readability.

Signed-off-by: João Soares <jsoaresgeral@gmail.com>
Changes Board#to_a to return the arrays deep copy

Board#to_a now returns a deep copy of the Board object's inner array
allowing the array returned to be modified freely without afecting the
original object.
Reimplements Sector#dup.
Implements Ship#dup.
Also adds some tests to verify that modification of the returned array
does not result in modifying the original object.

Signed-off-by: João Soares <jsoaresgeral@gmail.com>
Updates spec code using later API implementation

Replaces the use of #to_a method to access a row of the Board object by
the recently added and more readable method #row.
Also rewrites a spec example that relyed on previous #to_a method to
better express the intent of the specification.

Signed-off-by: João Soares <jsoaresgeral@gmail.com>
Alters board_spec to remove code duplication

Replaced context before(:each) blocks by a single one at the beginning
of the instance methods description list.

Signed-off-by: João Soares <jsoaresgeral@gmail.com>