Files
SerpentRace/SerpentRace_Backend/debug-border-logic.js
T
2025-09-20 11:14:51 +02:00

47 lines
2.0 KiB
JavaScript

// Quick test to verify border logic
const border = [37,48,45,50,39,5,1,55,54,46,23,89,53,94,56,18,14,92,64,61,43,99,27,36,58,40,41,75,57,49,3,65,77,31,72,2,34,19,78,35,69,68,98,20,22,86,63,76,38,85,8,67,95,21,88,51,82,42,79,73,62,97,44,13,28,33,9,11,32,52,96,100,24,70,91,71,15,93,16,80,74,66,59,26,84,83,47,87,7,17,25,90,4,12,30,10,81,6,60,29];
function calculateMovement(currentPosition, stepValue, diceValue, isPositive) {
console.log(`\n=== Calculating movement for position ${currentPosition} ===`);
console.log(`Step value: ${stepValue}, Dice: ${diceValue}, Positive: ${isPositive}`);
// Use current position as INDEX in border array
let borderIndex = currentPosition - 1;
console.log(`Initial border index: ${borderIndex}`);
console.log(`Starting value at border[${borderIndex}]: ${border[borderIndex]}`);
// Apply step value
if (isPositive) {
borderIndex = (borderIndex + stepValue + 100) % 100;
} else {
borderIndex = (borderIndex - Math.abs(stepValue) + 100) % 100;
}
console.log(`After step value: border index = ${borderIndex}, value = ${border[borderIndex]}`);
// Apply dice movement
if (isPositive) {
borderIndex = (borderIndex + diceValue) % 100;
} else {
borderIndex = (borderIndex - diceValue + 100) % 100;
}
console.log(`After dice: border index = ${borderIndex}, value = ${border[borderIndex]}`);
return border[borderIndex];
}
// Test position 12, step value 1
console.log("Testing position 12 with step value 1 (expected results: [10,-1,6,-1,29,-1])");
for (let dice = 1; dice <= 6; dice++) {
const result = calculateMovement(12, 1, dice, true);
console.log(`Dice ${dice}: Result = ${result}`);
}
// Test a few more
console.log("\n" + "=".repeat(50));
console.log("Testing position 15 with step value 11 (expected: [7,17,25,-1,4,12])");
for (let dice = 1; dice <= 6; dice++) {
const result = calculateMovement(15, 11, dice, true);
console.log(`Dice ${dice}: Result = ${result}`);
}