Sha256: b13f9e5dc44f3f0976e3914771d7af0fe2ff18da3bb00e4129a8fdf917d3e900

Contents?: true

Size: 649 Bytes

Versions: 1

Compression:

Stored size: 649 Bytes

Contents

require 'Matrix'

class GameCreator
  def self.create_new_game
    positions = random_positions(9)
    create_matrix(positions)
  end

  def self.create_matrix(positions)
    rows = []
    4.times {
      rows << [0,0,0,0]
    }
    positions.each {|position|
      rows[position[0]][position[1]] = rand(1..3)
    }
    Matrix.rows(rows)
  end

  def self.random_positions(number_of_positions)
    positions = []
    while (positions.length < number_of_positions)
      candidate_position = [rand(0..3), rand(0..3)]
      unless positions.include?(candidate_position)
        positions << candidate_position
      end
    end
    positions
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
threesmodel-0.0.3 lib/game_creator.rb