Chess
North Mini Code 1.0 GGUF · typescript

Reviews & generation details
Reviews
No human review yet. Unreviewed does not mean unsuccessful.
Generation context
Imported historical artifact. Its exact original instructions and lineage are not known.
Generation prompt · exact text unavailable
See the current prompt for reference. It may differ from the instructions used to generate this artifact.
Inspect original source 25,110 bytes · SHA-256 c4e0fd555473
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Chess</title>
<style>
</style>
</head>
<body>
<div id="app"></div>
<script>
(function () {
'use strict';
var __mods = {};
var __cache = {};
var __map = {"src/chessEngine.ts":{"./constants":"src/constants.ts"}};
function __require(id) {
if (__cache[id]) return __cache[id].exports;
var module = __cache[id] = { exports: {} };
var factory = __mods[id];
if (!factory) throw new Error("Module not found: " + id);
factory(module.exports, function (spec) {
var target = (__map[id] && __map[id][spec]) || spec;
return __require(target);
}, module);
return module.exports;
}
// ── module: src/main.ts ──
__mods["src/main.ts"] = function (exports, require, module) {
"use strict";
// Entry point. Runs after the DOM is parsed and after any classic
// <script> imports, so document queries and CDN globals are available.
// Import your other modules from here.
Object.defineProperty(exports, "__esModule", { value: true });
exports.start = start;
function start() {
// Replace this with the real startup sequence.
}
start();
};
// ── module: src/constants.ts ──
__mods["src/constants.ts"] = function (exports, require, module) {
"use strict";
/**
* Constants and configuration for the chess engine.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.AI_DEPTHS = exports.DRAW_50_MOVES = exports.DEFAULT_CASTLE_BLACK = exports.DEFAULT_CASTLE_WHITE = exports.CASTLE_BOTH = exports.CASTLE_QSIDE = exports.CASTLE_KSIDE = exports.CASTLE_NONE = exports.EMPTY = exports.COLORS = exports.PIECE_TYPES = exports.SQUARE_NAMES = exports.RANKS = exports.FILES = void 0;
exports.FILES = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'];
exports.RANKS = [8, 7, 6, 5, 4, 3, 2, 1];
exports.SQUARE_NAMES = exports.FILES.flatMap((f, i) => exports.RANKS.map((r) => `${f}${r}`));
exports.PIECE_TYPES = ['p', 'n', 'b', 'r', 'q', 'k'];
exports.COLORS = ['w', 'b'];
exports.EMPTY = null;
// Castling rights
exports.CASTLE_NONE = 0;
exports.CASTLE_KSIDE = 1; // king side
exports.CASTLE_QSIDE = 2; // queen side
exports.CASTLE_BOTH = exports.CASTLE_KSIDE | exports.CASTLE_QSIDE;
exports.DEFAULT_CASTLE_WHITE = exports.CASTLE_BOTH;
exports.DEFAULT_CASTLE_BLACK = exports.CASTLE_BOTH;
// 50-move rule and move counter
exports.DRAW_50_MOVES = 50;
// Zobrist hashing not needed for now
// AI depths per difficulty
exports.AI_DEPTHS = {
easy: 1,
medium: 2,
hard: 3,
};
};
// ── module: src/chessEngine.ts ──
__mods["src/chessEngine.ts"] = function (exports, require, module) {
"use strict";
/**
* Board representation and move generation for chess.
* Uses 0x88 board representation for efficiency.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.initPosition = initPosition;
exports.setupBoard = setupBoard;
exports.generateMoves = generateMoves;
exports.getLegalMoves = getLegalMoves;
exports.makeMove = makeMove;
exports.isInCheck = isInCheck;
exports.isCheckmate = isCheckmate;
exports.isStalemate = isStalemate;
exports.isDraw = isDraw;
exports.getGameResult = getGameResult;
exports.squareToAlgebraic = squareToAlgebraic;
exports.algebraicToSquare = algebraicToSquare;
const constants_1 = require("./constants");
// 0x88 board representation
const SQ = (index) => index & 0x88;
const OFF = (index) => index & 0x87;
const A1 = 0;
const B1 = 1;
const C1 = 2;
const D1 = 3;
const E1 = 4;
const F1 = 5;
const G1 = 6;
const H1 = 7;
const A8 = 0x70;
const B8 = 0x71;
const C8 = 0x72;
const D8 = 0x73;
const E8 = 0x74;
const F8 = 0x75;
const G8 = 0x76;
const H8 = 0x77;
// Square index to file and rank
function squareToFile(square) {
return square & 0x87;
}
function squareToRank(square) {
return (square >> 4) & 0x0F;
}
// Convert between algebraic notation and square index
function algebraicToSquare(alg) {
const file = alg.charCodeAt(0) - 97; // a=0, b=1, ..., h=7
const rank = parseInt(alg[1]) - 1; // 1=0, 2=1, ..., 8=0
return rank * 16 + file;
}
function squareToAlgebraic(square) {
const file = String.fromCharCode(97 + (square & 0x87));
const rank = String(8 - ((square >> 4) & 0x0F));
return `${file}${rank}`;
}
// Initialize starting position
function initPosition() {
return {
board: new Array(128).fill(null),
turn: 'w',
castlingRights: (constants_1.DEFAULT_CASTLE_WHITE << 8) | constants_1.DEFAULT_CASTLE_BLACK,
enPassantSquare: null,
halfmoveClock: 0,
fullmoveNumber: 1,
};
}
// Set up pieces on the board
function setupBoard(position) {
// Clear board
for (let i = 0; i < 128; i++) {
position.board[i] = null;
}
// Set up pieces
const backRank = [0, 1, 2, 3, 4, 5, 6, 7]; // rank 1 (0-indexed)
const pawnRank = 0x10; // rank 2 (0-indexed)
// White pieces
for (const square of backRank) {
position.board[square] = { type: 'r', color: 'w' };
}
position.board[0x10] = { type: 'p', color: 'w' };
for (let i = 1; i < 8; i++) {
position.board[0x10 + i] = { type: 'p', color: 'w' };
}
for (let i = 8; i < 16; i++) {
position.board[i] = { type: 'p', color: 'w' };
}
// Black pieces
for (const square of [0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77]) {
position.board[square] = { type: 'r', color: 'b' };
}
position.board[0x70 + 0x10] = { type: 'p', color: 'b' };
for (let i = 1; i < 8; i++) {
position.board[0x70 + 0x10 + i] = { type: 'p', color: 'b' };
}
for (let i = 0x70 + 8; i < 0x70 + 16; i++) {
position.board[i] = { type: 'p', color: 'b' };
}
// Pieces on back ranks
position.board[A8] = { type: 'r', color: 'b' };
position.board[B8] = { type: 'n', color: 'b' };
position.board[C8] = { type: 'b', color: 'b' };
position.board[D8] = { type: 'q', color: 'b' };
position.board[E8] = { type: 'k', color: 'b' };
position.board[F8] = { type: 'b', color: 'b' };
position.board[G8] = { type: 'n', color: 'b' };
position.board[H8] = { type: 'r', color: 'b' };
position.board[A1] = { type: 'r', color: 'w' };
position.board[B1] = { type: 'n', color: 'w' };
position.board[C1] = { type: 'b', color: 'w' };
position.board[D1] = { type: 'q', color: 'w' };
position.board[E1] = { type: 'k', color: 'w' };
position.board[F1] = { type: 'b', color: 'w' };
position.board[G1] = { type: 'n', color: 'w' };
position.board[H1] = { type: 'r', color: 'w' };
}
// Helper functions
function isWhite(color) { return color === 'w'; }
function isBlack(color) { return color === 'b'; }
function isSquareOccupied(board, square) {
return board[square] !== null;
}
function getPiece(board, square) {
return board[square];
}
function getPieceColor(board, square) {
const piece = getPiece(board, square);
return piece ? piece.color : null;
}
function getPieceType(board, square) {
const piece = getPiece(board, square);
return piece ? piece.type : null;
}
function isFriendly(board, fromSquare, toSquare, turn) {
const piece = getPiece(board, toSquare);
return piece !== null && piece.color === turn;
}
function isOpponent(board, fromSquare, toSquare, turn) {
const piece = getPiece(board, toSquare);
return piece !== null && piece.color !== turn;
}
// Generate all legal moves for the current position
function generateMoves(position) {
const moves = [];
const { board, turn } = position;
for (let from = 0; from < 128; from++) {
const piece = board[from];
if (piece === null || piece.color !== turn)
continue;
const type = piece.type;
// Generate moves based on piece type
if (type === 'p') {
generatePawnMoves(position, from, moves);
}
else if (type === 'n') {
generateKnightMoves(position, from, moves);
}
else if (type === 'b') {
generateBishopMoves(position, from, moves);
}
else if (type === 'r') {
generateRookMoves(position, from, moves);
}
else if (type === 'q') {
generateQueenMoves(position, from, moves);
}
else if (type === 'k') {
generateKingMoves(position, from, moves);
}
}
// Filter moves that leave own king in check
return moves.filter(move => {
const newPosition = makeMove(position, move);
return !isInCheck(newPosition, turn);
});
}
function generatePawnMoves(position, from, moves) {
const { board, turn, enPassantSquare } = position;
const piece = board[from];
if (piece === null)
return;
const direction = piece.color === 'w' ? -16 : 16;
const startRank = piece.color === 'w' ? 6 : 1;
// Forward one square
const to = from + direction;
if (SQ(to) === 0 && board[to] === null) {
// Regular move
moves.push(squareToAlgebraic(from) + squareToAlgebraic(to));
// Forward two squares from starting rank
if (from >= startRank * 16 && from < (startRank + 1) * 16) {
const to2 = from + direction * 2;
if (board[to2] === null) {
moves.push(squareToAlgebraic(from) + squareToAlgebraic(to2));
}
}
}
// Captures (left and right diagonals)
const left = from - 1;
const right = from + 1;
if (SQ(left) !== 0 && left % 16 !== 15 && board[left] !== null && board[left].color !== piece.color) {
// Regular capture
moves.push(squareToAlgebraic(from) + squareToAlgebraic(left));
}
if (SQ(right) !== 0 && right % 16 !== 0 && board[right] !== null && board[right].color !== piece.color) {
// Regular capture
moves.push(squareToAlgebraic(from) + squareToAlgebraic(right));
}
// En passant
if (enPassantSquare !== null) {
const epSquare = algebraicToSquare(enPassantSquare);
const left = from - 1;
const right = from + 1;
if (SQ(left) !== 0 && left % 16 !== 15 && left === epSquare) {
moves.push(squareToAlgebraic(from) + squareToAlgebraic(left) + ' e.p.');
}
if (SQ(right) !== 0 && right % 16 !== 0 && right === epSquare) {
moves.push(squareToAlgebraic(from) + squareToAlgebraic(right) + ' e.p.');
}
}
}
function generateKnightMoves(position, from, moves) {
const { board } = position;
const piece = board[from];
if (piece === null)
return;
const knightMoves = [15, 17, -15, -17, 10, -6, 6, -10];
for (const delta of knightMoves) {
const to = from + delta;
if (SQ(to) === 0 && board[to] !== piece) {
// Can move to this square
if (board[to] === null || board[to].color !== piece.color) {
moves.push(squareToAlgebraic(from) + squareToAlgebraic(to));
}
}
}
}
function generateBishopMoves(position, from, moves) {
const { board } = position;
const piece = board[from];
if (piece === null)
return;
const directions = [15, 17, -15, -17];
for (const delta of directions) {
let to = from + delta;
while (SQ(to) !== 0 && (to & 0x87) !== (from & 0x87)) {
if (board[to] === null) {
moves.push(squareToAlgebraic(from) + squareToAlgebraic(to));
}
else {
if (board[to].color !== piece.color) {
moves.push(squareToAlgebraic(from) + squareToAlgebraic(to));
}
break;
}
to += delta;
}
}
}
function generateRookMoves(position, from, moves) {
const { board } = position;
const piece = board[from];
if (piece === null)
return;
const directions = [16, -16, 1, -1];
for (const delta of directions) {
let to = from + delta;
while (SQ(to) !== 0 && (to & 0x87) !== (from & 0x87)) {
if (board[to] === null) {
moves.push(squareToAlgebraic(from) + squareToAlgebraic(to));
}
else {
if (board[to].color !== piece.color) {
moves.push(squareToAlgebraic(from) + squareToAlgebraic(to));
}
break;
}
to += delta;
}
}
}
function generateQueenMoves(position, from, moves) {
const { board } = position;
const piece = board[from];
if (piece === null)
return;
const directions = [15, 17, -15, -17, 16, -16, 1, -1];
for (const delta of directions) {
let to = from + delta;
while (SQ(to) !== 0 && (to & 0x87) !== (from & 0x87)) {
if (board[to] === null) {
moves.push(squareToAlgebraic(from) + squareToAlgebraic(to));
}
else {
if (board[to].color !== piece.color) {
moves.push(squareToAlgebraic(from) + squareToAlgebraic(to));
}
break;
}
to += delta;
}
}
}
function generateKingMoves(position, from, moves) {
const { board, turn } = position;
const piece = board[from];
if (piece === null)
return;
const kingMoves = [15, 17, -15, -17, 16, -16, 1, -1];
for (const delta of kingMoves) {
const to = from + delta;
if (SQ(to) === 0 && (to & 0x87) !== (from & 0x87)) {
if (board[to] === null || board[to].color !== piece.color) {
// Check if this move would put own king in check
const newPosition = makeMove(position, squareToAlgebraic(from) + squareToAlgebraic(to));
if (!isInCheck(newPosition, turn)) {
moves.push(squareToAlgebraic(from) + squareToAlgebraic(to));
}
}
}
}
// Castling
const castlingRights = turn === 'w' ? (position.castlingRights >> 8) & 0x0F : position.castlingRights & 0x0F;
if ((castlingRights & constants_1.CASTLE_KSIDE) &&
!isSquareInCheck(position, from) &&
!isSquareOccupied(position, from + 1) &&
!isSquareOccupied(position, from + 2) &&
!isSquareInCheck(position, from + 1) &&
!isSquareInCheck(position, from + 2)) {
moves.push('O-O');
}
if ((castlingRights & constants_1.CASTLE_QSIDE) &&
!isSquareInCheck(position, from) &&
!isSquareOccupied(position, from - 1) &&
!isSquareOccupied(position, from - 2) &&
!isSquareOccupied(position, from - 3) &&
!isSquareInCheck(position, from - 1) &&
!isSquareInCheck(position, from - 2)) {
moves.push('O-O-O');
}
}
function isSquareInCheck(position, square) {
const { board, turn } = position;
const opponentColor = turn === 'w' ? 'b' : 'w';
// Check for opponent pieces attacking this square
for (let from = 0; from < 128; from++) {
const piece = board[from];
if (piece === null || piece.color !== opponentColor)
continue;
const type = piece.type;
if (type === 'p') {
if (isPawnAttack(position, from, square))
return true;
}
else if (type === 'n') {
if (isKnightAttack(position, from, square))
return true;
}
else if (type === 'b') {
if (isDiagonalAttack(position, from, square))
return true;
}
else if (type === 'r') {
if (isStraightAttack(position, from, square))
return true;
}
else if (type === 'q') {
if (isDiagonalAttack(position, from, square) || isStraightAttack(position, from, square))
return true;
}
else if (type === 'k') {
if (isKingAttack(position, from, square))
return true;
}
}
return false;
}
function isPawnAttack(position, from, to) {
const { board } = position;
const piece = board[from];
if (piece === null || piece.type !== 'p')
return false;
const direction = piece.color === 'w' ? -16 : 16;
const left = from - 1;
const right = from + 1;
return to === left + direction || to === right + direction;
}
function isKnightAttack(position, from, to) {
const delta = Math.abs(to - from);
return (delta === 15 || delta === 17 || delta === 10 || delta === 6 ||
delta === -6 || delta === -10 || delta === -15 || delta === -17);
}
function isDiagonalAttack(position, from, to) {
const delta = Math.abs(to - from);
return delta === 15 || delta === 17 || delta === -15 || delta === -17;
}
function isStraightAttack(position, from, to) {
const delta = Math.abs(to - from);
return delta === 16 || delta === -16 || delta === 1 || delta === -1 ||
(to & 0x87) === (from & 0x87) && delta > 1;
}
function isKingAttack(position, from, to) {
const delta = Math.abs(to - from);
return delta <= 1 && delta > 0 && (to & 0x87) !== (from & 0x87);
}
function isInCheck(position, color) {
const { board } = position;
const kingSquare = findKingSquare(position, color);
return kingSquare !== null && isSquareInCheck(position, kingSquare);
}
function findKingSquare(position, color) {
const { board } = position;
for (let i = 0; i < 128; i++) {
const piece = board[i];
if (piece !== null && piece.type === 'k' && piece.color === color) {
return i;
}
}
return null;
}
function makeMove(position, move) {
const newPosition = {
board: [...position.board],
turn: position.turn,
castlingRights: position.castlingRights,
enPassantSquare: position.enPassantSquare,
halfmoveClock: position.halfmoveClock,
fullmoveNumber: position.fullmoveNumber,
};
const fromAlgebraic = move.substring(0, 2);
const toAlgebraic = move.substring(2, 4);
const from = algebraicToSquare(fromAlgebraic);
const to = algebraicToSquare(toAlgebraic);
const movingPiece = newPosition.board[from];
if (movingPiece === null)
return newPosition;
// Handle special moves
if (move === 'O-O') {
// King-side castling
const kingFrom = algebraicToSquare('e1');
const rookFrom = algebraicToSquare('h1');
const kingTo = algebraicToSquare('g1');
const rookTo = algebraicToSquare('f1');
newPosition.board[kingTo] = { type: 'k', color: 'w' };
newPosition.board[kingFrom] = null;
newPosition.board[rookTo] = { type: 'r', color: 'w' };
newPosition.board[rookFrom] = null;
// Update castling rights
newPosition.castlingRights &= 0x0F; // Clear white castling rights
newPosition.castlingRights &= ~constants_1.CASTLE_KSIDE; // Remove king-side right
// Switch turn
newPosition.turn = 'b';
newPosition.fullmoveNumber++;
return newPosition;
}
else if (move === 'O-O-O') {
// Queen-side castling
const kingFrom = algebraicToSquare('e1');
const rookFrom = algebraicToSquare('a1');
const kingTo = algebraicToSquare('c1');
const rookTo = algebraicToSquare('d1');
newPosition.board[kingTo] = { type: 'k', color: 'w' };
newPosition.board[kingFrom] = null;
newPosition.board[rookTo] = { type: 'r', color: 'w' };
newPosition.board[rookFrom] = null;
// Update castling rights
newPosition.castlingRights &= 0x0F; // Clear white castling rights
newPosition.castlingRights &= ~constants_1.CASTLE_QSIDE; // Remove queen-side right
// Switch turn
newPosition.turn = 'b';
newPosition.fullmoveNumber++;
return newPosition;
}
const capturedPiece = newPosition.board[to];
// Handle pawn moves
if (movingPiece.type === 'p') {
// Check for promotion
const rank = squareToRank(to);
if (rank === 0 || rank === 7) {
// Promotion - we'll handle this in UI
newPosition.board[to] = { type: 'q', color: movingPiece.color }; // Default to queen
}
else {
newPosition.board[to] = movingPiece;
}
newPosition.board[from] = null;
// Check for en passant
if (move.includes(' e.p.')) {
// Remove captured pawn
if (movingPiece.color === 'w') {
const capturedPawnSquare = to + 16; // White pawn captured from below
newPosition.board[capturedPawnSquare] = null;
}
else {
const capturedPawnSquare = to - 16; // Black pawn captured from above
newPosition.board[capturedPawnSquare] = null;
}
}
// Update castling rights (pawns moved)
if (movingPiece.color === 'w') {
newPosition.castlingRights &= ~0x0F; // Clear white castling rights
}
else {
newPosition.castlingRights &= ~0xF0; // Clear black castling rights
}
// Set en passant square
const direction = movingPiece.color === 'w' ? 16 : -16;
const left = from - 1;
const right = from + 1;
if (SQ(left) !== 0 && left % 16 !== 15 &&
newPosition.board[left] !== null && newPosition.board[left].type === 'p' &&
newPosition.board[left].color !== movingPiece.color) {
newPosition.enPassantSquare = squareToAlgebraic(left + direction);
}
else if (SQ(right) !== 0 && right % 16 !== 0 &&
newPosition.board[right] !== null && newPosition.board[right].type === 'p' &&
newPosition.board[right].color !== movingPiece.color) {
newPosition.enPassantSquare = squareToAlgebraic(right + direction);
}
else {
newPosition.enPassantSquare = null;
}
}
else {
// Regular piece move
newPosition.board[to] = movingPiece;
newPosition.board[from] = null;
// Update castling rights
if (movingPiece.type === 'k') {
if (movingPiece.color === 'w') {
newPosition.castlingRights &= ~0x0F; // Clear white castling rights
}
else {
newPosition.castlingRights &= ~0xF0; // Clear black castling rights
}
}
else if (movingPiece.type === 'r') {
// Check if this rook was on its original square
const originalWhiteRookSquares = [algebraicToSquare('a1'), algebraicToSquare('h1')];
const originalBlackRookSquares = [algebraicToSquare('a8'), algebraicToSquare('h8')];
if (movingPiece.color === 'w' && originalWhiteRookSquares.includes(from)) {
if (movingPiece.type === 'r') {
newPosition.castlingRights &= ~(movingPiece.color === 'w' ? constants_1.CASTLE_QSIDE : constants_1.CASTLE_KSIDE);
}
}
else if (movingPiece.color === 'b' && originalBlackRookSquares.includes(from)) {
if (movingPiece.type === 'r') {
newPosition.castlingRights &= ~(movingPiece.color === 'w' ? constants_1.CASTLE_QSIDE : constants_1.CASTLE_KSIDE);
}
}
}
// Reset en passant square
newPosition.enPassantSquare = null;
}
// Increment halfmove clock
if (movingPiece.type !== 'p' && capturedPiece === null) {
newPosition.halfmoveClock++;
}
else {
newPosition.halfmoveClock = 0;
}
// Switch turn
newPosition.turn = newPosition.turn === 'w' ? 'b' : 'w';
// Increment fullmove number on black's turn
if (newPosition.turn === 'b') {
newPosition.fullmoveNumber++;
}
return newPosition;
}
function getLegalMoves(position) {
return generateMoves(position);
}
function isCheckmate(position, color) {
if (!isInCheck(position, color))
return false;
return getLegalMoves(position).length === 0;
}
function isStalemate(position, color) {
if (isInCheck(position, color))
return false;
return getLegalMoves(position).length === 0;
}
function isDraw(position) {
// Check for 50-move rule
if (position.halfmoveClock >= constants_1.DRAW_50_MOVES)
return true;
// Check for threefold repetition (simplified - would need Zobrist hashing)
// For now, just return false
return false;
}
function getGameResult(position) {
const { turn } = position;
if (isCheckmate(position, turn))
return 'checkmate';
if (isStalemate(position, turn))
return 'stalemate';
if (isDraw(position))
return 'draw';
return 'ongoing';
}
};
// ── entry ──
__require("src/main.ts");
})();
</script>
</body>
</html>
<!-- agent-meta {"model":"unsloth/North-Mini-Code-1.0-GGUF","provider":"brigid","persona":"typescript","sessionId":"17515ede-1e11-4c6b-a9e4-565ce2afbf4d","tokensIn":268876,"tokensOut":18591,"tokensTotal":287467,"cost":0,"turns":15,"toolCalls":14,"failedToolCalls":2,"timestamp":"2026-08-07T23:10:23.377Z"} -->