Created
June 17, 2014 00:28
-
-
Save alex-wilmer/2c4c43b21468198dec8c to your computer and use it in GitHub Desktop.
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
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