Commit 2228630c authored by Dominik Wittwer's avatar Dominik Wittwer
Browse files

added more stats and more stats tracking, added possibility to add a specific bot

parent e9a3e665
Pipeline #14174 passed with stages
in 23 minutes and 7 seconds
......@@ -118,15 +118,27 @@ Pond.Duck.init = function() {
for (var playerData, i = 0; playerData = players[i]; i++) {
var codeUrl = function(code) {
var url = document.getElementById(code).value;
if (url.toLowerCase() == 'bot') {
var bots = [
"pond/botRook.js",
"pond/botSniper.js",
"pond/botCounter.js"
];
url = bots[Math.floor(Math.random()*3)];
} else if (url.toLowerCase() == 'target') {
url = "pond/botRabbit.js";
switch(url.toLowerCase()) {
case "bot":
var bots = [
"pond/botRook.js",
"pond/botSniper.js",
"pond/botCounter.js"
];
url = bots[Math.floor(Math.random()*3)];
break;
case "target":
url = "pond/botRabbit.js";
break;
case "bot rook":
url = "pond/botRook.js";
break;
case "bot sniper":
url = "pond/botSniper.js";
break;
case "bot counter":
url = "pond/botCounter.js";
break;
}
console.log(code + " uses " + url);
return $.ajax({
......
......@@ -152,7 +152,7 @@
</div>
<div class="modal fade" id="statsModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-dialog modal-xl" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Stats</h5>
......@@ -161,19 +161,19 @@
</button>
</div>
<div class="modal-body">
<div id="stats" class="w-100 mt-2">
<h2>Bot stats</h2>
<div id="stats" class="mx-3 mt-2">
<h2>Scoreboard</h2>
<table id="stats-table" class="w-100">
</table>
</div>
<div id="result" class="w-100 mt-5 mb-4">
<h2>Results</h2>
<div id="result" class="mx-3 mt-5 mb-4">
<h2>Round Results</h2>
<table id="result-table" class="w-100 mb-4">
</table>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
......
......@@ -146,7 +146,9 @@ Pond.Avatar.prototype.addDamage = function(add) {
this.damage += add;
if (this.damage >= 100) {
this.die();
return true;
}
return false;
};
/**
......@@ -298,6 +300,7 @@ Pond.Avatar.prototype.cannon = function(degree, range) {
progress: 0
};
this.battle_.MISSILES.push(missile);
Pond.Battle.BOT_STATS[this.name].shots += 1;
this.battle_.EVENTS.push({'type': 'BANG', 'avatar': this,
'degree': missile.degree});
return true;
......
......@@ -44,7 +44,7 @@ Pond.Battle.RANK = [];
Pond.Battle.ROUND_RANKS = [];
Pond.Battle.BOT_STATS = [];
Pond.Battle.BOT_STATS = {};
Pond.Battle.ROUND_COUNT = 5;
......@@ -247,6 +247,7 @@ Pond.Battle.updateMissiles_ = function() {
// Boom.
Pond.Battle.MISSILES.splice(i, 1);
// Damage any avatar in range.
var missile_success = false;
for (var j = 0, avatar; avatar = Pond.Battle.AVATARS[j]; j++) {
if (avatar.dead) {
continue;
......@@ -254,8 +255,19 @@ Pond.Battle.updateMissiles_ = function() {
var range = goog.math.Coordinate.distance(avatar.loc, missile.endLoc);
var damage = (1 - range / 4) * 10;
if (damage > 0) {
avatar.addDamage(damage);
var is_kill = avatar.addDamage(damage);
maxDamage = Math.max(maxDamage, damage);
Pond.Battle.BOT_STATS[missile.avatar.name].player_hits += 1;
Pond.Battle.BOT_STATS[missile.avatar.name].damage_done += damage;
Pond.Battle.BOT_STATS[avatar.name].hits_recieved += 1;
if (is_kill) {
Pond.Battle.BOT_STATS[missile.avatar.name].kills += 1;
Pond.Battle.BOT_STATS[avatar.name].deaths += 1;
}
if (!missile_success) {
Pond.Battle.BOT_STATS[missile.avatar.name].shots_success += 1;
}
missile_success = true;
}
}
Pond.Battle.EVENTS.push({'type': 'BOOM', 'damage': maxDamage,
......@@ -289,6 +301,7 @@ Pond.Battle.updateAvatars_ = function() {
var speed = avatar.speed / 100 * Pond.Battle.AVATAR_SPEED;
var dx = Math.cos(angleRadians) * speed;
var dy = Math.sin(angleRadians) * speed;
var old_pos = JSON.parse(JSON.stringify(avatar.loc));
avatar.loc.x += dx;
avatar.loc.y += dy;
if (avatar.loc.x < 0 || avatar.loc.x > 100 ||
......@@ -296,13 +309,25 @@ Pond.Battle.updateAvatars_ = function() {
// Collision with wall.
avatar.loc.x = goog.math.clamp(avatar.loc.x, 0, 100);
avatar.loc.y = goog.math.clamp(avatar.loc.y, 0, 100);
var dx_eff = avatar.loc.x - old_pos.x;
var dy_eff = avatar.loc.y - old_pos.y;
Pond.Battle.BOT_STATS[avatar.name].distance_traveled += Math.sqrt(dx_eff*dx_eff + dy_eff*dy_eff);
var damage = avatar.speed / 100 * Pond.Battle.COLLISION_DAMAGE;
avatar.addDamage(damage);
var is_kill = avatar.addDamage(damage);
Pond.Battle.BOT_STATS[avatar.name].crashes += 1;
Pond.Battle.BOT_STATS[avatar.name].crash_dmg_recieved += damage;
if (is_kill) {
Pond.Battle.BOT_STATS[avatar.name].deaths += 1;
Pond.Battle.BOT_STATS[avatar.name].deaths_by_crash += 1;
}
avatar.speed = 0;
avatar.desiredSpeed = 0;
Pond.Battle.EVENTS.push(
{'type': 'CRASH', 'avatar': avatar, 'damage': damage});
} else {
Pond.Battle.BOT_STATS[avatar.name].distance_traveled += Math.sqrt(dx*dx + dy*dy);
var tuple = Pond.Battle.closestNeighbour(avatar);
var neighbour = tuple[0];
var closestAfter = tuple[1];
......@@ -313,10 +338,28 @@ Pond.Battle.updateAvatars_ = function() {
avatar.loc.y -= dy;
var damage = Math.max(avatar.speed, neighbour.speed) / 100 *
Pond.Battle.COLLISION_DAMAGE;
avatar.addDamage(damage);
var is_kill_a = avatar.addDamage(damage);
Pond.Battle.BOT_STATS[avatar.name].crashes += 1;
Pond.Battle.BOT_STATS[avatar.name].crash_dmg_recieved += damage;
Pond.Battle.BOT_STATS[neighbour.name].crash_dmg_done += damage;
if (is_kill_a) {
Pond.Battle.BOT_STATS[neighbour.name].kills += 1;
Pond.Battle.BOT_STATS[neighbour.name].kills_by_crash += 1;
Pond.Battle.BOT_STATS[avatar.name].deaths += 1;
Pond.Battle.BOT_STATS[avatar.name].deaths_by_crash += 1;
}
avatar.speed = 0;
avatar.desiredSpeed = 0;
neighbour.addDamage(damage);
var is_kill_b = neighbour.addDamage(damage);
Pond.Battle.BOT_STATS[neighbour.name].crashes += 1;
Pond.Battle.BOT_STATS[neighbour.name].crash_dmg_recieved += damage;
Pond.Battle.BOT_STATS[avatar.name].crash_dmg_done += damage;
if (is_kill_b) {
Pond.Battle.BOT_STATS[neighbour.name].deaths += 1;
Pond.Battle.BOT_STATS[neighbour.name].deaths_by_crash += 1;
Pond.Battle.BOT_STATS[avatar.name].kills += 1;
Pond.Battle.BOT_STATS[avatar.name].kills_by_crash += 1;
}
neighbour.speed = 0;
neighbour.desiredSpeed = 0;
Pond.Battle.EVENTS.push(
......
......@@ -40,14 +40,40 @@ Pond.endBattle = function(survivors) {
console.log(Pond.Battle.RANK);
console.log("Round " + Pond.Battle.ROUND_RANKS.length + " finished!");
// Update Bot Stats table - winner takes it all for now
Pond.Battle.BOT_STATS[Pond.Battle.RANK[0].name] += 1;
// Update Player Stats table - winner takes it all for now
Pond.Battle.BOT_STATS[Pond.Battle.RANK[0].name].points += 1;
console.log(Pond.Battle.BOT_STATS);
var players = Pond.Battle.AVATARS.slice();
players.sort(function(a, b) {
var val_a = Pond.Battle.BOT_STATS[a.name].points*10000000 + Pond.Battle.BOT_STATS[a.name].kills*1000 + Pond.Battle.BOT_STATS[a.name].player_hits;
var val_b = Pond.Battle.BOT_STATS[b.name].points*10000000 + Pond.Battle.BOT_STATS[b.name].kills*1000 + Pond.Battle.BOT_STATS[b.name].player_hits;
return val_b - val_a;
});
var statsTable = "<table>\n<tr><th>Bot</th><th align='right'>Points</th></tr>";
for (var name in Pond.Battle.BOT_STATS) {
statsTable += "<tr></tr><td>" + name + "</td><td align='right'>" + Pond.Battle.BOT_STATS[name] + "</td></tr>\n";
var statsTable = "<table><thead><tr><th>Player</th><th class='text-right'>Kills</th><th class='text-right'>Deaths</th><th class='text-right'>Players hit</th><th class='text-right'>Accuracy</th><th class='text-right'>Hits recieved</th><th class='text-right'>Points</th></tr></thead><tbody>";
for (var i = 0; i < players.length; i++) {
// New row
statsTable += "<tr>";
// Player name
statsTable += "<td>" + players[i].name + "</td>";
// Player kills
statsTable += "<td class='text-right'>" + Pond.Battle.BOT_STATS[players[i].name].kills + "</td>";
// Player deaths
statsTable += "<td class='text-right'>" + Pond.Battle.BOT_STATS[players[i].name].deaths + "</td>";
// Player hits
statsTable += "<td class='text-right'>" + Pond.Battle.BOT_STATS[players[i].name].player_hits + "</td>";
// Player accuracy
var accuracy = Math.round(Pond.Battle.BOT_STATS[players[i].name].shots_success / Pond.Battle.BOT_STATS[players[i].name].shots * 100);
statsTable += "<td class='text-right'>" + accuracy + "%</td>";
// Player hits recieved
statsTable += "<td class='text-right'>" + Pond.Battle.BOT_STATS[players[i].name].hits_recieved + "</td>";
// Player points
statsTable += "<td class='text-right'>" + Pond.Battle.BOT_STATS[players[i].name].points + "</td>";
// Close row
statsTable += "</tr>";
}
statsTable += "</table>";
statsTable += "</tbody></table>";
$("#stats-table").html(statsTable);
// Update Results table
......@@ -225,15 +251,27 @@ Pond.runButtonClick = function(e) {
if (document.getElementById(playerData.code).value != "") {
var codeUrl = function(code) {
var url = document.getElementById(code).value;
if (url.toLowerCase() == 'bot') {
var bots = [
"pond/botRook.js",
"pond/botSniper.js",
"pond/botCounter.js"
];
url = bots[Math.floor(Math.random()*3)];
} else if (url.toLowerCase() == 'target') {
url = "pond/botRabbit.js";
switch(url.toLowerCase()) {
case "bot":
var bots = [
"pond/botRook.js",
"pond/botSniper.js",
"pond/botCounter.js"
];
url = bots[Math.floor(Math.random()*3)];
break;
case "target":
url = "pond/botRabbit.js";
break;
case "bot rook":
url = "pond/botRook.js";
break;
case "bot sniper":
url = "pond/botSniper.js";
break;
case "bot counter":
url = "pond/botCounter.js";
break;
}
console.log(code + " uses " + url);
return $.ajax({
......@@ -250,11 +288,26 @@ Pond.runButtonClick = function(e) {
// Init bot results and stats
for (var i=0; i < Pond.Battle.AVATARS.length; i++) {
Pond.Battle.BOT_STATS[Pond.Battle.AVATARS[i].name] = 0;
Pond.Battle.BOT_STATS[Pond.Battle.AVATARS[i].name] = {
points: 0,
kills: 0,
kills_by_crash: 0,
deaths: 0,
deaths_by_crash: 0,
player_hits: 0,
damage_done: 0,
crashes: 0,
crash_dmg_done: 0,
crash_dmg_recieved: 0,
hits_recieved: 0,
shots: 0,
shots_success: 0,
distance_traveled: 0
};
}
var resultFirstRow = "<tr><td>Round</td>";
for (var i = 0; i < Pond.Battle.AVATARS.length; i++) {
resultFirstRow += "<td>#" + i + "</td>";
resultFirstRow += "<td>#" + (i + 1) + "</td>";
}
resultFirstRow += "</tr>";
$("#result-table").html(resultFirstRow);
......
......@@ -307,7 +307,6 @@ Pond.Visualization.display_ = function() {
ctx.arc(missileX, missileY, Pond.Visualization.MISSILE_RADIUS,
0, Math.PI * 2, true);
ctx.closePath();
console.log(missile.avatar)
ctx.fillStyle = Pond.Visualization.COLOURS[
missile.avatar.visualizationIndex % Pond.Visualization.COLOURS.length];
ctx.fill();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment