-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c791786
commit 58781a6
Showing
4 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Inspired by Conway's 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
function handle_record(record) | ||
end | ||
|
||
function complete(result) | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
SELECT DISTINCT ACCOUNTID, TOACCOUNTID | ||
FROM CHECKINGACCOUNT_V1 | ||
WHERE TRANSCODE = 'Transfer'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<script> | ||
var Game = function() { | ||
this.set = {}; | ||
|
||
var gamestateFromSet = function(set) { | ||
var gamestate = {}; | ||
|
||
|
||
for (var cell in set) { | ||
|
||
var a = neighboursOf(cell); | ||
a.forEach(function(n) { | ||
if (!gamestate[n]) gamestate[n] = 0 | ||
gamestate[n] += 1 | ||
}) | ||
}; | ||
|
||
return gamestate; | ||
} | ||
|
||
var neighboursOf = function(cell) { | ||
var cell = cell.split(','), x = parseInt(cell[0]), y = parseInt(cell[1]); | ||
return [[x-1, y-1], [x-1, y], [x-1, y+1], [x, y-1], [x, y+1], [x+1, y-1], [x+1, y], [x+1, y+1]] | ||
} | ||
|
||
this.add = function(cell) { | ||
this.set[cell] = true; | ||
} | ||
|
||
this.isAlive = function(cell) { | ||
return this.set[cell]; | ||
} | ||
|
||
this.tick = function() { | ||
nextGen = {}; | ||
|
||
var gamestate = gamestateFromSet(this.set); | ||
|
||
for (cell in gamestate) { | ||
|
||
var count = gamestate[cell]; | ||
|
||
if (count == 3) { | ||
nextGen[cell] = true; | ||
} | ||
else if (count == 2 && this.set[cell]) { | ||
nextGen[cell] = true; | ||
} | ||
} | ||
|
||
this.set = nextGen; | ||
} | ||
} | ||
</script> | ||
|
||
|
||
<pre id="board"> | ||
|
||
</pre> | ||
|
||
<script type="text/javascript"> | ||
|
||
game = new Game() | ||
|
||
<TMPL_LOOP NAME=CONTENTS> | ||
game.add([<TMPL_VAR ACCOUNTID>, <TMPL_VAR TOACCOUNTID>]) | ||
game.add([<TMPL_VAR TOACCOUNTID>, <TMPL_VAR ACCOUNTID>]) | ||
</TMPL_LOOP> | ||
|
||
game.tick() | ||
|
||
|
||
var board = document.getElementsByTagName("pre")[0]; | ||
|
||
function draw() { | ||
var s = '' | ||
for (var x = 0; x < 30; x++) { | ||
for (var y = 0; y < 100; y++) { | ||
s += game.isAlive([x,y]) ? 'o' : '.'; | ||
} | ||
s += "\n"; | ||
} | ||
board.innerHTML = s; | ||
} | ||
|
||
setInterval(function() { game.tick(); draw(); } , 500); | ||
|
||
</script> |