Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jrosaaen/9164202 to your computer and use it in GitHub Desktop.
Save jrosaaen/9164202 to your computer and use it in GitHub Desktop.
phase 0 unit 2 week 1boggle class challenge
class BoggleBoard
#your code here
class BoggleBoard
# This will create an object called board that I can use later to directly access the board
attr_reader :board
# Initialize the board
def initialize(board)
@board = board
end
# Create words by mapping coordinates
def create_word(*coords)
coords.map { |coord| @board[coord.first][coord.last]}.join("")
end
# Get row
def get_row(row)
@board[row]
end
# Get column
def get_col(column)
@board.collect {|row| row[column]}
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:
print boggle_board.create_word([3,0], [3,1], [2,1], [3,2], [2,2], [3,3]) #=> "tackle"
puts
print boggle_board.create_word([1,0], [0,1], [0,2], [1,3], [0,3]) #=> "irate"
puts
print boggle_board.create_word([0,0], [0,1], [1,0], [2,0]) #=> "brie"
puts
print boggle_board.create_word([0,0], [1,0], [0,1], [1,2]) #=> "bird"
puts
print boggle_board.create_word([0,1], [1,1], [2,1], [3,2]) #=> "rock"
puts
print boggle_board.create_word([0,2], [1,3], [0,3]) #=> "ate"
puts
print boggle_board.get_row(1) #=> ["i", "o", "d", "t"]
puts
print boggle_board.get_row(2) #=> ["e", "c", "l", "r"]
puts
print boggle_board.get_row(3) #=> ["t", "a", "k", "e"]
puts
print boggle_board.get_col(1) #=> ["r", "o", "c", "a"]
puts
print boggle_board.get_col(2) #=> ["a", "d", "l", "k"]
puts
print boggle_board.get_col(3) #=> ["e", "t", "r", "e"]
puts
# create driver test code to retrieve a value at a coordinate here:
print boggle_board.board[1][0] #=> should be "i"
puts
puts
print boggle_board.board[0][1] #=> should be "r"
puts
print boggle_board.board[1][1] #=> should be "o"
puts
print boggle_board.board[2][1] #=> should be "c"
puts
print boggle_board.board[3][2] #=> should be "k"
puts
# Starting to feel a little cocky and confident at this time
#...probably should rein that in...but for now
#...I want to revel in this. LOL!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment