Last active
August 29, 2015 14:06
-
-
Save liammclennan/56466b18014aeb2e530a to your computer and use it in GitHub Desktop.
Typescript game of life
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
// start of a port of Ristretto/Coffeescript game of life to typescript | |
// http://withouttheloop.com/articles/2013-08-11-coffeescript-gameoflife-ristretto/ | |
class Cell { | |
constructor(public x: number, public y:number) {} | |
} | |
function isNeighbour(c:Cell, x:number, y:number): boolean { | |
return Math.abs(x-c.x) < 2 | |
&& Math.abs(y-c.y) < 2 | |
&& (!(x === c.x && y === c.y)) | |
} | |
function livingNeighbours(cs:Cell[], x:number, y:number): number { | |
return cs.filter(function (c) { | |
return isNeighbour(c, x, y); | |
}).length; | |
} | |
function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment