|
|
|
@ -22,23 +22,77 @@ Game.prototype.getPlayers = function() { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Game.prototype.getRobots = function() { |
|
|
|
|
return [ |
|
|
|
|
{i: 9, j: 9, color: '#E00000' }, |
|
|
|
|
{i: 18, j: 9, color: '#00C000' }, |
|
|
|
|
{i: 1, j: 9, color: '#0000FF' }, |
|
|
|
|
{i: 9, j: 18, color: '#00C0C0' }, |
|
|
|
|
{i: 9, j: 1, color: '#F000F0' }, |
|
|
|
|
]; |
|
|
|
|
const robots = ['#E00000', '#00C000', '#0000FF', '#00C0C0', '#F000F0']; |
|
|
|
|
const squaresPerSide = 20; |
|
|
|
|
const gen = () => Math.floor(Math.random() * squaresPerSide); |
|
|
|
|
|
|
|
|
|
// Leave here for testing.
|
|
|
|
|
// return [
|
|
|
|
|
// {i: 9, j: 9, color: '#E00000' },
|
|
|
|
|
// {i: 18, j: 9, color: '#00C000' },
|
|
|
|
|
// {i: 1, j: 9, color: '#0000FF' },
|
|
|
|
|
// {i: 9, j: 18, color: '#00C0C0' },
|
|
|
|
|
// {i: 9, j: 1, color: '#F000F0' },
|
|
|
|
|
// ];
|
|
|
|
|
|
|
|
|
|
return robots.map(color => ({ i: gen(), j: gen(), color })); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Game.prototype.getWalls = function() { |
|
|
|
|
// Edge IDs are of the form [i1-j1-i2-j2]. Top left is 0, 0.
|
|
|
|
|
return [ |
|
|
|
|
"1-9-1-10", |
|
|
|
|
"9-1-10-1", |
|
|
|
|
"9-19-10-19",
|
|
|
|
|
"19-9-19-10" |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
// Leave here for testing.
|
|
|
|
|
// return [
|
|
|
|
|
// "1-9-1-10",
|
|
|
|
|
// "9-1-10-1",
|
|
|
|
|
// "9-19-10-19",
|
|
|
|
|
// "19-9-19-10"
|
|
|
|
|
// ];
|
|
|
|
|
|
|
|
|
|
console.log("Generating walls."); |
|
|
|
|
|
|
|
|
|
// Squares per side has quadratic relationship with wall/corner requirements.
|
|
|
|
|
const squaresPerSide = 20; |
|
|
|
|
const numberOfCorners = Math.ceil(Math.pow((squaresPerSide / 10), 2)); |
|
|
|
|
const numberOfWalls = Math.ceil(Math.pow((squaresPerSide / 5), 2)); |
|
|
|
|
|
|
|
|
|
const gen = () => Math.floor(Math.random() * squaresPerSide + 1); |
|
|
|
|
const edges = []; |
|
|
|
|
|
|
|
|
|
// DO NUMBER OF CORNERS FIRST AFTER TESTING
|
|
|
|
|
for (let n = 0; n < numberOfWalls; n++) { |
|
|
|
|
const ri = gen(); |
|
|
|
|
const rj = gen(); |
|
|
|
|
|
|
|
|
|
const isHorizontal = Math.random() < 0.5; |
|
|
|
|
const isBackward = Math.random() < 0.5; |
|
|
|
|
|
|
|
|
|
let i1, j1, i2, j2; |
|
|
|
|
|
|
|
|
|
if (isHorizontal) { |
|
|
|
|
i1 = isBackward ? ri - 1 : ri; |
|
|
|
|
i2 = isBackward ? ri : ri + 1; |
|
|
|
|
|
|
|
|
|
j1 = rj; |
|
|
|
|
j2 = rj; |
|
|
|
|
} else { |
|
|
|
|
i1 = ri; |
|
|
|
|
i2 = ri; |
|
|
|
|
|
|
|
|
|
j1 = isBackward ? rj - 1 : rj; |
|
|
|
|
j2 = isBackward ? rj : rj + 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const edge = `${i1}-${j1}-${i2}-${j2}`; |
|
|
|
|
|
|
|
|
|
if (edges.includes(edge)) { |
|
|
|
|
n--; |
|
|
|
|
} else { |
|
|
|
|
edges.push(edge); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return edges; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
module.exports = Game; |