class TwentyFortyEight::Board
Constants
- DEFAULTS
Attributes
board[R]
settings[R]
Public Class Methods
new(opts = {})
click to toggle source
# File lib/TwentyFortyEight/board.rb, line 9 def initialize(opts = {}) opts = Options.new DEFAULTS.merge(opts) @settings = opts @settings[:size] = settings.board.size if settings.board? @board = settings.board || Board.generate(settings) end
Private Class Methods
generate(opts_hsh, **opts)
click to toggle source
# File lib/TwentyFortyEight/board.rb, line 50 def self.generate(opts_hsh, **opts) opts = opts_hsh.merge opts Array.new(opts.size) { Array.new(opts.size) { opts.fill } } end
Public Instance Methods
dup()
click to toggle source
# File lib/TwentyFortyEight/board.rb, line 44 def dup new settings.merge(board: board.dup) end
empty_cells()
click to toggle source
# File lib/TwentyFortyEight/board.rb, line 36 def empty_cells board.each_with_index.map do |col, y| col.each_with_index.map do |val, x| { x: x, y: y } if settings.empty? val end.compact end.flatten end
full?()
click to toggle source
# File lib/TwentyFortyEight/board.rb, line 28 def full? empty_cells.empty? end
replace!(board_arr)
click to toggle source
# File lib/TwentyFortyEight/board.rb, line 24 def replace!(board_arr) @board = board_arr end
set!(value, **opts)
click to toggle source
# File lib/TwentyFortyEight/board.rb, line 16 def set!(value, **opts) @board[opts[:y]][opts[:x]] = value if opts[:x] && opts[:y] end
to_a()
click to toggle source
# File lib/TwentyFortyEight/board.rb, line 32 def to_a board end
transpose!()
click to toggle source
# File lib/TwentyFortyEight/board.rb, line 20 def transpose! replace! board.transpose end