Sonntag, 15. Dezember 2013

Life after Coderetreat 2013

Last Saturday I was on Coderetreat 2013 in Vienna. There we tried to implement rules of Conway's Game of Life. During the day I've got a lot of experience in TDD, pair programming and languages I haven't used for a while. One thing I've missed was final implementation of game.

One day after the event I've tried some ideas I'd got before. I've pushed my own implementation of game in my Github repository and created an instance of server on Heroku.

I've used Play Framework with Scala and tried to implement rules in functional way.

The idea was to represent the state of space as a function:

 type GameState = (Int, Int) => Boolean  

Initial state in that case may be represented by following implementation for one-cell space:

 val initial: GameState = (x: Int, y: Int) => x == 1 || y == 1  

Transformation from previous state to next state has to be implemented as following function:

 def transform(state: GameState): GameState

One thing I didn't take into attention was that complexity of calculation state of cell will be equal Nth power of 9 after N iterations. As the result it will fail after a very few steps.

I was totally disappointed with this approach and as workaround I added one more step after each transformation - I persist a state of fixed area of space using function with following signature:

 def persist(state: GameState, upperLeft: (Int, Int), lowerRight: (Int, Int)): GameState  

As the result I've got working implementation of game, but not in infinite space.



Keine Kommentare:

Kommentar veröffentlichen