Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save papapoison/7667893 to your computer and use it in GitHub Desktop.

Select an option

Save papapoison/7667893 to your computer and use it in GitHub Desktop.

Revisions

  1. papapoison revised this gist Nov 26, 2013. 1 changed file with 55 additions and 5 deletions.
    60 changes: 55 additions & 5 deletions 0.2.1-boggle_class_from_methods.rb
    Original file line number Diff line number Diff line change
    @@ -1,22 +1,72 @@
    #Boggle Board class

    class BoggleBoard

    #your code here
    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


    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)

    # implement tests for each of the methods here:
    ###############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)

    # create driver test code to retrieve a value at a coordinate here:
    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.
  2. @dbc-challenges dbc-challenges revised this gist Oct 31, 2013. 1 changed file with 10 additions and 1 deletion.
    11 changes: 10 additions & 1 deletion 0.2.1-boggle_class_from_methods.rb
    Original 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)
    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:



  3. @dbc-challenges dbc-challenges created this gist Oct 31, 2013.
    13 changes: 13 additions & 0 deletions 0.2.1-boggle_class_from_methods.rb
    Original 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)