Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save devdame/7712334 to your computer and use it in GitHub Desktop.
Save devdame/7712334 to your computer and use it in GitHub Desktop.
phase 0 unit 2 week 1 boggle class challenge
class BoggleBoard
def initialize(board)
@board = board
end
def get_row(row)
@board[row]
end
def get_col(col)
@board.transpose[col]
end
def create_word(*coords)
coords.map { |coord| @board[coord.first][coord.last]}.join("")
end
def get_diagonal(coord1, coord2)
unless coord1[1] - coord2[1] == coord1[0] - coord2[0] && coord1[1] - coord2[1] != 0
puts "This will not produce a diagonal!"
else
until coord1[1] == coord2[1] && coord1[0] == coord2[0]
diagonal = []
diagonal << @board[coord1[0]][coord1[1]]
if coord1[0] < coord2[0]
coord1[0] += 1
if coord1[1] < coord2[1]
coord1[1] +=1
else
coord1[1] -= 1
end
else
coord1[0] -= 1
if coord1[1] < coord2[1]
coord1[1] += 1
else
coord1[1] -= 1
end
end
end
diagonal << @board[coord2[0]][coord2[1]]
end
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:
# create driver test code to retrieve a value at a coordinate here:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment