rename GRID_SIZE -> GRID_COUNT

This commit is contained in:
StevenJoeZhang 2019-02-22 01:39:14 +08:00
parent 2cf9221ac2
commit df1dfa3062
11 changed files with 38 additions and 35 deletions

View File

@ -20,7 +20,7 @@ After cloning this repository, run the follow commands to install dependencies a
npm start
```
You can configure the game by editing `config.json`. Remember: DO NOT EDIT THE `consts` SETTINGS UNLESS YOU KNOW WHAT YOU ARE DOING.
You can configure the game by editing `config.json`. WARNING: DO NOT EDIT THE `consts` SETTINGS UNLESS YOU KNOW WHAT YOU ARE DOING.
## Bots

View File

@ -4,11 +4,11 @@
"ws_port": 8081,
"bots": [],
"consts": {
"GRID_SIZE": 80,
"GRID_COUNT": 100,
"CELL_WIDTH": 40,
"SPEED": 5,
"BORDER_WIDTH": 20,
"MAX_PLAYERS": 81,
"MAX_PLAYERS": 30,
"PREFIXES": "Angry Baby Crazy Diligent Excited Fat Greedy Hungry Interesting Japanese Kind Little Magic Naïve Old Powerful Quiet Rich Superman THU Undefined Valuable Wifeless Xiangbuchulai Young Zombie",
"NAMES": "Alice Bob Carol Dave Eve Francis Grace Hans Isabella Jason Kate Louis Margaret Nathan Olivia Paul Queen Richard Susan Thomas Uma Vivian Winnie Xander Yasmine Zach"
}

File diff suppressed because one or more lines are too long

View File

@ -30,7 +30,10 @@
<input id="name" autocomplete="off" placeholder="An awesome name!"/>
<input id="start" type="button" value="Play!" disabled="disabled"/>
<div>
<small id="error">Your browser does not support JavaScript!</small>
<small id="error">Please wait... Maybe something's wrong!</small>
<noscript>
<small>Your browser does not support JavaScript!</small>
</noscript>
</div>
</div>
</div>

View File

@ -132,6 +132,6 @@ input[type=button]:active {
input[type=button]:disabled {
cursor: not-allowed;
}
#error {
small {
color: red;
}

View File

@ -49,7 +49,7 @@ var DIST_TYPES = {
}
}, edge: {
check: function(loc) {
return loc.row <= 1 || loc.col <= 1 || loc.row >= consts.GRID_SIZE - 1 || loc.col >= consts.GRID_SIZE - 1
return loc.row <= 1 || loc.col <= 1 || loc.row >= consts.GRID_COUNT - 1 || loc.col >= consts.GRID_COUNT - 1
},
coeff: function() {
return coeffs[4];
@ -122,7 +122,7 @@ function tail(player, loc) {
}
function traverseGrid(dir) {
steps = new Array(consts.GRID_SIZE * consts.GRID_SIZE);
steps = new Array(consts.GRID_COUNT * consts.GRID_COUNT);
for (var i in steps) {
steps[i] = -1;
}
@ -133,8 +133,8 @@ function traverseGrid(dir) {
}
var row = user.row, col = user.col;
var minRow = Math.max(0, row - 10), maxRow = Math.min(consts.GRID_SIZE, row + 10);
var minCol = Math.max(0, col - 10), maxCol = Math.min(consts.GRID_SIZE, col + 10);
var minRow = Math.max(0, row - 10), maxRow = Math.min(consts.GRID_COUNT, row + 10);
var minCol = Math.max(0, col - 10), maxCol = Math.min(consts.GRID_COUNT, col + 10);
var proj = 0;
for (var i = 1; i >= -1; i-=2) {
@ -152,7 +152,7 @@ function traverseGrid(dir) {
loc.row += user.row;
loc.col += user.col;
if (loc.row < 0 || loc.row >= consts.GRID_SIZE || loc.col < 0 || loc.col >= consts.GRID_SIZE) continue;
if (loc.row < 0 || loc.row >= consts.GRID_COUNT || loc.col < 0 || loc.col >= consts.GRID_COUNT) continue;
if (DIST_TYPES[distType].check(loc)) distWeights[distType] += dist;
}
}
@ -162,9 +162,9 @@ function traverseGrid(dir) {
}
function printGrid() {
var chars = new core.Grid(consts.GRID_SIZE);
for (var r = 0; r < consts.GRID_SIZE; r++) {
for (var c = 0; c < consts.GRID_SIZE; c++) {
var chars = new core.Grid(consts.GRID_COUNT);
for (var r = 0; r < consts.GRID_COUNT; r++) {
for (var c = 0; c < consts.GRID_COUNT; c++) {
if (tail(user, {row: r, col: c})) chars.set(r, c, "t");
else {
var owner = grid.get(r, c);
@ -179,9 +179,9 @@ function printGrid() {
chars.set(user.row, user.col, "^>V<"[user.currentHeading]);
var str = "";
for (var r = 0; r < consts.GRID_SIZE; r++) {
for (var r = 0; r < consts.GRID_COUNT; r++) {
str += "\n";
for (var c = 0; c < consts.GRID_SIZE; c++) {
for (var c = 0; c < consts.GRID_COUNT; c++) {
str += chars.get(r, c);
}
}

View File

@ -258,7 +258,7 @@ function floodFill(data, grid, row, col, been) {
if (grid.isOutOfBounds(row, col) || been.get(row, col) || onTail(start) || grid.get(row, col) === data.player) return;
//Avoid allocating too many resources
var coords = [];
var filled = new Stack(consts.GRID_SIZE * consts.GRID_SIZE + 1);
var filled = new Stack(consts.GRID_COUNT * consts.GRID_COUNT + 1);
var surrounded = true;
coords.push(start);

View File

@ -11,7 +11,7 @@ var deadFrames = 0;
var requesting = -1; //frame that we are requesting at
var frameCache = []; //Frames after our request
var allowAnimation = true;
var grid = new core.Grid(consts.GRID_SIZE, function(row, col, before, after) {
var grid = new core.Grid(consts.GRID_COUNT, function(row, col, before, after) {
invokeRenderer("updateGrid", [row, col, before, after]);
});

View File

@ -33,11 +33,11 @@ function Game(id) {
var frameLocs = [];
var frame = 0;
var filled = 0;
var grid = new core.Grid(consts.GRID_SIZE, function(row, col, before, after) {
var grid = new core.Grid(consts.GRID_COUNT, function(row, col, before, after) {
if (!!after ^ !!before) {
if (after) filled++;
else filled--;
if (filled === consts.GRID_SIZE * consts.GRID_SIZE) log("FULL GAME");
if (filled === consts.GRID_COUNT * consts.GRID_COUNT) log("FULL GAME");
}
});
this.id = id;

View File

@ -13,7 +13,8 @@ var MIN_BAR_WIDTH = 65;
var BAR_HEIGHT = SHADOW_OFFSET + consts.CELL_WIDTH;
var BAR_WIDTH = 400;
var canvas, canvasWidth, canvasHeight, gameWidth, gameHeight, ctx, offctx, offscreenCanvas;
var canvas, ctx, offscreenCanvas, offctx,
canvasWidth, canvasHeight, gameWidth, gameHeight;
$(function() {
canvas = $("#main-ui")[0];
@ -42,7 +43,7 @@ function updateSize() {
}
function reset() {
animateGrid = new core.Grid(consts.GRID_SIZE);
animateGrid = new core.Grid(consts.GRID_COUNT);
playerPortion = [];
portionsRolling = [];
barProportionRolling = [];
@ -58,7 +59,7 @@ reset();
//Paint methods
function paintGridBorder(ctx) {
ctx.fillStyle = "lightgray";
var gridWidth = consts.CELL_WIDTH * consts.GRID_SIZE;
var gridWidth = consts.CELL_WIDTH * consts.GRID_COUNT;
ctx.fillRect(-consts.BORDER_WIDTH, 0, consts.BORDER_WIDTH, gridWidth);
ctx.fillRect(-consts.BORDER_WIDTH, -consts.BORDER_WIDTH, gridWidth + consts.BORDER_WIDTH * 2, consts.BORDER_WIDTH);
@ -69,7 +70,7 @@ function paintGridBorder(ctx) {
function paintGrid(ctx) {
//Paint background
ctx.fillStyle = "rgb(211, 225, 237)";
ctx.fillRect(0, 0, consts.CELL_WIDTH * consts.GRID_SIZE, consts.CELL_WIDTH * consts.GRID_SIZE);
ctx.fillRect(0, 0, consts.CELL_WIDTH * consts.GRID_COUNT, consts.CELL_WIDTH * consts.GRID_COUNT);
paintGridBorder(ctx);
//paintGridLines(ctx);
@ -86,7 +87,7 @@ function paintGrid(ctx) {
for (var c = minCol; c < maxCol; c++) {
var p = grid.get(r, c);
var x = c * consts.CELL_WIDTH, y = r * consts.CELL_WIDTH, baseColor, shadowColor;
var animateSpec = animateGrid.get(r, c);
var animateSpec = animateGrid.get(r, c);
if (client.allowAnimation && animateSpec) {
if (animateSpec.before) { //fading animation
var frac = (animateSpec.frame / ANIMATE_FRAMES);
@ -101,11 +102,10 @@ function paintGrid(ctx) {
shadowColor = p.shadowColor;
}
else continue; //No animation nor is this player owned
var hasBottom = !grid.isOutOfBounds(r + 1, c);
var hasBottom = !grid.isOutOfBounds(r + 1, c);
var bottomAnimate = hasBottom && animateGrid.get(r + 1, c);
var totalStatic = !bottomAnimate && !animateSpec;
var bottomEmpty = totalStatic ? (hasBottom && !grid.get(r + 1, c)) :
(!bottomAnimate || (bottomAnimate.after && bottomAnimate.before));
var bottomEmpty = totalStatic ? (hasBottom && !grid.get(r + 1, c)) : (!bottomAnimate || (bottomAnimate.after && bottomAnimate.before));
if (hasBottom && ((!!bottomAnimate ^ !!animateSpec) || bottomEmpty)) {
ctx.fillStyle = shadowColor.rgbString();
ctx.fillRect(x, y + consts.CELL_WIDTH, consts.CELL_WIDTH + 1, SHADOW_OFFSET);
@ -225,7 +225,7 @@ function paintUIBar(ctx) {
}
function paint(ctx) {
ctx.fillStyle = "#e2ebf3"; //"whitesmoke";
ctx.fillStyle = "#e2ebf3"; //"whitesmoke";
ctx.fillRect(0, 0, canvasWidth, canvasHeight);
//Move grid to viewport as said with the offsets, below the stats
@ -281,7 +281,7 @@ function update() {
//Calculate player portions
client.getPlayers().forEach(function(player) {
var roll = portionsRolling[player.num];
roll.value = playerPortion[player.num] / consts.GRID_SIZE / consts.GRID_SIZE;
roll.value = playerPortion[player.num] / consts.GRID_COUNT / consts.GRID_COUNT;
roll.update();
});
@ -340,7 +340,7 @@ function Rolling(value, frames) {
module.exports = exports = {
addPlayer: function(player) {
playerPortion[player.num] = 0;
portionsRolling[player.num] = new Rolling(9 / consts.GRID_SIZE / consts.GRID_SIZE, ANIMATE_FRAMES);
portionsRolling[player.num] = new Rolling(9 / consts.GRID_COUNT / consts.GRID_COUNT, ANIMATE_FRAMES);
barProportionRolling[player.num] = new Rolling(0, ANIMATE_FRAMES);
},
disconnect: function() {

View File

@ -49,9 +49,9 @@ function update(frame) {
//the original code (i.e. deobfuscating) and made more efficient in some
//areas (and some tweaks), otherwise, the original logic is about the same.
var row = user.row, col = user.col, dir = user.currentHeading;
var thres = (.05 + .1 * Math.random()) * consts.GRID_SIZE * consts.GRID_SIZE;
var thres = (.05 + .1 * Math.random()) * consts.GRID_COUNT * consts.GRID_COUNT;
if (row < 0 || col < 0 || row >= consts.GRID_SIZE || col >= consts.GRID_SIZE) return;
if (row < 0 || col < 0 || row >= consts.GRID_COUNT || col >= consts.GRID_COUNT) return;
if (grid.get(row, col) === user) {
//When we are inside our territory
@ -65,7 +65,7 @@ function update(frame) {
var nr = MOVES[nd][0] * S + row;
var nc = MOVES[nd][1] * S + col;
if (nr < 0 || nc < 0 || nr >= consts.GRID_SIZE || nc >= consts.GRID_SIZE) {
if (nr < 0 || nc < 0 || nr >= consts.GRID_COUNT || nc >= consts.GRID_COUNT) {
if (S > 1) weights[nd]--;
else weights[nd] = -9999;
}
@ -131,7 +131,7 @@ function update(frame) {
var nr = MOVES[nd][0] * S + row;
var nc = MOVES[nd][1] * S + col;
if (nr < 0 || nc < 0 || nr >= consts.GRID_SIZE || nc >= consts.GRID_SIZE) {
if (nr < 0 || nc < 0 || nr >= consts.GRID_COUNT || nc >= consts.GRID_COUNT) {
if (S > 1) weights[nd]--;
else weights[nd] = -9999;
}