Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added some tests for the cell and for the conways class also, put eve…
…rything in namespace etc
- Loading branch information
Showing
7 changed files
with
281 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,30 +1,35 @@ | |||
class Cell | module Conways | ||
class << self | class Cell | ||
def live | LIVE = 1 | ||
1 | DEAD = 0 | ||
end | class << self | ||
def live_one | |||
Cell.new Cell::LIVE | |||
end | |||
|
|
||
def dead | def dead_one | ||
0 | Cell.new Cell::DEAD | ||
end | end | ||
end | end | ||
|
|
||
attr_accessor :neighbours, :state, :next_state, :previous_state | attr_accessor :state, :next_state | ||
def initialize(state) | def initialize(state) | ||
@state = state | raise "Cell must be live or dead" unless state == Cell::LIVE || state == Cell::DEAD | ||
@next_state = nil | @state = state | ||
end | @next_state = nil | ||
end | |||
|
|
||
def live? | def live? | ||
@state == Cell.live | @state == Cell::LIVE | ||
end | end | ||
|
|
||
def dead? | def dead? | ||
@state == Cell.dead | @state == Cell::DEAD | ||
end | end | ||
|
|
||
def update_to_next_generation_state | def move_to_next_state | ||
@state = @next_state | @state = @next_state | ||
@next_state = nil | @next_state = nil | ||
end | end | ||
end | |||
end | end |
Oops, something went wrong.