Forked from dbc-challenges/0.2.1-boggle_class_from_methods.rb
Last active
August 29, 2015 13:55
-
-
Save newrube7/8739018 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(new_grid) | |
@boggle_board = new_grid | |
end | |
def create_word(*coords) | |
board = @boggle_board | |
coords.map { |coord| board[coord.first][coord.last] }.join("") | |
end | |
#puts @boggle_board, [2,1], [1,1], [1,2], [0,3] #=> returns "code" | |
#puts @boggle_board, [0,1], [0,2], [1,2] #=> creates what california slang word? | |
# puts create_word(@boggle_board, [2,1], [1,1], [1,2], [0,3]) #=> returns "code" | |
# puts create_word(@boggle_board, [0,1], [0,2], [1,2]) #=> creates the word "rad" | |
# puts create_word(@boggle_board, [3,0], [0,2], [3,2], [3,3]) #=> creates the word "take" | |
# puts create_word(@boggle_board, [0,3], [2,1], [2,2], [0,2], [1,0], [2,3]) #=> creates the word "eclair" | |
def get_row(row) | |
@row = row | |
board = @boggle_board | |
one_row = board[@row][(0..3)] | |
puts "row #{@row} looks like #{one_row}" #=> ["i", "o", "d", "t"] | |
end | |
puts "space between row and col" | |
def get_col(col) | |
board = @boggle_board | |
n=0 | |
one_col = [] | |
while n < 4 do one_col << board[ n ][col] | |
n += 1 | |
end | |
puts "Col #{col} looks like #{one_col}" | |
end | |
end # end class | |
#dice_grid = [] | |
# implement tests for each of the methods here: | |
dice_grid = [["b", "r", "a", "e"], | |
["i", "o", "d", "t"], | |
["e", "c", "l", "r"], | |
["t", "a", "k", "e"]] | |
boggle_board = BoggleBoard.new(dice_grid) | |
puts "dice_grid looks like #{dice_grid}" | |
puts "dice_grid.is_a? is #{dice_grid.is_a? Array}" | |
puts boggle_board.create_word([2,1], [1,1], [1,2], [0,3]) # code | |
puts boggle_board.get_row(1) #=> ["i", "o", "d", "t"] | |
puts boggle_board.get_col(1) #==> ["r", "o", "c", "a"] | |
# create driver test code to retrieve a value at a coordinate here: | |
puts boggle_board.create_word([3,2]) # k | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment