summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorArjun Satarkar <me@arjunsatarkar.net>2024-10-31 12:36:24 +0000
committerArjun Satarkar <me@arjunsatarkar.net>2024-10-31 12:36:24 +0000
commitd687ab739cb0bc0c3cea8398a8320070a8e3cda1 (patch)
treef5ff2f4b88e3015ca705e988c60a5bf631662a34 /src
parent19def0070044c1594f70ea1413232967b68d91d0 (diff)
downloadthrow_simulation-d687ab739cb0bc0c3cea8398a8320070a8e3cda1.tar
throw_simulation-d687ab739cb0bc0c3cea8398a8320070a8e3cda1.tar.gz
throw_simulation-d687ab739cb0bc0c3cea8398a8320070a8e3cda1.zip
Make scoring system more complicated
Whether it is "better" is sort of a philosophical question, but this will do.
Diffstat (limited to 'src')
-rw-r--r--src/index.js19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/index.js b/src/index.js
index b6f6e0b..71554ce 100644
--- a/src/index.js
+++ b/src/index.js
@@ -6,8 +6,9 @@ const LINEAR_DAMPING = 0.5;
const OBJ_BASE_RADIUS = 30;
const OBJ_BASE_SIZE = { x: OBJ_BASE_RADIUS * 2, y: OBJ_BASE_RADIUS * 2 };
const OBJ_MASS = 100;
-const SCORE_DECAY_RATE = 5;
-const SCORE_DECAY_THRESHOLD = 150;
+const SCORE_DECAY_CURVE_L = 1000;
+const SCORE_DECAY_CURVE_K = 0.01;
+const SCORE_DECAY_CURVE_X0 = 1000;
const SCORE_INCREMENT = 150;
const STEP_MS = 33;
const TARGET_WIDTH_FACTOR = 0.05;
@@ -80,14 +81,18 @@ RAPIER.init().then(() => {
lastCollision = { handle1: handle1, handle2: handle2 };
});
- const now = performance.now();
- if (now - lastScoredAt > SCORE_DECAY_THRESHOLD) {
- score -= SCORE_DECAY_RATE;
+ const score_gap = performance.now() - lastScoredAt;
+ const score_decay_coefficient =
+ SCORE_DECAY_CURVE_L -
+ SCORE_DECAY_CURVE_L /
+ (1 + Math.exp(-SCORE_DECAY_CURVE_K * (score - SCORE_DECAY_CURVE_X0)));
+ if (score_gap > score_decay_coefficient) {
+ score -= Math.max(Math.log(score), 1);
score = Math.max(score, 0);
}
- scoreElement.textContent = `${score}`;
- highScoreElement.textContent = `${highScore}`;
+ scoreElement.textContent = `${Math.round(score)}`;
+ highScoreElement.textContent = `${Math.round(highScore)}`;
const objPosition = obj.translation();
objElement.style.left = `${objPosition.x}px`;