Preventing ~solve when numbers game is in progress.

This commit is contained in:
ThePendulum 2024-01-02 16:15:37 +01:00
parent 4017f1cd07
commit 47484ba7e2
1 changed files with 7 additions and 2 deletions

View File

@ -367,6 +367,11 @@ async function solve(equation, context) {
return;
}
if (Array.from(games.entries()).some(([roomId, game]) => roomId === context.room.id || game.target === target)) {
context.sendMessage('Nice try! Please wait for this numbers round to end :)', context.room.id);
return;
}
try {
const solutions = await solveAll(numbers, target, 3);
const bestSolution = solutions.reduce((closest, solution) => (!closest || Math.abs(target - solution.answer) < Math.abs(target - closest.answer) ? solution : closest), null);
@ -377,11 +382,11 @@ async function solve(equation, context) {
}
if (bestSolution.answer === target) {
context.sendMessage(`My best solution for ${numbers.join(' ')} = ${target} is: ${bestSolution.solution}`, context.room.id);
context.sendMessage(`My best solution for ${numbers.join(' ')} = ${target} is: ${style.bold(bestSolution.solution)}`, context.room.id);
return;
}
context.sendMessage(`I could not find an exact solution for ${numbers.join(' ')} = ${target}. My closest solution is: ${bestSolution.solution} = ${bestSolution.answer}`, context.room.id);
context.sendMessage(`I could not find an exact solution for ${numbers.join(' ')} = ${target}. My closest solution is: ${style.bold(bestSolution.solution)} = ${style.italic(bestSolution.answer)}`, context.room.id);
} catch (error) {
console.log(error);
}