Skip to content

Instantly share code, notes, and snippets.

@liammclennan
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liammclennan/56466b18014aeb2e530a to your computer and use it in GitHub Desktop.
Save liammclennan/56466b18014aeb2e530a to your computer and use it in GitHub Desktop.
Typescript game of life
// 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