Skip to content

Instantly share code, notes, and snippets.

@yoshitsugu
Last active December 20, 2015 11:09
Show Gist options
  • Select an option

  • Save yoshitsugu/6120933 to your computer and use it in GitHub Desktop.

Select an option

Save yoshitsugu/6120933 to your computer and use it in GitHub Desktop.
dice
class Dice
attr_accessor :coords
def initialize
@coords = [[0,0,1],[1,0,0],[0,-1,0],[0,1,0],[-1,0,0],[0,0,-1]]
end
def top
@coords.each_with_index{|coord,i|
if coord == [0,0,1]
return i+1
end
}
end
def roll(s)
if s == "N" || s == "S"
@coords.each{|coord|
tmp = coord.clone
coord[0] = tmp[2]
coord[0] *= -1 if s == "S"
coord[2] = tmp[0]
coord[2] *= -1 if s == "N"
}
end
if s == "W" || s == "E"
@coords.each{|coord|
tmp = coord.clone
coord[1] = tmp[2]
coord[1] *= -1 if s == "W"
coord[2] = tmp[1]
coord[2] *= -1 if s == "E"
}
end
top
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment