Skip to content

Instantly share code, notes, and snippets.

@alex-wilmer
Created June 17, 2014 00:28
Show Gist options
  • Save alex-wilmer/2c4c43b21468198dec8c to your computer and use it in GitHub Desktop.
Save alex-wilmer/2c4c43b21468198dec8c to your computer and use it in GitHub Desktop.
window.angular.module('go.controllers.index', [])
.controller('IndexController', ['$scope', 'Global',
function ($scope, Global) {
$scope.global = Global;
rows = 6;
cols = 6;
$scope.board = matrix(rows, cols);
$scope.player = "black";
$scope.move = function (cell, col, row) {
if (cell.color == "empty") {
cell.color = $scope.player;
$scope.player = $scope.player == "white" ? "black" : "white";
}
}
}]);
function matrix(rows, cols) {
var arr = [];
var id = 0;
var libs;
for(var i=0; i < rows; i++){
arr.push([]);
arr[i].push(new Array(cols));
for(var j=0; j < cols; j++) {
if ((i==0 && j==0) ||
(i==cols-1 && j==cols-1) ||
(i==0 && j==cols-1) ||
(i==cols-1 && j==0)) {
libs = 2;
} else if ((i==0 || j==0) ||
(i==cols-1 || j==cols-1)) {
libs = 3;
} else {
libs = 4;
}
arr[i][j] = {color:"empty", liberties:libs, chainId:0, id:id};
id++;
}
}
return arr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment