
Web worker wars
Web Worker Wars is a game I developed for JavaScript programmers written, of course, in JavaScript.
Variety of games Memory Fight. Something similar to the Google AI Challenge or HabraWars.

1. The game is a turn-based strategy for 2 or more bots
2. Each player writes his own Web Worker, which receives special commands from the game engine and can return action
3. The bot has 4 action points for each move and can distribute them to its actions.
4. The bot has a limited field of view (the example is highlighted in blue on the logo).
- All objects that fall into the field of view are transferred to callback actions and can be used in calculations
5. While the bot can perform 2 actions:
- move 1 cell to the left, right, up, down, cost 1 OD
- aim shot (hits cell) at a distance of up to 5 cells, worth 2 OD, takes 2 life points or shields from the enemy or yourself.
Further detailed rules, an example of a worker and a demo.
6. Until the bot has run out of OD The engine will request actions from the bot.
- If the bot did not respond 2 seconds after the action request, its progress is completed, the OD is burned out
- If there is not enough OD for the action, then the action is not performed, the bot’s move is completed, the OD is burned out
- As soon as the action is taken, the bot takes a certain amount of OD
- If bot sent defunct team removed 1 MP
- The bot could not walk on walls or on other players
- After each step, the boat can turn in any direction
7. The first goes to the worker is that the first was initialized
- in the future remake: b children go first worker is a minimum volume.
8. Each bot has 10 Life Points and 2 Shield Points
- The shield is regenerated by +1 at the end of each phase (when everyone left), but cannot be more than 2
9. The playing field has a size of 10 by 10 cells in the field’s wall - the wall (the field is actually 8 by 8).
10. At the beginning, bots are placed in the corners: the first bot in cell 1.1, the second - 8.8
11. The game has a limit of 500 moves (2000 OD on all bots)
12. Each bot can receive various events: (onDamage, onHit, onAfterMove ...)
- While their number is limited
While the game is in trial mode, any rule can change.
Its logic is simple: the worker walks randomly and turns randomly, looking for the enemy, as soon as the enemy falls into his field of vision, he starts shooting to the last (almost all comments are removed from the example in the article, the full version is either in the demo or in the archive).
Initializer battles: azproduction.ru/web_worker_wars
Demka 2 bot: azproduction.ru/web_worker_wars/arena.html#ZRV1vYGY&ZRV1vYGY
4 bot azproduction.ru/web_worker_wars/arena.html#ZRV1vYGY&ZRV1vYGY&ZRV1vYGY&ZRV1vYGY
visualization demo - record previous battle workers` i.e. not realtime.
Archive with all files (old version): narod.ru/disk/1947680001/web_worker_wars.rar.html
Google code project code.google.com/p/web-worker-wars
Your opinion about the game is interesting, suggestions for improvement.
UPD Now you can upload your bots on pastebin.com and use the id of the script from pastebin (http://pastebin.com/ZRV1vYGY) to launch bots in the battle initializerazproduction.ru/web_worker_wars
Variety of games Memory Fight. Something similar to the Google AI Challenge or HabraWars.

Features and Rules
1. The game is a turn-based strategy for 2 or more bots
2. Each player writes his own Web Worker, which receives special commands from the game engine and can return action
3. The bot has 4 action points for each move and can distribute them to its actions.
4. The bot has a limited field of view (the example is highlighted in blue on the logo).
- All objects that fall into the field of view are transferred to callback actions and can be used in calculations
5. While the bot can perform 2 actions:
- move 1 cell to the left, right, up, down, cost 1 OD
- aim shot (hits cell) at a distance of up to 5 cells, worth 2 OD, takes 2 life points or shields from the enemy or yourself.
Further detailed rules, an example of a worker and a demo.
6. Until the bot has run out of OD The engine will request actions from the bot.
- If the bot did not respond 2 seconds after the action request, its progress is completed, the OD is burned out
- If there is not enough OD for the action, then the action is not performed, the bot’s move is completed, the OD is burned out
- As soon as the action is taken, the bot takes a certain amount of OD
- If bot sent defunct team removed 1 MP
- The bot could not walk on walls or on other players
- After each step, the boat can turn in any direction
7. The first goes to the worker is that the first was initialized
- in the future remake: b children go first worker is a minimum volume.
8. Each bot has 10 Life Points and 2 Shield Points
- The shield is regenerated by +1 at the end of each phase (when everyone left), but cannot be more than 2
9. The playing field has a size of 10 by 10 cells in the field’s wall - the wall (the field is actually 8 by 8).
10. At the beginning, bots are placed in the corners: the first bot in cell 1.1, the second - 8.8
11. The game has a limit of 500 moves (2000 OD on all bots)
12. Each bot can receive various events: (onDamage, onHit, onAfterMove ...)
- While their number is limited
While the game is in trial mode, any rule can change.
Worker example
Its logic is simple: the worker walks randomly and turns randomly, looking for the enemy, as soon as the enemy falls into his field of vision, he starts shooting to the last (almost all comments are removed from the example in the article, the full version is either in the demo or in the archive).
/**#nocode+*/
(function (global) {
/**#nocode-*/
/**
* Callbacks
*
* @namespace Callbacks
*/
var Callbacks = {
callback: function (state) {
// its own id
var id = state.player.name,
target,
i, c, ok = false, fow = [];
// looking for enemy in fow
for (i = 0, c = state.fow.length; i < c; i += 1) {
// push fow elements to 2d array, required for movements
if (!fow[state.fow[i].y]) {
fow[state.fow[i].y] = [];
}
fow[state.fow[i].y][state.fow[i].x] = state.fow[i].object;
if (typeof state.fow[i].object === 'object' && state.fow[i].object.name !== id) {
// found!
target = {
x: state.fow[i].x,
y: state.fow[i].y
};
}
}
if (target) { // target - shoot!
Player.post({
action: 'shoot', // shoot action
options: target, // enemy x y
direction: state.player.direction // do not change direction
});
} else { // no target - seeking for target
// make random moves
if (Math.random() > 0.5) { // move to x
while (!ok) { // check if cell not occupied
target = {
x: state.player.x + (~~(Math.random() * 3) - 1),
y: state.player.y
};
if (typeof fow[target.y] === 'undefined' || typeof fow[target.y][target.x] === 'undefined' ) {
ok = true; // cell is free
}
}
} else { // or move to y
while (!ok) { // check if cell not occupied
target = {
x: state.player.x,
y: state.player.y + (~~(Math.random() * 3) - 1)
};
if (typeof fow[target.y] === 'undefined' || typeof fow[target.y][target.x] === 'undefined' ) {
ok = true; // cell is free
}
}
}
Player.post({
action: 'move', // move action
options: target,
direction: ~~(Math.random() * 5) // random direction
});
}
},
onHit: function (param) {
},
onDamage: function (param) {
},
onKill: function (param) {
},
onDead: function () {
}
};
/**
* Player
* @namespace Player
*/
var Player = {
post: function (data) {
global.postMessage(JSON.stringify(data));
}
};
/**
* Message listener
*/
global.onmessage = function (e) {
var data = JSON.parse(e.data);
if (data.call && typeof Callbacks[data.call] === 'function') {
Callbacks[data.call](data.arguments);
}
};
/**#nocode+*/
}(this));
/**#nocode-*/
Initializer battles: azproduction.ru/web_worker_wars
Demka 2 bot: azproduction.ru/web_worker_wars/arena.html#ZRV1vYGY&ZRV1vYGY
4 bot azproduction.ru/web_worker_wars/arena.html#ZRV1vYGY&ZRV1vYGY&ZRV1vYGY&ZRV1vYGY
visualization demo - record previous battle workers` i.e. not realtime.
Archive with all files (old version): narod.ru/disk/1947680001/web_worker_wars.rar.html
Google code project code.google.com/p/web-worker-wars
Your opinion about the game is interesting, suggestions for improvement.
UPD Now you can upload your bots on pastebin.com and use the id of the script from pastebin (http://pastebin.com/ZRV1vYGY) to launch bots in the battle initializerazproduction.ru/web_worker_wars