Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save boue/8087620 to your computer and use it in GitHub Desktop.
Save boue/8087620 to your computer and use it in GitHub Desktop.
phase 0 unit 2 week 1 boggle class challenge
#Pseudocode
#We want to be able to create a new boggleboard. Dice_grid will be passed as an argument.
#From our past work we will be able to re-use and integrate some of the methods into our classes.
#When we create a new instance of BoggleBoard we will have to pass Dice_grid as an argument to be able to call the board 2D array.
class BoggleBoard
attr_reader :board
def initialize(board)
@board = board
end
def get_row(row)
print @board[row]
end
def create_word(*coords)
coords.map { |coord| @board[coord.first][coord.last]}.join("")
end
def get_col(col)
print @board.map {|row| row[col]}
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) #if we pass dice_grid as an argument, we will later store it in instance variable when
# a new instance of the object is initialized.
# implement tests for each of the methods here:
boggle_board.get_row(0) # ["b", "r", "a", "e"]
boggle_board.get_col(1) # ["r", "o", "c", "a"]
puts boggle_board.create_word([1,2], [1,1], [2,1], [3,2]) # Returns "dock"
puts boggle_board.board[1][3] #returns t
puts boggle_board.board[3][2] #returns k
puts boggle_board.board[2][2] #returns l
puts boggle_board.board[3][3] #returns e
#IDEAS FOR BONUS
#get_diagonal needs 2 coordinates entered to define the diagonal. Here we would have to sort of shift progressively per
# row depending on which starting point and return a diagonal.
def get_diagonal(coord1, coord2)
end
#We will also need an Error checking to make sure the coordinates are actually a diagonal so they would have to start
#from the top left, top right, bottom right, bottom left.
def is_diagonal?(coord1, coord2)
boggle_board.board[0][0] || boggle_board.board[0][3] || boggle_board.board[3][0] || boggle_board.board[3][3] ? true : false
end
#Reflection
# Most of the work was already done as we had defined the method from the previous exercise. I realized how you can store
# the dice grid into an instance variable. Also every time you create an object now, you don't have to repeat the same
# methods over and over as each instance of the object will have those behaviors. I am understanding that to be the essence
# of O.O.P.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment