Class: Board
- Inherits:
-
Object
- Object
- Board
- Defined in:
- lib/connect_four.rb
Instance Attribute Summary collapse
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#grid ⇒ Object
readonly
Returns the value of attribute grid.
-
#path_coords ⇒ Object
correct searchpaths for the cells, which will be how the game searches for a winner.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
-
#winner ⇒ Object
readonly
Returns the value of attribute winner.
Instance Method Summary collapse
- #cell(a1, column = nil) ⇒ Object
-
#initialize ⇒ Board
constructor
A new instance of Board.
- #offset(cell_x_y, x_offset, y_offset) ⇒ Object
Constructor Details
#initialize ⇒ Board
Returns a new instance of Board.
26 27 28 29 30 31 |
# File 'lib/connect_four.rb', line 26 def initialize @grid = create_board @rows = ("A".."F").to_a @columns = ("1".."7").to_a @path_coords = {:N =>[-1,0],:NE =>[-1,1],:E =>[0,1],:SE =>[1,1],:S =>[1,0],:SW =>[1,-1],:W =>[0,-1],:NW =>[-1,-1]} end |
Instance Attribute Details
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
25 26 27 |
# File 'lib/connect_four.rb', line 25 def columns @columns end |
#grid ⇒ Object (readonly)
Returns the value of attribute grid.
25 26 27 |
# File 'lib/connect_four.rb', line 25 def grid @grid end |
#path_coords ⇒ Object
correct searchpaths for the cells, which will be how the game searches for a winner.
24 25 26 |
# File 'lib/connect_four.rb', line 24 def path_coords @path_coords end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
25 26 27 |
# File 'lib/connect_four.rb', line 25 def rows @rows end |
#winner ⇒ Object (readonly)
Returns the value of attribute winner.
25 26 27 |
# File 'lib/connect_four.rb', line 25 def winner @winner end |
Instance Method Details
#cell(a1, column = nil) ⇒ Object
33 34 35 36 |
# File 'lib/connect_four.rb', line 33 def cell(a1,column = nil) #takes either an alphanumeric string argument (e.g. B3), or two Fixnums, and returns cell at those coordinates. a1.is_a?(String) ? @grid[@rows.index(a1[0].upcase)][@columns.index(a1[1])] : @grid[a1][column] end |
#offset(cell_x_y, x_offset, y_offset) ⇒ Object
38 39 40 |
# File 'lib/connect_four.rb', line 38 def offset(cell_x_y, x_offset, y_offset) @grid[cell_x_y.row + x_offset][cell_x_y.column + y_offset] end |