Skip to content

Commit

Permalink
saner (and faster) matrix creation in Tribo
Browse files Browse the repository at this point in the history
  • Loading branch information
Canop committed May 9, 2014
1 parent 5b1f524 commit f61e4dc
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions plugins/ludogene/client-scripts/Tribo.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
// A move is encoded in one character

var Tribo = (function(){

// returns a square matrix filled with the provided value
function matrix(s, v, c){
return (c=Array.apply(0,Array(s))).map(function(){ return c.map(function(){ return v }) });
function matrix(s, v){
var row = [], m = [];
for (var i=0; i<s; i++) row[i] = v;
for (var i=0; i<s; i++) m[i] = i ? row.slice() : row;
return m;
}

return {
// is the cell playable by p (assuming he's the current player) ?
canPlay: function(g, x, y, p) {
var c = g.cells;
if (c[x][y] != -1) return false;
if (c[x][y] !== -1) return false;
if ((x > 0 && c[x-1][y] == p) ||
(x < 9 && c[x+1][y] == p) ||
(y > 0 && c[x][y-1] == p) ||
Expand Down

0 comments on commit f61e4dc

Please sign in to comment.