Class: Board

Inherits:
Object
  • Object
show all
Defined in:
lib/connect_four.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBoard

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

#columnsObject (readonly)

Returns the value of attribute columns.



25
26
27
# File 'lib/connect_four.rb', line 25

def columns
  @columns
end

#gridObject (readonly)

Returns the value of attribute grid.



25
26
27
# File 'lib/connect_four.rb', line 25

def grid
  @grid
end

#path_coordsObject

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

#rowsObject (readonly)

Returns the value of attribute rows.



25
26
27
# File 'lib/connect_four.rb', line 25

def rows
  @rows
end

#winnerObject (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