Commit 7f50d285 authored by Martin Bachmann's avatar Martin Bachmann
Browse files

Modified the results display to update after each round. Added bot stats.

parent f87cd4d1
Pipeline #12784 passed with stages
in 2 minutes and 47 seconds
......@@ -96,13 +96,13 @@ Pond.Duck.init = function() {
var url = document.getElementById(code).value;
if (url.toLowerCase() == 'bot') {
var bots = [
"/pond/botRook.js",
"/pond/botSniper.js",
"/pond/botCounter.js"
"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";
url = "pond/botRabbit.js";
}
console.log(code + " uses " + url);
return $.ajax({
......
......@@ -41,11 +41,17 @@
{call Pond.soy.visualization /}
</div>
<div id="result">
<h2>Results</h2>
<table id="result-table">
</table>
</div>
<div id="stats" style="padding: 20px;">
<h2>Bot stats</h2>
<table id="stats-table">
</table>
</div>
<div id="result" style="padding: 20px;">
<h2>Results</h2>
<table id="result-table">
</table>
</div>
</div>
{/template}
......@@ -44,6 +44,8 @@ Pond.Battle.RANK = [];
Pond.Battle.ROUND_RANKS = [];
Pond.Battle.BOT_STATS = [];
Pond.Battle.ROUND_COUNT = 5;
/**
......
......@@ -39,17 +39,28 @@ Pond.endBattle = function(survivors) {
Pond.Battle.ROUND_RANKS.push(Pond.Battle.RANK.slice());
console.log(Pond.Battle.RANK);
console.log("Round " + Pond.Battle.ROUND_RANKS.length + " finished!");
// Update Bot Stats table
Pond.Battle.BOT_STATS[Pond.Battle.RANK[0].name] += 3;
Pond.Battle.BOT_STATS[Pond.Battle.RANK[1].name] += 2;
Pond.Battle.BOT_STATS[Pond.Battle.RANK[2].name] += 1;
var statsTable = "<table>\n<tr><th>Bot</th><th>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";
}
statsTable += "</table>";
$("#stats-table").html(statsTable);
// Update Results table
var round = Pond.Battle.RANK;
var resultRow = "<tr><td>" + (Pond.Battle.ROUND_RANKS.length) + "</td><td>" + round[0].name + "</td><td>" + round[1].name + "</td><td>" + round[2].name + "</td><td>" + round[3].name + "</td></tr>";
$("#result-table").append(resultRow);
if (Pond.Battle.ROUND_RANKS.length < Pond.Battle.ROUND_COUNT) {
Pond.execute();
} else {
var result_list = "<tr><th>Round</th><th>#1</th><th>#2</th><th>#3</th><th>#4</th></tr>";
var rounds = Pond.Battle.ROUND_RANKS;
console.log(rounds);
for (var i = 0; i < rounds.length; i++) {
console.log(rounds[i]);
result_list += "<tr><td>" + (i + 1) + "</td><td>" + rounds[i][0].name + "</td><td>" + rounds[i][1].name + "</td><td>" + rounds[i][2].name + "</td><td>" + rounds[i][3].name + "</td></tr>";
}
$("#result-table").html(result_list);
// completed last round
}
};
......@@ -144,6 +155,14 @@ Pond.runButtonClick = function(e) {
}
runButton.style.display = 'none';
resetButton.style.display = 'inline';
Pond.Battle.ROUND_RANKS = [];
// 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;
}
$("#result-table").html("<tr><th>Round</th><th>#1</th><th>#2</th><th>#3</th><th>#4</th></tr>");
var config_fields = $(".game-config");
$.each(config_fields, function() {
Pond.Battle[$(this).attr("id")] = eval($(this).val());
......
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