Skip to content

Commit

Permalink
Tak squad mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Petah committed Sep 3, 2020
1 parent 8b1ad95 commit 6275b15
Show file tree
Hide file tree
Showing 9 changed files with 2,196 additions and 2,093 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ dist/**/*.js
dist/**/*.js.map
engine
engine2
games/**/*.json.gz
/env.json
22 changes: 19 additions & 3 deletions debug/debug-delete.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
<?php
$files = glob(__DIR__ . '/../games/*.json');
foreach ($files as $file) {
unlink($file);

function deleteDirectory($directory)
{
if (is_dir($directory)) {
$objects = scandir($directory);
foreach ($objects as $object) {
if ($object != '.' && $object != '..') {
if (is_dir($directory . DIRECTORY_SEPARATOR . $object) && !is_link($directory . DIRECTORY_SEPARATOR . $object)) {
deleteDirectory($directory . DIRECTORY_SEPARATOR . $object);
} else {
unlink($directory . DIRECTORY_SEPARATOR . $object);
}
}
}
rmdir($directory);
}
}

deleteDirectory(__DIR__ . '/../games/');

header('Location: debug.php');
6 changes: 3 additions & 3 deletions debug/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ body {
width: 100%;
height: 100%;
display: flex;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

pre {
Expand Down Expand Up @@ -55,8 +56,7 @@ pre {
}

.col {
border-top: 1px dashed #bbb;
border-left: 1px dashed #bbb;
border: 1px solid #bbb;
display: flex;
flex-direction: column;
flex: 1;
Expand Down Expand Up @@ -91,7 +91,7 @@ pre {
.snake {
flex: 1;
width: 100%;
border: 1px dotted #eee;
border: 1px solid #eee;
}

.weight {
Expand Down
2 changes: 0 additions & 2 deletions games/.gitignore

This file was deleted.

4,184 changes: 2,124 additions & 2,060 deletions package-lock.json

Large diffs are not rendered by default.

43 changes: 22 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,38 @@
"version": "0.0.0",
"private": true,
"dependencies": {
"body-parser": "^1.18.3",
"body-parser": "^1.19.0",
"crc-32": "^1.2.0",
"cross-env": "^5.2.0",
"express": "^4.16.4",
"morgan": "^1.9.1",
"cross-env": "^5.2.1",
"express": "^4.17.1",
"morgan": "^1.10.0",
"pathfinding": "git+https://github.com/paulrobello/PathFinding.js.git#3840d6e60b88a71c38ee5c356542b4a5883f3444",
"websocket": "^1.0.30"
"websocket": "^1.0.32"
},
"devDependencies": {
"@babel/core": "^7.3.4",
"@babel/preset-env": "^7.3.4",
"@types/angular": "^1.6.56",
"@types/express": "^4.16.1",
"@types/jquery": "^3.3.29",
"@types/node": "^11.9.5",
"@types/websocket": "^1.0.0",
"@babel/core": "^7.11.5",
"@babel/preset-env": "^7.11.5",
"@types/angular": "^1.7.2",
"@types/color": "^3.0.1",
"@types/express": "^4.17.8",
"@types/jquery": "^3.5.1",
"@types/node": "^11.15.21",
"@types/websocket": "^1.0.1",
"babelify": "^10.0.0",
"browserify": "^16.2.3",
"concurrently": "^5.0.0",
"browserify": "^16.5.2",
"color": "^3.1.2",
"concurrently": "^5.3.0",
"forever": "^0.15.3",
"gulp": "^4.0.0",
"gulp": "^4.0.2",
"gulp-babel": "^8.0.0",
"gulp-sourcemaps": "^2.6.5",
"gulp-typescript": "^5.0.0",
"gulp-uglify": "^3.0.1",
"gulp-typescript": "^5.0.1",
"gulp-uglify": "^3.0.2",
"gulplog": "^1.0.0",
"nodemon": "^1.18.10",
"ts-node": "^8.0.2",
"nodemon": "^1.19.4",
"ts-node": "^8.10.2",
"tslint": "^5.20.1",
"typescript": "^3.3.3333",
"typescript": "^3.9.7",
"vinyl-buffer": "^1.0.1",
"vinyl-source-stream": "^2.0.0"
},
Expand All @@ -53,4 +55,3 @@
]
}
}

12 changes: 11 additions & 1 deletion src/lib/isEnemy.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import { BTSnake } from '../types/BTData';

export function isEnemy(you: BTSnake, other: BTSnake) {
if (other.id == you.id || (you.squad && you.squad == other.squad)) {
if (you.id == other.id || (you.squad && you.squad == other.squad)) {
return false;
}
return true;
}

export function isSquad(you: BTSnake, other: BTSnake) {
if (you.id == other.id) {
return false;
}
if (you.squad && you.squad == other.squad) {
return true;
}
return false;
}
9 changes: 7 additions & 2 deletions src/lib/weight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { gridDistance } from './gridDistance';
import { BTData } from '../types/BTData';
import { isFree } from './isFree';
import { cache } from './cache';
import { isEnemy, isSquad } from './isEnemy';

export const BLOCKED_THRESHOLD = 10;

Expand Down Expand Up @@ -100,7 +101,7 @@ const isNearTail = (data: BTData, x: number, y: number) => {
export function weight(data: BTData, x: number, y: number, blockHeads = true) {
if (data.grid[y][x].weight === undefined) {
data.grid[y][x].weight = computeWeight(data, x, y, blockHeads);
let color = (data.grid[y][x].weight) / 100 * 255;
let color = Math.round((data.grid[y][x].weight) / 100 * 255);
data.grid[y][x].color = `rgba(${color}, ${color}, ${color}, 1)`;
}
return data.grid[y][x].weight;
Expand All @@ -120,6 +121,10 @@ function computeWeight(data: BTData, x: number, y: number, blockHeads = true) {
if (p === 0 && !blockHeads) {
continue;
}
// Check squad mode
if (isSquad(data.you, snake)) {
continue;
}
return 0;
}
}
Expand Down Expand Up @@ -180,7 +185,7 @@ function computeWeight(data: BTData, x: number, y: number, blockHeads = true) {
}
}


// Borders
if (x == 0) {
result = Math.min(result, 35);
}
Expand Down
10 changes: 9 additions & 1 deletion src/web/grid.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { BTData, initBTData } from '../types/BTData';
import snakes from "../server/snakes";
import { invertColor } from '../lib/invertColor';
import * as Color from 'color';

export interface MoveData {
body: BTData,
Expand Down Expand Up @@ -37,6 +38,7 @@ export function loadGrid(moveJson) {
const gridCell = moveJson.body.grid ? moveJson.body.grid[y][x] : {};
const col = $('<div>').addClass('col').css({
backgroundColor: gridCell.color || '#000000',
borderColor: new Color(gridCell.color || '#000000').darken(0.2).hex(),
}).appendTo(row);
const cellData = [];
cellData.push(x + '/' + y);
Expand All @@ -56,11 +58,17 @@ export function loadGrid(moveJson) {
$('<div>').addClass('food').appendTo(col);
}
for (const snake of moveJson.body.board.snakes) {
const color = snake.id == moveJson.body.you.id ? '#2ecc71' : '#e74c3c';
let color = '#e74c3c';
if (snake.id == moveJson.body.you.id) {
color = '#2ecc71';
} else if (moveJson.body.you.squad && moveJson.body.you.squad == snake.squad) {
color = '#3c69e7';
}
for (const [p, part] of snake.body.entries()) {
const col = getCol(part.x, part.y);
$('<div>').addClass('snake').css({
backgroundColor: color,
borderColor: new Color(color).darken(0.2).hex(),
borderRadius: p == 0 ? 100 : 0,
}).text(' ').appendTo(col);
}
Expand Down

0 comments on commit 6275b15

Please sign in to comment.