29 lines
1.2 KiB
JavaScript
29 lines
1.2 KiB
JavaScript
// Kiitos AI (client side) — a thin, skill-aware wrapper over the server engine's
|
|
// move chooser. The heavy dictionary work (prefix search, word finding) lives in
|
|
// server/words/kiitosEngine.js so the full ENABLE list never ships to the browser;
|
|
// this module just asks for a move and paces it so turns feel deliberate.
|
|
|
|
import { api } from '../../services/api.js';
|
|
|
|
// Returns one of:
|
|
// { type:'play', letter, forced:true } — mandatory next letter
|
|
// { type:'deviate', letter, prefix, word } — repurpose / start a word
|
|
// { type:'pass' } — no legal move
|
|
export async function chooseAIMove({ hand, built, targetWord, minLen, skill, allowPrepend, superKiitos }) {
|
|
try {
|
|
return await api.post('/words/kiitos/ai-move', {
|
|
hand, built, targetWord, minLen, skill, allowPrepend, superKiitos,
|
|
});
|
|
} catch (err) {
|
|
console.error('[kiitos] ai-move failed:', err);
|
|
return { type: 'pass' };
|
|
}
|
|
}
|
|
|
|
// A short think time so the AI doesn't snap instantly. Stronger players "decide"
|
|
// a touch faster; everyone gets a little jitter.
|
|
export function thinkDelay(skill = 3) {
|
|
const k = Math.max(1, Math.min(5, skill | 0));
|
|
return 420 + (5 - k) * 90 + Math.random() * 520;
|
|
}
|