109 lines
3.8 KiB
JavaScript
109 lines
3.8 KiB
JavaScript
// Test the new simplified movement logic
|
|
function testSimplifiedMovement() {
|
|
console.log('=== Testing New Simplified Movement Logic ===\n');
|
|
|
|
// Test function that mimics the new calculateMovement logic
|
|
function calculateMovement(currentPosition, stepValue, diceValue, isPositive) {
|
|
let finalPosition;
|
|
|
|
if (isPositive) {
|
|
// Positive: current + step + dice
|
|
finalPosition = currentPosition + stepValue + diceValue;
|
|
} else {
|
|
// Negative: current + step - dice (step is negative)
|
|
finalPosition = currentPosition + stepValue - diceValue;
|
|
}
|
|
|
|
// Wrap around the 1-100 board
|
|
while (finalPosition > 100) {
|
|
finalPosition -= 100;
|
|
}
|
|
while (finalPosition < 1) {
|
|
finalPosition += 100;
|
|
}
|
|
|
|
return finalPosition;
|
|
}
|
|
|
|
function isValidDistance(currentPosition, targetPosition) {
|
|
const distance = Math.abs(targetPosition - currentPosition);
|
|
|
|
// Fields 1-85: max 20 fields in any direction
|
|
if (currentPosition <= 85) {
|
|
return distance <= 20;
|
|
}
|
|
|
|
// Fields 86-100: max 30 fields backward, max 20 fields forward
|
|
if (targetPosition > currentPosition) {
|
|
return distance <= 20; // Moving forward
|
|
} else {
|
|
return distance <= 30; // Moving backward
|
|
}
|
|
}
|
|
|
|
// Test case 1: Position 20 with various step values
|
|
console.log('Test Case 1: Position 20 (should be within 20 field limit)');
|
|
for (let step = 1; step <= 10; step++) {
|
|
const results = [];
|
|
let validCount = 0;
|
|
|
|
for (let dice = 1; dice <= 6; dice++) {
|
|
const result = calculateMovement(20, step, dice, true);
|
|
const distance = Math.abs(result - 20);
|
|
const valid = isValidDistance(20, result);
|
|
results.push(`${result}${valid ? '' : '*'}`);
|
|
if (valid) validCount++;
|
|
}
|
|
|
|
console.log(` Step ${step}: [${results.join(', ')}] (${validCount}/6 valid)`);
|
|
if (validCount === 6) {
|
|
console.log(` ✅ PERFECT step value found: ${step}`);
|
|
break;
|
|
}
|
|
}
|
|
|
|
console.log('\nTest Case 2: Position 90 (should respect 86-100 rules)');
|
|
for (let step = -1; step >= -10; step--) {
|
|
const results = [];
|
|
let validCount = 0;
|
|
|
|
for (let dice = 1; dice <= 6; dice++) {
|
|
const result = calculateMovement(90, step, dice, false);
|
|
const distance = Math.abs(result - 90);
|
|
const valid = isValidDistance(90, result);
|
|
results.push(`${result}${valid ? '' : '*'}`);
|
|
if (valid) validCount++;
|
|
}
|
|
|
|
console.log(` Step ${step}: [${results.join(', ')}] (${validCount}/6 valid)`);
|
|
if (validCount === 6) {
|
|
console.log(` ✅ PERFECT step value found: ${step}`);
|
|
break;
|
|
}
|
|
}
|
|
|
|
console.log('\nTest Case 3: Position 50 (middle position)');
|
|
for (let step = 1; step <= 10; step++) {
|
|
const results = [];
|
|
let validCount = 0;
|
|
|
|
for (let dice = 1; dice <= 6; dice++) {
|
|
const result = calculateMovement(50, step, dice, true);
|
|
const distance = Math.abs(result - 50);
|
|
const valid = isValidDistance(50, result);
|
|
results.push(`${result}${valid ? '' : '*'}`);
|
|
if (valid) validCount++;
|
|
}
|
|
|
|
console.log(` Step ${step}: [${results.join(', ')}] (${validCount}/6 valid)`);
|
|
if (validCount === 6) {
|
|
console.log(` ✅ PERFECT step value found: ${step}`);
|
|
break;
|
|
}
|
|
}
|
|
|
|
console.log('\n* = Invalid due to 20-30 rule violation');
|
|
console.log('\n=== Test Complete ===');
|
|
}
|
|
|
|
testSimplifiedMovement(); |