Skip to content

Instantly share code, notes, and snippets.

@tejo
Created January 15, 2012 12:26
Show Gist options
  • Save tejo/1615700 to your computer and use it in GitHub Desktop.
Save tejo/1615700 to your computer and use it in GitHub Desktop.
italian boggle
Array::randomize = -> @sort -> 0.5 - Math.random()
class Boggle
constructor: ->
@dices = [
['A', 'Z', 'F', 'S', 'Qu', 'B'],
['G', 'C', 'S', 'V', 'P', 'A'],
['H', 'I', 'S', 'E', 'R', 'N'],
['A', 'I', 'O', 'B', 'M', 'C'],
['T', 'I', 'V', 'E', 'N', 'G'],
['M', 'O', 'V', 'D', 'I', 'T'],
['V', 'N', 'D', 'Z', 'A', 'E'],
['O', 'A', 'A', 'I', 'E', 'T'],
['F', 'R', 'I', 'P', 'A', 'G'],
['M', 'L', 'R', 'C', 'O', 'I'],
['O', 'N', 'F', 'E', 'B', 'L'],
['L', 'O', 'C', 'I', 'D', 'M'],
['T', 'B', 'R', 'L', 'I', 'A'],
['C', 'F', 'A', 'R', 'O', 'I'],
['N', 'U', 'E', 'O', 'C', 'T'],
['L', 'E', 'P', 'U', 'S', 'T'],
['N', 'O', 'D', 'E', 'S', 'T'],
['A', 'I', 'O', 'S', 'M', 'R'],
['T', 'G', 'C', 'A', 'P', 'I'],
['L', 'A', 'R', 'E', 'S', 'C'],
['A', 'B', 'O', 'O', 'Qu', 'M'],
['G', 'U', 'E', 'O', 'N', 'L'],
['C', 'D', 'P', 'M', 'A', 'E'],
['R', 'O', 'E', 'L', 'U', 'I'],
['H', 'I', 'F', 'E', 'I', 'E'],
]
@result = []
roll: ->
for roll in @dices.randomize()
dice = roll.randomize()
@result.push dice[0]
@result
b = new Boggle
result = b.roll()
for i in [0..4]
console.log result[(i*5)..((5*(i+1))-1)].join('')
class Array
def randomize
duplicated_original, new_array = self.dup, self.class.new
new_array << duplicated_original.slice!(rand(duplicated_original.size)) until new_array.size.eql?(self.size)
new_array
end
def randomize!
self.replace(randomize)
end
end
dices = [
%w(A Z F S Qu B),
%w(G C S V P A),
%w(H I S E R N),
%w(A I O B M C),
%w(T I V E N G),
%w(M O V D I T),
%w(V N D Z A E),
%w(O A A I E T),
%w(F R I P A G),
%w(M L R C O I),
%w(O N F E B L),
%w(L O C I D M),
%w(T B R L I A),
%w(C F A R O I),
%w(N U E O C T),
%w(L E P U S T),
%w(N O D E S T),
%w(A I O S M R),
%w(T G C A P I),
%w(L A R E S C),
%w(A B O O Qu M),
%w(G U E O N L),
%w(C D P M A E),
%w(R O E L U I),
%w(H I F E I E),
]
dices.randomize!.each_with_index do |dice, i|
dice.randomize!
print dice[0]
puts '' if (i+1)%5 == 0
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment