Forked from dbc-challenges/0.2.1-boggle_class_from_methods.rb
Last active
August 29, 2015 13:55
-
-
Save payam10/8778580 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(dice_grid, *coords) | |
coords.map { |coord| dice_grid[coord.first][coord.last]}.join("") | |
end | |
def get_row(row) | |
p @dice_grid[row] | |
end | |
def get_col(col) | |
p @dice_grid.collect {|x| x[col]} | |
end | |
def get_all_rows | |
@dice_grid.map {|array| array.join} #prints rows as strings | |
end | |
end | |
dice_grid = [["b", "r", "a", "e"], # changed from Boggle_board to dice_grid | |
["i", "o", "d", "t"], | |
["e", "c", "l", "r"], | |
["t", "a", "k", "e"]] | |
boggle_board = BoggleBoard.new(dice_grid) # NEW boggle_board object | |
# implement tests for each of the methods here: | |
p boggle_board.create_word(dice_grid, [1,2], [1,1], [2,1], [3,2] ) # => dock | |
p boggle_board.get_row(0) # b r a e | |
p boggle_board.get_col(1) # r o c a | |
p boggle_board.get_all_rows | |
# create driver test code to retrieve a value at a coordinate here: | |
p 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