Browse files

wip

  • Loading branch information...
1 parent 8e74339 commit 3b39703c597d17dbaa64d3c8f1a0798410c7ec8d @haru01 committed May 3, 2012
Showing with 14 additions and 6 deletions.
  1. +10 −5 src/lifegame.coffee
  2. +4 −1 test/lifegame_spec.coffee
View
15 src/lifegame.coffee
@@ -7,21 +7,26 @@ class Space
nextTime: ->
nextCells = []
- for row, y in @cells
+ for row, ri in @cells
+ # console.log "#{row}, #{y}"
nextRows = []
nextCells.push nextRows
- for node, x in row
+ for node, ci in row
# fake it
- if @isBirthCase(x, y)
+ if @isBirthCase(ri, ci)
nextRows.push ALIVE
else
nextRows.push node
new Space nextCells
- isBirthCase: ->
- #fake it
+ isBirthCase: (r, c) ->
+ return false if @cells[r][c] is ALIVE
+ return false unless @countAlive(r, c) is 3
true
+ countAlive: (r, c) ->
+ # fake it
+ 3
exports = {} unless exports
View
5 test/lifegame_spec.coffee
@@ -17,4 +17,7 @@ suite 'Life Game', ->
suite 'isBirthCase(x,y)', ->
test '誕生ケースは trueを返すこと', ->
- expect( birthSpace().isBirthCase(1,1) ).to.be.true
+ expect( birthSpace().isBirthCase(1,1) ).to.be true
+ test '誕生ケースでない場合は、 falseを返すこと', ->
+ expect( birthSpace().isBirthCase(0,0) ).to.be false
+ # expect( birthSpace().isBirthCase(1,0) ).to.be false

0 comments on commit 3b39703

Please sign in to comment.