Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save femmestem/8747542 to your computer and use it in GitHub Desktop.
Save femmestem/8747542 to your computer and use it in GitHub Desktop.
Phase 0 Week 4 SOLO CHALLENGE: Create A Boggle Board
class BoggleBoard
def initialize(board)
@board = board
end
def letter_at(coord)
@board[coord.first][coord.last]
end
def create_word(*coords)
coords.collect { |coord| letter_at(coord) }.join("")
end
def get_row(row_coord)
return @board[row_coord]
end
def get_col(col_coord)
column = []
@board.each { |row| column << row[col_coord] }
return column
end
def get_diagonal(coord1, coord2)
# WIP
end
end
dice_grid = [["b", "r", "a", "e"],
["i", "o", "d", "t"],
["e", "c", "l", "r"],
["t", "a", "k", "e"]]
boggle_board = BoggleBoard.new(dice_grid)
# implement tests for each of the methods here:
puts "#create_word"
p boggle_board.create_word([2,1], [1,1], [1,2], [0,3]) == "code" # => true
p boggle_board.create_word([1,2], [1,1], [2,1], [3,2]) == "dock" # => true
p "#get_row"
p boggle_board.get_row(1) == ["i", "o", "d", "t"] # => true
p "#get_col"
p boggle_board.get_col(1) == ["r", "o", "c", "a"] # => true
# create driver test code to retrieve a value at a coordinate here:
puts "#letter_at"
p boggle_board.letter_at([3,2]) == "k"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment