@nodots-llc/backgammon-ai
Version:
AI and integration for nodots-backgammon using gnubg as a backend engine.
76 lines (75 loc) • 3.37 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
// Mock axios before any imports
jest.mock('axios', () => ({
post: jest.fn().mockResolvedValue({
data: { output: 'mocked gnubg output' },
}),
}));
// Mock getBestMoveFromGnubg to always resolve
jest.mock('../gnubgApi', () => ({
getBestMoveFromGnubg: jest.fn().mockResolvedValue('mocked gnubg output'),
}));
const path_1 = __importDefault(require("path"));
const pluginLoader_1 = require("../pluginLoader");
describe('Plugin Analyzers', () => {
const pluginsDir = path_1.default.join(__dirname, '../../plugins');
const analyzers = (0, pluginLoader_1.loadAnalyzersFromPluginsDir)(pluginsDir);
// Minimal mock moves
const moves = [
{
id: '1',
player: {},
dieValue: 6,
stateKind: 'ready',
moveKind: 'point-to-point',
origin: { position: { clockwise: 10, counterclockwise: 15 } },
},
{
id: '2',
player: {},
dieValue: 3,
stateKind: 'ready',
moveKind: 'point-to-point',
origin: { position: { clockwise: 20, counterclockwise: 5 } },
},
{
id: '3',
player: {},
dieValue: 1,
stateKind: 'ready',
moveKind: 'point-to-point',
origin: { position: { clockwise: 5, counterclockwise: 20 } },
},
];
it('randomMoveAnalyzer returns one of the moves', () => __awaiter(void 0, void 0, void 0, function* () {
const move = yield analyzers['randomMoveAnalyzer'].selectMove(moves);
expect(moves).toContain(move);
}));
it('furthestFromOffMoveAnalyzer returns the move with highest clockwise position', () => __awaiter(void 0, void 0, void 0, function* () {
const move = yield analyzers['furthestFromOffMoveAnalyzer'].selectMove(moves);
expect(move).toBe(moves[1]); // clockwise: 20 is highest
}));
it('examplePluginAnalyzer returns the first move', () => __awaiter(void 0, void 0, void 0, function* () {
const move = yield analyzers['examplePluginAnalyzer'].selectMove(moves);
expect(move).toBe(moves[0]);
}));
it('gnubgMoveAnalyzer returns the first move (stub, logs GNUBG output)', () => __awaiter(void 0, void 0, void 0, function* () {
const move = yield analyzers['gnubgMoveAnalyzer'].selectMove(moves, {
positionId: 'dummy-xgid-string',
});
expect(move).toBe(moves[0]);
}));
});