backend extended
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
const { exec } = require('child_process');
|
||||
|
||||
// Test the pattern-based approach movement calculation
|
||||
function calculateMovement(currentPosition, stepValue, diceRoll, border, isPositive) {
|
||||
// Calculate base movement (multiplication for larger distances)
|
||||
let baseMovement = Math.abs(stepValue) * diceRoll;
|
||||
if (!isPositive) {
|
||||
baseMovement = -baseMovement;
|
||||
}
|
||||
|
||||
// Get position modifier based on current position pattern for strategic thinking
|
||||
let patternModifier = 0;
|
||||
|
||||
// Pattern rules: Players must consider their current position
|
||||
if (currentPosition % 10 === 0) {
|
||||
// Positions ending in 0 (10, 20, 30, etc.) get no modifier
|
||||
patternModifier = 0;
|
||||
} else if (currentPosition % 5 === 0) {
|
||||
// Positions ending in 5 (15, 25, 35, etc.) get ±3 modifier
|
||||
patternModifier = isPositive ? 3 : -3;
|
||||
} else if (currentPosition % 3 === 0) {
|
||||
// Positions divisible by 3 get ±2 modifier
|
||||
patternModifier = isPositive ? 2 : -2;
|
||||
} else if (currentPosition % 2 === 1) {
|
||||
// Odd positions get ±1 modifier
|
||||
patternModifier = isPositive ? 1 : -1;
|
||||
} else {
|
||||
// Even positions (not divisible by other patterns) get no modifier
|
||||
patternModifier = 0;
|
||||
}
|
||||
|
||||
// Calculate final position
|
||||
let finalPosition = currentPosition + baseMovement + patternModifier;
|
||||
|
||||
// Handle bounds (no wrapping - clamp to 1-100)
|
||||
if (finalPosition > 100) finalPosition = 100;
|
||||
if (finalPosition < 1) finalPosition = 1;
|
||||
|
||||
return finalPosition;
|
||||
}
|
||||
|
||||
// Test function for various positions
|
||||
function testPatternLogic() {
|
||||
console.log('Testing Pattern-Based Movement Calculation');
|
||||
console.log('=========================================');
|
||||
|
||||
const testPositions = [3, 5, 10, 15, 18, 20, 25, 30, 33, 40, 45, 50, 60, 65, 75, 80, 85, 90, 95, 100];
|
||||
const border = Array.from({length: 100}, (_, i) => i + 1); // Simple 1-100 border for testing
|
||||
|
||||
for (const pos of testPositions) {
|
||||
console.log(`\nPosition ${pos}:`);
|
||||
|
||||
// Check pattern
|
||||
const lastDigit = pos % 10;
|
||||
let patternType = 'even (no modifier)';
|
||||
if (pos % 10 === 0) patternType = 'ends in 0 (no modifier)';
|
||||
else if (pos % 5 === 0) patternType = 'ends in 5 (±3 modifier)';
|
||||
else if (pos % 3 === 0) patternType = 'divisible by 3 (±2 modifier)';
|
||||
else if (pos % 2 === 1) patternType = 'odd (±1 modifier)';
|
||||
|
||||
console.log(` Pattern: ${patternType}`);
|
||||
|
||||
// Test positive movement with dice 1-6 and step value 4
|
||||
console.log(' Positive moves (step=4):');
|
||||
for (let dice = 1; dice <= 6; dice++) {
|
||||
const result = calculateMovement(pos, 4, dice, border, true);
|
||||
const distance = Math.abs(result - pos);
|
||||
const valid = (pos <= 85 && distance >= 20 && distance <= 30) ||
|
||||
(pos > 85 && distance >= 20 && distance <= 30);
|
||||
console.log(` Dice ${dice}: ${pos} -> ${result} (distance: ${distance}) ${valid ? '✓' : '✗'}`);
|
||||
}
|
||||
|
||||
// Test negative movement with dice 1-6 and step value -4
|
||||
console.log(' Negative moves (step=-4):');
|
||||
for (let dice = 1; dice <= 6; dice++) {
|
||||
const result = calculateMovement(pos, -4, dice, border, false);
|
||||
const distance = Math.abs(result - pos);
|
||||
const valid = (pos <= 85 && distance >= 20 && distance <= 30) ||
|
||||
(pos > 85 && distance >= 20 && distance <= 30);
|
||||
console.log(` Dice ${dice}: ${pos} -> ${result} (distance: ${distance}) ${valid ? '✓' : '✗'}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
testPatternLogic();
|
||||
|
||||
// Test board generation
|
||||
console.log('\n\nTesting Board Generation...');
|
||||
console.log('============================');
|
||||
|
||||
exec('cd d:\\munka\\SzeSnake\\SerpentRace_Backend && npm run test -- --testNamePattern="BoardGenerationService"',
|
||||
(error, stdout, stderr) => {
|
||||
if (error) {
|
||||
console.error(`Error: ${error}`);
|
||||
return;
|
||||
}
|
||||
console.log(stdout);
|
||||
if (stderr) {
|
||||
console.error(`Stderr: ${stderr}`);
|
||||
}
|
||||
}
|
||||
);
|
||||
Reference in New Issue
Block a user