Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base: 9df50d7311
...
compare: baa69f410d
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Showing with 20 additions and 12 deletions.
  1. +2 −0  README
  2. +18 −12 index.js
View
2  README
@@ -32,6 +32,8 @@ max_ships - When battling battle this number of ships against the offense (de
max_tries - The number of battles to run to determine the % of win's
offense - The opposing team, by default it is [ancient], but it can be set to anything, such as [ancient, ancient] or [gcds]
+all_ships_must_survive - True by default this says that you only 'win' a battle if you have no losses. Useful for comparing for example the different class sizes against each other. Set to false if you want to get the results for any outcome that would cause a win. This option only matters if max_ships is greater than 1.
+
To disable a specific part (For example if it hasn't been drawn in your game yet or you just don't want it to be included) set the available flag to false in the parts listing.
$ parts['plasm missile'].available = false;
View
30 index.js
@@ -151,6 +151,9 @@ gcds.push(parts['hull']);
gcds.push(parts['nuclear drive']);
gcds.push(parts['fusion source']);
+// The following are the stock human ships
+// Modify them as needed for the stock alien ships
+
var interceptor = [];
interceptor.push({});
interceptor.push(parts['ion cannon']);
@@ -192,7 +195,6 @@ function validShip(ship) {
return true;
}
-
function rollDie() {
var min = 1;
var max = 6;
@@ -202,7 +204,7 @@ function rollDie() {
// TODO currently if a dice is a hit
// we simply assign it damage to the first valid
// ship rather than optimally distributing the dice
-// which can matter is multi-ship battles.
+// which can matter is multi-ship multi-class battles.
function execBattle(ships) {
for (var ship in ships) {
ships[ship].hit = 0;
@@ -214,14 +216,14 @@ function execBattle(ships) {
function hit(ship) {
ship.hit += damage;
- //console.log('hit: ' + ship.side + ' got a hit of ' + damage);
+ //console.log('hit: ' + ship.player + ' got a hit of ' + damage);
}
var computer = attackingShip['computer'];
- var side = attackingShip.side;
+ var player = attackingShip.player;
var ahit = false;
for (var ship in ships) {
- if (ships[ship].side === side)
+ if (ships[ship].player === player)
continue;
if ((ships[ship].hull - ships[ship].hit) < 0)
continue;
@@ -236,11 +238,11 @@ function execBattle(ships) {
}
}
//if ((ships[ship].hull - ships[ship].hit) < 0)
- // console.log(ships[ship].side + ' destroyed by ' + side + ' ' + damage + ' ' + roll);
+ // console.log(ships[ship].player + ' destroyed by ' + player + ' ' + damage + ' ' + roll);
if (ahit)
break;
}
- //console.log('attack: ' + side + ' ' + roll + ' ' + damage + ' ' + computer + ' ' + ahit);
+ //console.log('attack: ' + player + ' ' + roll + ' ' + damage + ' ' + computer + ' ' + ahit);
}
function rollDice(shoot_once) {
@@ -267,9 +269,9 @@ function execBattle(ships) {
for (var ship in ships) {
if ((ships[ship].hull - ships[ship].hit) < 0)
continue;
- if (ships[ship].side === 'a')
+ if (ships[ship].player === 'a')
ac++;
- if (ships[ship].side === 'b')
+ if (ships[ship].player === 'b')
bc++;
}
}
@@ -284,15 +286,18 @@ function execBattle(ships) {
countUp();
} while (ac > 0 && bc > 0);
//console.log((ac > 0 ? 'a' : 'b') + ' won');
- return bc > 0 && bc === initialbc;
+ if (all_ships_must_survive === true)
+ return bc > 0 && bc === initialbc;
+ else
+ return bc > 0;
}
function battle(playerA, playerB) {
// Tag the ships and put into one list sorted by influence
for (var ship in playerA)
- playerA[ship].side = 'a';
+ playerA[ship].player = 'a';
for (var ship in playerB)
- playerB[ship].side = 'b';
+ playerB[ship].player = 'b';
var ships = [].concat(playerA, playerB);
ships.sort(function(a, b) { return a['influence'] < b['influence']; });
@@ -474,3 +479,4 @@ var max_tries = 200;
var max_research = 1;
var max_cost = 10;
var max_ships = 1;
+var all_ships_must_survive = true;

No commit comments for this range

Something went wrong with that request. Please try again.