Sha256: 72c4ef3726540d336b3272aaf1dfbd8fc60a3f01566cdc63ca8c42e8dc7851b0
Contents?: true
Size: 888 Bytes
Versions: 3
Compression:
Stored size: 888 Bytes
Contents
module WordSearch module ThreeDimensional class Generator < Generator::Base def directions Direction.values.shuffle.map do |direction| Point.new(direction.first, direction.second, direction.third) end end private def place_word(word) placed = false until placed || used_coordinates.uniq.count == plane.total_points placed = position_word(word).present? end word_bank.errors.add(word, 'cannot be placed') if placed.blank? placed end def position_word(word) used_coordinates << (coordinate = random_point) directions.find do |direction| PositionWord.new(plane, word, direction, coordinate).perform end end def random_point Point.new(random(plane.x), random(plane.y), random(plane.z)) end end end end
Version data entries
3 entries across 3 versions & 1 rubygems