Skip to content
This repository has been archived by the owner on Oct 2, 2021. It is now read-only.

Prepare for more scoring data. #286

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions bot.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -1223,19 +1223,23 @@ var userInterface = window.userInterface = (function() {
// Update stats overlay.
updateStats: function() {
var oContent = [];
var median;

if (bot.scores.length === 0) return;
median = Math.round((bot.scores[Math.floor((bot.scores.length - 1) / 2)] +
bot.scores[Math.ceil((bot.scores.length - 1) / 2)]) / 2);

var avg = Math.round(bot.scores.reduce(function (a, b) { return a + b.score; }, 0) /

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected space before function parentheses.

(bot.scores.length));

var median = Math.round((bot.scores[Math.floor((bot.scores.length - 1) / 2)].score +
bot.scores[Math.ceil((bot.scores.length - 1) / 2)].score) / 2);


oContent.push('games played: ' + bot.scores.length);
oContent.push('a: ' + Math.round(
bot.scores.reduce(function(a, b) { return a + b; }) / (bot.scores.length)) +
oContent.push('a: ' + avg +
' m: ' + median);

for (var i = 0; i < bot.scores.length && i < 10; i++) {
oContent.push(i + 1 + '. ' + bot.scores[i]);
oContent.push(i + 1 + '. ' + bot.scores[i].score +
' in ' + Math.round(bot.scores[i].duration / 1000) + 's');
}

userInterface.overlays.statsOverlay.innerHTML = oContent.join('<br/>');
Expand Down Expand Up @@ -1325,14 +1329,20 @@ var userInterface = window.userInterface = (function() {
} else if (bot.isBotEnabled && bot.isBotRunning) {
bot.isBotRunning = false;
if (window.lastscore && window.lastscore.childNodes[1]) {
bot.scores.push(parseInt(window.lastscore.childNodes[1].innerHTML));
var score = parseInt(window.lastscore.childNodes[1].innerHTML);
var duration = Date.now() - bot.startTime;
bot.scores.push({
score: score,
duration: duration
});
bot.scores.sort(function(a, b) {
return b - a;
return b.score - a.score;
});
userInterface.updateStats();
}

if (window.autoRespawn) {
bot.startTime = Date.now();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change suggests bad state management. We should have some bot states to check our code against

  • Not playing
  • Connecting
  • Connected?
  • Playing
  • Dying

window.connect();
}
}
Expand Down Expand Up @@ -1456,5 +1466,6 @@ var userInterface = window.userInterface = (function() {
setInterval(userInterface.framesPerSecond.fpsTimer, 80);

// Start!
bot.startTime = Date.now();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate code so guess bad state management

userInterface.oefTimer();
})();