Class: C4::Model::Board
- Inherits:
-
Object
- Object
- C4::Model::Board
- Defined in:
- lib/c4/model/board.rb
Instance Attribute Summary collapse
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#num_columns ⇒ Object
readonly
Returns the value of attribute num_columns.
-
#num_rows ⇒ Object
readonly
Returns the value of attribute num_rows.
Instance Method Summary collapse
- #diagonals ⇒ Object
- #full? ⇒ Boolean
-
#initialize(num_rows, num_columns) ⇒ Board
constructor
A new instance of Board.
- #put_stone!(column, mark) ⇒ Object
- #to_a(mode = :column_wise) ⇒ Object
Constructor Details
Instance Attribute Details
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
9 10 11 |
# File 'lib/c4/model/board.rb', line 9 def columns @columns end |
#num_columns ⇒ Object (readonly)
Returns the value of attribute num_columns.
9 10 11 |
# File 'lib/c4/model/board.rb', line 9 def num_columns @num_columns end |
#num_rows ⇒ Object (readonly)
Returns the value of attribute num_rows.
9 10 11 |
# File 'lib/c4/model/board.rb', line 9 def num_rows @num_rows end |
Instance Method Details
#diagonals ⇒ Object
37 38 39 40 |
# File 'lib/c4/model/board.rb', line 37 def diagonals matrix = Matrix.new(columns.map(&:to_a), num_rows, num_columns) matrix.diagonals end |
#full? ⇒ Boolean
25 26 27 |
# File 'lib/c4/model/board.rb', line 25 def full? columns.all?(&:full?) end |
#put_stone!(column, mark) ⇒ Object
19 20 21 22 23 |
# File 'lib/c4/model/board.rb', line 19 def put_stone!(column, mark) raise InvalidColumnError, 'Column does not exist!' if column.negative? || column >= columns.size columns[column].put!(mark) end |
#to_a(mode = :column_wise) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/c4/model/board.rb', line 29 def to_a(mode = :column_wise) column_wise = Matrix.new(columns.map(&:to_a), num_rows, num_columns) return column_wise.transpose.matrix if mode == :row_wise # Changes the shape return column_wise.transpose.reverse.matrix if mode == :print column_wise.matrix end |