Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/jladuval/clashjs
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Groom committed Sep 24, 2015
2 parents c38b43f + 76a5238 commit d032dde
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 18 deletions.
18 changes: 9 additions & 9 deletions src/players/rogue_shadow.js
Expand Up @@ -75,15 +75,6 @@ export default {
return 'north';
}
if (equal(corner, [12, 12])) {
if (me.direction === 'south') {
return 'west';
}
if (me.direction === 'west') {
return 'south';
}
return 'west';
}
if (equal(corner, [12, 0])) {
if (me.direction === 'north') {
return 'east';
}
Expand All @@ -92,6 +83,15 @@ export default {
}
return 'east';
}
if (equal(corner, [12, 0])) {
if (me.direction === 'south') {
return 'west';
}
if (me.direction === 'west') {
return 'south';
}
return 'west';
}

} else {
var direction = utils.fastGetDirection(me.position, corner);
Expand Down
39 changes: 34 additions & 5 deletions src/players/thor.js
@@ -1,4 +1,32 @@
var utils = require('../lib/utils.js');
var _ = require('lodash');

var goToClosestAmmo = function(playerState, enemiesStates, gameEnvironment) {
var closestAmmo = _.sortBy(gameEnvironment.ammoPosition, function(ammoPosition) {
return utils.getDistance(playerState.position, ammoPosition);
})[0];

var direction = utils.getDirection(playerState.position, closestAmmo);
if (playerState.direction != direction) {
return direction;
}

return 'move';
};

var livingEnemyPlayerPositions = function(enemiesStates) {
var positions = _.map(enemiesStates, function(state){
return state.position;
});
return positions;
}

var directionsToPositions = function(currentPosition, positions) {
var directions = _.map(positions, function(pos) {
return utils.fastGetDirection(currentPosition, pos);
});
return directions;
}

var thor = {
info: {
Expand All @@ -15,16 +43,17 @@ var thor = {

// if no ammo, find ammo
if (!playerState.ammo && gameEnvironment.ammoPosition.length) {
directionToAmmo = utils.fastGetDirection(playerState.position, gameEnvironment.ammoPosition[0]);

if (directionToAmmo !== playerState.direction) return directionToAmmo;
return 'move';
return goToClosestAmmo(playerState, enemiesStates, gameEnvironment);
}

// if have ammo, go camp somewhere
//return utils.safeRandomMove();
var allDirections = directionsToPositions(playerState.position,
livingEnemyPlayerPositions(enemiesStates));
console.log('enemy directions' + allDirections);

var myArray = ['north', 'south', 'east', 'west'];
return myArray[Math.floor(Math.random() * myArray.length)];
return allDirections[Math.floor(Math.random() * allDirections.length)];
//return utils.safeRandomMove();
}
}
Expand Down
25 changes: 21 additions & 4 deletions src/players/will3.js
Expand Up @@ -18,6 +18,19 @@ utils.canKillSafe = (currentPlayerState = {}, enemiesStates = []) => {
});
};

var getDirectionVertical = (start = [], end = []) => {
start = start || [];
end = end || [];

var diffVertical = Math.abs(start[0] - end[0]);
var diffHorizontal = Math.abs(start[1] - end[1]);

if (diffVertical != 0) {
return (start[0] - end[0] > 0) ? 'north' : 'south';
}
return (start[1] - end[1] > 0) ? 'west' : 'east';
};

var gridSize, topLeft, topRight, bottomLeft, bottomRight, lastIndex, corners;
var init = function(gameEnvironment) {
gridSize = gameEnvironment.gridSize;
Expand All @@ -39,7 +52,7 @@ module.exports = function() {
return utils.getDistance(playerState.position, ammoPosition);
})[0];

var direction = utils.getDirection(playerState.position, closestAmmo);
var direction = getDirectionVertical(playerState.position, closestAmmo);
if (playerState.direction != direction) {
return direction;
}
Expand Down Expand Up @@ -85,14 +98,14 @@ module.exports = function() {

for (var i in corners) {
var corner = corners[i];
var distance = utils.getDistance(playerState.position, corner);
var distance = getDirectionVertical(playerState.position, corner);
if (distance < minDis || minDis == null) {
minDis = distance;
closestCorner = corner;
}
}

var direction = utils.getDirection(playerState.position, closestCorner);
var direction = getDirectionVertical(playerState.position, closestCorner);
if (playerState.direction == direction) {
return 'move';
}
Expand Down Expand Up @@ -144,14 +157,18 @@ module.exports = function() {
var canMove = !getWillBeKilled(playerState, enemiesStates);

if (!canMove) {
return utils.randomMove();
return 'north';
}

var move = utils.randomMove();
if (playerState.ammo == 0 && gameEnvironment.ammoPosition.length > 0) {
return goToClosestAmmo(playerState, enemiesStates, gameEnvironment);
}

if (enemiesStates.length == 1) {
return utils.randomMove();
}

if (!atCorner(playerState, gameEnvironment)) {
return getClosestCorner(playerState, gameEnvironment);
}
Expand Down

0 comments on commit d032dde

Please sign in to comment.