boardwidth is 3
i represend a 3x3 matrix by a 1x9 array
the test:
test "the row checking to see if we have a winner (incorrect)" do
board = Board.new
board.state = [0,0,1,0,0,1,0,0,1]
assert false ==board.check_rows_for_winner
end
relevant code
@board_layout = []
def init_board
@board_layout = Array.new(@@board_width * @@board_width)
end
def state=(custom_board)
@board_layout = custom_board
end
def check_rows_for_winner
self.width.times do |row|
if @board_layout.transpose[row].uniq.size == 1 then
return true
end
end
return false
end
error:
TypeError: can't convert Fixnum into Array
app/models/board.rb:39:in `transpose'
app/models/board.rb:39:in `check_rows_for_winner'
app/models/board.rb:38:in `times'
app/models/board.rb:38:in `check_rows_for_winner'