Skip to content

Instantly share code, notes, and snippets.

@lordhumunguz
Created March 15, 2013 08:01
Show Gist options
  • Save lordhumunguz/5168206 to your computer and use it in GitHub Desktop.
Save lordhumunguz/5168206 to your computer and use it in GitHub Desktop.
This gist has been created from CodeCred.me
class BoggleBoard
DICE = [['A','A','E','E','G','N'],
['E','L','R','T','T','Y'],
['A','O','O','T','T','W'],
['A','B','B','J','O','O'],
['E','H','R','T','V','W'],
['C','I','M','O','T','U'],
['D','I','S','T','T','Y'],
['E','I','O','S','S','T'],
['D','E','L','R','V','Y'],
['A','C','H','O','P','S'],
['H','I','M','N','Qu','U'],
['E','E','I','N','S','U'],
['E','E','G','H','N','W'],
['A','F','F','K','P','S'],
['H','L','N','N','R','Z'],
['D','E','I','L','R','X']]
def initialize
@board = Array.new(4, Array.new(4, '_'))
end
def shake!
random_dice = DICE.shuffle.map { |die| die.sample }
@board = Array.new(4) {random_dice.shift(4) }
end
def to_s
@str = ""
@board.each do |row|
row.each { |elem| elem == 'Qu' ? @str << elem + " " : @str << elem + " " }
@str << "\n"
end
@str
end
end
board = BoggleBoard.new
board.shake!
p board
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment