Forked from dbc-challenges/0.2.1-boggle_class_from_methods.rb
Last active
January 1, 2016 09:08
-
-
Save tsamb/8122634 to your computer and use it in GitHub Desktop.
phase 0 unit 2 week 1
boggle 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_letter(row, col) | |
@board[row][col] | |
end | |
def get_row(row) | |
@board[row] | |
end | |
def get_col(col) | |
column_contents = [] | |
@board.each_index { |i| column_contents << @board[i][col] } | |
column_contents | |
end | |
def get_diagonal(coord1, coord2) | |
# is it possible for coord1 & 2 to be diagonal? | |
# coord1[0] + 1, 2 or 3, or coord1[0] - 1, 2, or 3 == coord2[0] | |
# and coord1[1] + 1, 2 or 3, or coord1[1] - 1, 2, or 3 == coord2[1] | |
# | |
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: | |
# Write out a test with it's expectation in a comment, and then create the method in the BoggleBoard class. Try these coordinates: (1,2), (1,1), (2,1), (3,2). | |
puts boggle_board.create_word([1,2], [1,1], [2,1], [3,2]) #=> prints "dock" | |
p boggle_board.get_col(3) #=> prints ["e", "t", "r", "e"] | |
p boggle_board.get_row(1) #=> prints ["b", "r", "a", "e"] | |
# create driver test code to retrieve a value at a coordinate here: | |
p boggle_board.get_letter(3,2) #=> prints "k" | |
# in_arrays = [[[0,0], [0,1], [0,2], [0,3]], | |
# [[1,0], [1,1], [1,2], [1,3]], | |
# [[2,0], [2,1], [2,2], [2,3]], | |
# [[3,0], [3,1], [3,2], [3,3]]] | |
# diagonal test | |
# valid diagonals: | |
# [0,0][1,1][2,2][3,3] | |
# [1,0][2,1][3,2] | |
# [1,0][0,1] | |
# [2,0][1,1][0,2] | |
# [3,0][2,1][1,2][0,3] | |
# etc | |
# | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment