You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.6 KiB

import { expect, it } from 'vitest';
import { go } from '../server/games/go.mjs';
import { oca } from '../server/games/oca.mjs';
it('Go captura grupos sin libertades y prohíbe el suicidio', () => {
const state = go.create();
state.board[10] = 2;
for (const n of [1, 9, 19]) state.board[n] = 1;
const next = go.apply(state, { type: 'move', to: 11 }, 0).state;
expect(next.board[10]).toBe(0);
expect(next.captures).toEqual([1, 0]);
expect(() => go.apply(next, { type: 'move', to: 10 }, 1)).toThrow();
});
it('Go no permite repetir una posición anterior', () => {
const state = go.create(),
next = [...state.board];
next[40] = 1;
state.history.push(next.join(''));
expect(go.legal(state, 0).some((a) => a.type === 'move' && a.to === 40)).toBe(
false,
);
});
it('Go necesita dos pases y el acuerdo de ambos para terminar', () => {
let state = go.apply(go.create(), { type: 'pass' }, 0).state;
state = go.apply(state, { type: 'pass' }, 1).state;
expect(state.phase).toBe('scoring');
const first = go.apply(state, { type: 'accept-score' }, 0);
expect(first.result).toBeNull();
const second = go.apply(first.state, { type: 'accept-score' }, 1);
expect(second.result?.winner).toBe(1);
expect(second.state.scores).toEqual([0, 6.5]);
});
it('la oca resuelve el movimiento, la repetición y los descansos en el servidor', () => {
const first = oca.apply(oca.create(2), { type: 'roll' }, 0, () => 5);
expect(first.state.positions[0]).toBe(9);
expect(first.state.turn).toBe(0);
expect(first.state.lastEffect).toBe('bonus');
const state = oca.create(2);
state.positions = [18, 1];
const inn = oca.apply(state, { type: 'roll' }, 0, () => 1).state;
expect(inn.skips[0]).toBe(1);
expect(inn.turn).toBe(1);
expect(inn.lastEffect).toBe('penalty');
const next = oca.apply(inn, { type: 'roll' }, 1, () => 1).state;
expect(next.turn).toBe(1);
expect(next.skips[0]).toBe(0);
});
it('la oca rebota si se pasa y exige el número exacto para ganar', () => {
const state = oca.create(2);
state.positions[0] = 61;
expect(
oca.apply(state, { type: 'roll' }, 0, () => 4).state.positions[0],
).toBe(61);
expect(oca.apply(state, { type: 'roll' }, 0, () => 2).result?.winner).toBe(0);
});
it('la última oca conserva la posición y su mensaje no anuncia una llegada a meta', () => {
const state = oca.create(2);
state.positions[0] = 58;
const result = oca.apply(state, { type: 'roll' }, 0, () => 1);
expect(result.state.positions[0]).toBe(59);
expect(result.state.turn).toBe(0);
expect(result.label).toContain('oca: 59');
expect(result.result).toBeNull();
});

Powered by TurnKey Linux.