Skip to content

Instantly share code, notes, and snippets.

@stomatocode
Created June 28, 2013 04:37
Show Gist options
  • Save stomatocode/5882481 to your computer and use it in GitHub Desktop.
Save stomatocode/5882481 to your computer and use it in GitHub Desktop.
class Die
attr_reader :dice, :top
@@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','Q','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
@dice = @@dice.shuffle.pop
roll
end
def roll
@top = @dice.sample
end
def to_s
@top
end
end
class BoggleBoard
def initialize
@state = populate
end
def populate
Array.new(4) { Array.new(4) { Die.new } }
end
def shake!
@state.flatten.each {|die| die.roll}
end
def to_s
@state.each {|row| p row.each }
end
end
game = BoggleBoard.new
game.shake!
puts game
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment