Class: Gobgems::Board
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#count, #exist?, #pop, #push
#__move_to__, #can_move?, #move
Constructor Details
#initialize(cells, position) ⇒ Board
Returns a new instance of Board.
52
53
54
55
|
# File 'lib/gobgems/board.rb', line 52
def initialize(cells, position)
@cells = cells
@head_position = position
end
|
Instance Attribute Details
#cells ⇒ Object
Returns the value of attribute cells.
50
51
52
|
# File 'lib/gobgems/board.rb', line 50
def cells
@cells
end
|
#head_position ⇒ Object
Returns the value of attribute head_position.
50
51
52
|
# File 'lib/gobgems/board.rb', line 50
def head_position
@head_position
end
|
Class Method Details
.empty(x, y, position = [0, 0]) ⇒ Object
71
72
73
|
# File 'lib/gobgems/board.rb', line 71
def self.empty(x, y, position=[0, 0])
self.new((1..x).map { (1..y).map { empty_cell } }, position)
end
|
.from(cells, position = [0, 0]) ⇒ Object
75
76
77
|
# File 'lib/gobgems/board.rb', line 75
def self.from(cells, position=[0, 0])
self.new(cells.map { |row| row.map { |cell| empty_cell.merge(cell) } }, position)
end
|
Instance Method Details
#==(other) ⇒ Object
61
62
63
64
65
|
# File 'lib/gobgems/board.rb', line 61
def ==(other)
self.class == other.class &&
self.cells == other.cells &&
self.head_position == other.head_position
end
|
#__cell_at__(position) ⇒ Object
83
84
85
86
|
# File 'lib/gobgems/board.rb', line 83
def __cell_at__(position)
raise OutOfBoardError unless within_bounds? position
cells[position[0]][position[1]]
end
|
#__set_cell__(position, cell) ⇒ Object
79
80
81
|
# File 'lib/gobgems/board.rb', line 79
def __set_cell__(position, cell)
__cell_at__(position).merge! cell
end
|
#hash ⇒ Object
67
68
69
|
# File 'lib/gobgems/board.rb', line 67
def hash
self.cells.hash ^ self.head_position.hash
end
|
#size ⇒ Object
57
58
59
|
# File 'lib/gobgems/board.rb', line 57
def size
[cells.size, cells[0].size]
end
|