diff options
| author | a14m <[email protected]> | 2020-11-30 12:05:07 +0100 |
|---|---|---|
| committer | a14m <[email protected]> | 2020-11-30 12:05:07 +0100 |
| commit | 55dabbb7c98d9ded2bf94b8e3c81f6baa9806449 (patch) | |
| tree | dc9a020660340263e0cf2e89871f5c786fd39e02 /CLI/ruby | |
| parent | bb03e493c2d29e8ba01061331b034a3f4f6648a3 (diff) | |
Add the x,y position to the cell attributes
Diffstat (limited to 'CLI/ruby')
| -rw-r--r-- | CLI/ruby/lib/game_of_life/cell.rb | 8 | ||||
| -rw-r--r-- | CLI/ruby/lib/game_of_life/generators/input.rb | 4 |
2 files changed, 8 insertions, 4 deletions
diff --git a/CLI/ruby/lib/game_of_life/cell.rb b/CLI/ruby/lib/game_of_life/cell.rb index 5fc527e..19a48e0 100644 --- a/CLI/ruby/lib/game_of_life/cell.rb +++ b/CLI/ruby/lib/game_of_life/cell.rb @@ -2,12 +2,16 @@ module GameOfLife class Cell - attr_accessor :alive + attr_accessor :alive, :pos_x, :pos_y # Initialize a cell in the game of life universe # @param alive [True|False] boolean indicating if the cell is considered alive - def initialize(alive:) + # @param pos_x [Integer] the x position on the cyclic universe plane + # @param pos_y [Integer] the y position on the cyclic universe plane + def initialize(alive:, pos_x:, pos_y:) @alive = alive + @pos_x = pos_x + @pos_y = pos_y end # Representation of a cell diff --git a/CLI/ruby/lib/game_of_life/generators/input.rb b/CLI/ruby/lib/game_of_life/generators/input.rb index 7a255fd..cbde075 100644 --- a/CLI/ruby/lib/game_of_life/generators/input.rb +++ b/CLI/ruby/lib/game_of_life/generators/input.rb @@ -34,8 +34,8 @@ module GameOfLife universe = GameOfLife::Universe.new(height: height, width: width) (0...height).each do |i| (0...width).each do |j| - cell = ::GameOfLife::Cell.new(alive: parsed_input.fetch(i, nil)&.fetch(j, nil)) - universe[i][j] = cell + cell = { pos_x: j, pos_y: i, alive: parsed_input.fetch(i, nil)&.fetch(j, nil) } + universe[i][j] = ::GameOfLife::Cell.new(cell) end end universe |
