Forked from dbc-challenges/0.2.1-boggle_class_from_methods.rb
Last active
August 29, 2015 13:55
-
-
Save fgarbagnati/8703092 to your computer and use it in GitHub Desktop.
phase 0 unit 2 week 1boggle class challenge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BoggleBoard | |
def initialize(board) | |
@board = board | |
end | |
def create_word(*coords) | |
coords.map { |coord| @board[coord.first][coord.last]}.join("") | |
end | |
def get_row(row) | |
@board[row] | |
end | |
def get_col(col) | |
returned_col = [] | |
@board.each do |row| | |
returned_col << row.at(col) | |
end | |
returned_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) | |
# implement tests for each of the methods here: | |
# create_word | |
p boggle_board.create_word([1,2],[1,1],[2,1],[3,2]) == "dock" | |
p boggle_board.create_word([3,0],[3,1],[2,1],[3,2],[2,2],[3,3]) == "tackle" | |
p boggle_board.create_word([1,1],[0,2],[0,1]) == "oar" | |
# get_row | |
p boggle_board.get_row(0) == ["b", "r", "a", "e"] | |
p boggle_board.get_row(1) == ["i", "o", "d", "t"] | |
p boggle_board.get_row(2) == ["e", "c", "l", "r"] | |
p boggle_board.get_row(3) == ["t", "a", "k", "e"] #=> Real word!! | |
# get_col | |
p boggle_board.get_col(0) == ["b", "i", "e", "t"] | |
p boggle_board.get_col(1) == ["r", "o", "c", "a"] | |
p boggle_board.get_col(2) == ["a", "d", "l", "k"] | |
p boggle_board.get_col(3) == ["e", "t", "r", "e"] #=> Real word in French!! | |
# p boggle_board.get_diagonal([0,0],[3,3]) #== ["b", "o", "l", "e"] | |
##### couldn't figure out the diagonal on my own :( ##### | |
# create driver test code to retrieve a value at a coordinate here: | |
p boggle_board.create_word([3,2]) == "k" | |
p boggle_board.create_word([1,3]) == "t" | |
##### Not sure if this is what that objective was looking for... ##### | |
##### REFLECTION ##### | |
=begin | |
I think object-oriented programming requires more of an abstract thought process than procedural programming. Procedural | |
programming feels a lot more systematic. I can see how object-oriented programming has its benefits in that the code | |
is more reusable. | |
I had trouble doing the diagonal without help. I've been doing some research and may come back to it later on this week, | |
but if I do have an answer, it was likely influenced by a lot of research. | |
=end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment