Skip to content

Commit

Permalink
making jshint happy
Browse files Browse the repository at this point in the history
  • Loading branch information
julienmoumne committed Oct 6, 2016
1 parent 03164ed commit 8d7231d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
2 changes: 2 additions & 0 deletions hs.js
Expand Up @@ -2,8 +2,10 @@ item({desc: 'rx-training-games'}, function () {
item({key: 'i', cmd'sudo npm install'})
item({key: 'd', desc: 'dev mode build & run', cmd'npm start'})
item({key: 'p', desc: 'prod mode build & run', cmd'npm run start:prod'})
item({key: 'l', cmd'npm run lint'})
item({key: 'g', desc: 'generate gh-pages' + '\n ', cmd: script(
'set -eu',
'npm run lint',
'git checkout gh-pages',
'git merge master -m "Merge branch \'master\' into gh-pages"',
'npm run build:prod',
Expand Down
20 changes: 10 additions & 10 deletions js/samples/langton-ant/langton-ant.js
@@ -1,13 +1,13 @@
var squareSize = 4, antPulse = 1
var squareSize = 4, antPulse = 1;

api.initGrid({squareSize: squareSize})
api.initGrid({squareSize: squareSize});

var boardLayer = api.addLayer({color: '#337ab7'}), antLayer = api.addLayer({color: '#275b8c'})
var boardLayer = api.addLayer({color: '#337ab7'}), antLayer = api.addLayer({color: '#275b8c'});

// place the ant in the middle of the board
antLayer.fill({x: api.gameSize / 2, y: api.gameSize / 2})
antLayer.fill({x: api.gameSize / 2, y: api.gameSize / 2});

var pulse = Rx.Observable.interval(antPulse).share()
var pulse = Rx.Observable.interval(antPulse).share();

// is the ant walking on an activated square?
var probes = pulse.map(() => antLayer.getActiveSquares()[0])
Expand All @@ -16,24 +16,24 @@ var probes = pulse.map(() => antLayer.getActiveSquares()[0])
active: boardLayer.getActiveSquares()
.find(boardSquare => boardSquare.x == antSquare.x && boardSquare.y == antSquare.y)
})
).share()
).share();

// http://javascript.about.com/od/problemsolving/a/modulobug.htm
var modulo = (n, m) => ((n % m) + m) % m
var modulo = (n, m) => ((n % m) + m) % m;

// determine next direction
var directions = probes.scan((acc, step) => modulo(acc + (step.active ? -1 : 1), 4), 0)
.map(directionIndex =>
[api.directions.Left, api.directions.Up,
api.directions.Right, api.directions.Down][directionIndex])
.map(direction => direction(antLayer.getActiveSquares()[0]))
.share()
.share();

// update ant's position
directions.do(antLayer.fill).subscribe(() => antLayer.clear(antLayer.getActiveSquares()[0]))
directions.do(antLayer.fill).subscribe(() => antLayer.clear(antLayer.getActiveSquares()[0]));

// switch color of square left behind
probes.subscribe(step => (step.active ? boardLayer.clear : boardLayer.fill)(step.coord))
probes.subscribe(step => (step.active ? boardLayer.clear : boardLayer.fill)(step.coord));

// handle end of 'game'
directions.where(api.isOffLimits).subscribe(api.gameOver);
Expand Down

0 comments on commit 8d7231d

Please sign in to comment.