Forked from dbc-challenges/0.2.1-boggle_class_from_methods.rb
Last active
December 29, 2015 11:59
-
-
Save papapoison/7667893 to your computer and use it in GitHub Desktop.
Revisions
-
papapoison revised this gist
Nov 26, 2013 . 1 changed file with 55 additions and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,22 +1,72 @@ #Boggle Board class class BoggleBoard def initialize(board) @board = board end def access(point1, point2) puts @board[point1][point2] end def create_word(*coords) puts coords.map { |coord| @board[coord.first][coord.last]}.join("") end def get_row(row) puts @board[row].inspect end def get_col(col) puts @board.transpose[col].inspect end def get_diag(row, col) diag_arr = [] diag_arr << @board[row - 1][col - 1] unless @board[row][col] == nil diag_arr << @board[row + 1][col + 1] unless @board[row][col] == nil diag_arr << @board[row + 1][col - 1] unless @board[row][col] == nil diag_arr << @board[row - 1][col + 1] unless @board[row][col] == nil puts diag_arr.inspect end end ##########Calls############## dice_grid = [["b", "r", "a", "e"], ["i", "o", "d", "t"], ["e", "c", "l", "r"], ["t", "a", "k", "e"]] boggle_board = BoggleBoard.new(dice_grid) ###############TESTS################ boggle_board.create_word([2, 1], [1, 1], [1, 2], [0, 3]) boggle_board.create_word([0, 1], [0, 2], [1, 2]) boggle_board.create_word([2, 1], [3, 1], [3, 2], [3, 3]) boggle_board.create_word([3, 0], [3, 1], [2, 1], [3, 2], [2, 2], [3, 3]) boggle_board.get_row(1) boggle_board.get_row(0) boggle_board.get_col(3) boggle_board.get_col(2) boggle_board.get_diag(2, 2) boggle_board.get_diag(2, 1) ###############DRIVER################## boggle_board.access(2, 1) boggle_board.access(3, 1) boggle_board.access(3, 2) ##############REVIEW################### #Coding using OOP methodology makes things a great deal easier. Conceptually, it just makes more sense. #Thing 1 can do a, b, and c. d, e, and f are private, and cannot be acceced from without #It also makes the code more versatile, allowing me to pass in any values at the initialization of my code # that will work regardless. It's good stuff. In the long run it makes your code more dry because you can reuse # methods without retyping the shit each time. -
dbc-challenges revised this gist
Oct 31, 2013 . 1 changed file with 10 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -10,4 +10,13 @@ class BoggleBoard ["e", "c", "l", "r"], ["t", "a", "k", "e"]] boggle_board = BoggleBoard.new(dice_grid) # implement tests for each of the methods here: # create driver test code to retrieve a value at a coordinate here: -
dbc-challenges created this gist
Oct 31, 2013 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ class BoggleBoard #your code here 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)