Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Bigspencey/7779953 to your computer and use it in GitHub Desktop.
Save Bigspencey/7779953 to your computer and use it in GitHub Desktop.
phase 0 unit 2 week 1 boggle class challenge
class BoggleBoard
def initialize(dice_grid)
@dice_grid = dice_grid
end
def create_word(board, *coords)
coords.map { |coord| board[coord.first][coord.last] }.join("")
end
def get_row(row)
@dice_grid[row].join("")
end
def get_col(col)
@dice_grid.map { |x| x[col] }.join("")
end
def get_diagonal(first, last)
#Having trouble with the bonus at the moment - coming back to it later.
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 boggle_board.create_word(dice_grid, [1,2], [1,1], [2,1], [3,2])
puts boggle_board.get_row(0)
puts boggle_board.get_row(1)
puts boggle_board.get_row(2)
puts boggle_board.get_row(3)
puts boggle_board.get_col(0)
puts boggle_board.get_col(1)
puts boggle_board.get_col(2)
puts boggle_board.get_col(3)
# dock => Real Word!
# brae
# iodt
# eclr
# take => Real Word!
# biet
# roca
# adlk
# etre
# create driver test code to retrieve a value at a coordinate here:
boggle_board.create_word(dice_grid, [3,2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment