Forked from dbc-challenges/0.2.1-boggle_class_from_methods.rb
Last active
August 29, 2015 13:56
-
-
Save ktantry/9144420 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(dice_grid) | |
@dice_grid = dice_grid | |
end | |
def create_word(*coords) | |
coords.map { |coord| @dice_grid[coord.first][coord.last]}.join("") | |
end | |
def get_row(row) | |
return @dice_grid[row] | |
end | |
def get_column(column) | |
current_column = [] | |
@dice_grid.each do |element| | |
current_column << element[column] | |
end | |
return current_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) | |
# Driver Test Code for Accessing a Coordinate | |
puts boggle_board.create_word([1,2], [1,1], [2,1], [3,2]) #=> returns "dock" | |
puts boggle_board.create_word([3,2]) == "k" #=> returns "true" | |
puts boggle_board.create_word([3,1]) == "a" #=> returns "true" | |
puts boggle_board.create_word([3,0]) == "r" #=> returns "false" | |
# Commented test code for 8 four letter words (columns and rows) | |
=begin | |
puts boggle_board.get_row(0).join("") == "brae" # returns true | |
puts boggle_board.get_row(1).join("") == "iodt" # returns true | |
puts boggle_board.get_row(2).join("") == "eclr" # returns true | |
puts boggle_board.get_row(3).join("") == "take" # returns true | |
puts boggle_board.get_column(0).join("") == "biet" # returns true | |
puts boggle_board.get_column(1).join("") == "roca" # returns true | |
puts boggle_board.get_column(2).join("") == "adlk" # returns true | |
puts boggle_board.get_column(3).join("") == "etre" # returns true | |
=end | |
# Reflection: | |
# Definitely a good exercise in understanding classes. I'm really glad that we've basically | |
# spent this whole week on understanding the sequences of classes and methods. I think, even | |
# more importantly, I've learned how to quickly and efficiently test code. In the past, I was | |
# always confused about how to call a method within a class. I always had to look online, and I | |
# would often make typos. Practicing the testing process has made the entire thing much less | |
# cumbersome. | |
# Object oriented program is great for organizational purposes. I've been reviewing the 3 | |
# components of the user story as well, and it makes me realize how important organization is. | |
# 3 weeks ago, I feel like I would plan for 5 minutes, and then code for an hour to solve a problem. | |
# Now I feel like if I plan for 20 minutes, I can code for less than 20 more minutes and solve the same problem. | |
# In terms of technical knowledge, I did not really learn anything new. It was very similar to | |
# the first boggle_board problem, and I actually reused most of my code. It was the building of | |
# classes that made this exercise worthwhile. | |
# Not entirely sure how to do the get_diagonal bonus right now. I'm going to check up and come back | |
# to this later. But perhaps there will be some new method that I learn. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment