import { describe, expect, it } from 'vitest';
import { BOARD_SIZE, centre, premiumGrid } from './premiums';

// Premium-square geometry parity with scrabble-solver/rules/rules.go: scrabble_en/scrabble_ru
// share standardBoard (centre is a double word); erudit_ru shares the geometry but a
// non-doubling centre. Tile-value and alphabet parity moved to the Go engine test
// (backend/internal/engine AlphabetTable) — the server now owns that table.
describe('premium layout', () => {
  it('is a 15x15 grid with TW corners', () => {
    const g = premiumGrid('scrabble_en');
    expect(g.length).toBe(BOARD_SIZE);
    expect(g[0].length).toBe(BOARD_SIZE);
    for (const [r, c] of [
      [0, 0],
      [0, 14],
      [14, 0],
      [14, 14],
    ]) {
      expect(g[r][c]).toBe('TW');
    }
  });

  it('doubles the centre for standard variants but not for erudit_ru', () => {
    expect(centre('scrabble_en')).toEqual({ row: 7, col: 7 });
    expect(premiumGrid('scrabble_en')[7][7]).toBe('DW');
    expect(premiumGrid('scrabble_ru')[7][7]).toBe('DW');
    expect(centre('erudit_ru')).toEqual({ row: 7, col: 7 });
    expect(premiumGrid('erudit_ru')[7][7]).toBe('');
  });

  it('keeps the standard premium counts', () => {
    const flat = premiumGrid('scrabble_en').flat();
    const count = (p: string) => flat.filter((x) => x === p).length;
    expect(count('TW')).toBe(8);
    expect(count('TL')).toBe(12);
    expect(count('DL')).toBe(24);
    expect(count('DW')).toBe(17); // 16 double-word squares + the centre
  });
});
