<commit_before>import {
	WHITE,
	BLACK,
	KING,
	QUEEN,
	KNIGHT,
	BISHOP,
	ROOK,
	PAWN,
} from './brands';
import {
	entries,
	identity,
	squareName,
	squareCoords,
	oppositeColor,
	bounded,
} from './util';
import { Mobility } from './piece/mobility';
import { Castling } from './piece/king/castling';
import { EnPassantTarget } from './piece/pawn/eptarget'
import { Point } from './point';
import { MobilityError, CheckError } from './error'
// MODULE
export class Position {

	constructor({
		ranks=8,
		files=8,
		activeColor=WHITE,
		castling=true,
		enPassantTarget=null,
		halfmoveClock=0,
		fullmoveClock=0,
		board=null,
	} = {}) {
		this.ranks = ranks;
		this.files = files;
		this.board = createBoard(ranks, files);
		this.activeColor = activeColor || WHITE;
		this.castling = new Castling(castling);
		this.enPassantTarget = new EnPassantTarget(enPassantTarget);
		this.halfmoveClock = halfmoveClock;
		this.fullmoveClock = fullmoveClock;
		this.pieces = new Set();
		this.pieces[KING] = new Set();
		this.pieces[QUEEN] = new Set();
		this.pieces[KNIGHT] = new Set();
		this.pieces[BISHOP] = new Set();
		this.pieces[ROOK] = new Set();
		this.pieces[PAWN] = new Set();
		if (board) {
			decorateBoard(this, board);
		}
	}

	map(fn) {
		return this.board.map((rank, i) =>
			rank.map((piece, j) => fn(piece, i, j)));
	}

	getPieces(brand) {
		return brand == null ? this.pieces : this.pieces[brand];
	}

	getPiece(squareName) {
		return this.getPieceByCoords(squareCoords(squareName));
	}

	getCapturablePiece(squareNameP, capturerBrand=null) {
		if (capturerBrand !== PAWN || !this.enPassantTarget.equal(squareNameP)) {
			return [this.getPiece(squareNameP), squareNameP, false];
		}
		const coords = squareCoords(squareNameP);
		if (coords.equal(this.enPassantTarget)) {
			const captureSquare = coords.sum(new Point(0, coords.y === 2 ? 1 : -1));
			const capturedPiece = this.getPieceByCoords(captureSquare);
			return [
				capturedPiece,
				capturedPiece && squareName(captureSquare),
				!!capturedPiece
			];
		}
		return [null, null, false];
	}

	getPieceSquare(piece) {
		const coords = this.getPieceCoords(piece);
		return coords == null ? null : squareName(coords);
	}

	getPieceByCoords({ x, y }) {
		const rank = this.board[y];
		return rank == null ? null : rank[x];
	}

	getPieceCoords(piece) {
		for (var i = 0, iLen = this.board.length; i < iLen; i++) {
			const rank = this.board[i];
			for (var j = 0, jLen = rank.length; j < jLen; j++) {
				const p = rank[j];
				if (p === piece) {
					return new Point(j, i);
				}
			}
		}
		return null;
	}

	*queryAll(selector={}) {
		pieces: for (var piece of this.getPieces(selector.brand)) {
			for (var [val, key] of entries(selector)) {<commit_msg>code style: group like methods<commit_after>import {
	WHITE,
	BLACK,
	KING,
	QUEEN,
	KNIGHT,
	BISHOP,
	ROOK,
	PAWN,
} from './brands';
import {
	entries,
	identity,
	squareName,
	squareCoords,
	oppositeColor,
	bounded,
} from './util';
import { Mobility } from './piece/mobility';
import { Castling } from './piece/king/castling';
import { EnPassantTarget } from './piece/pawn/eptarget'
import { Point } from './point';
import { MobilityError, CheckError } from './error'
// MODULE
export class Position {

	constructor({
		ranks=8,
		files=8,
		activeColor=WHITE,
		castling=true,
		enPassantTarget=null,
		halfmoveClock=0,
		fullmoveClock=0,
		board=null,
	} = {}) {
		this.ranks = ranks;
		this.files = files;
		this.board = createBoard(ranks, files);
		this.activeColor = activeColor || WHITE;
		this.castling = new Castling(castling);
		this.enPassantTarget = new EnPassantTarget(enPassantTarget);
		this.halfmoveClock = halfmoveClock;
		this.fullmoveClock = fullmoveClock;
		this.pieces = new Set();
		this.pieces[KING] = new Set();
		this.pieces[QUEEN] = new Set();
		this.pieces[KNIGHT] = new Set();
		this.pieces[BISHOP] = new Set();
		this.pieces[ROOK] = new Set();
		this.pieces[PAWN] = new Set();
		if (board) {
			decorateBoard(this, board);
		}
	}

	map(fn) {
		return this.board.map((rank, i) =>
			rank.map((piece, j) => fn(piece, i, j)));
	}

	getPieces(brand) {
		return brand == null ? this.pieces : this.pieces[brand];
	}

	getPiece(squareName) {
		return this.getPieceByCoords(squareCoords(squareName));
	}

	getCapturablePiece(squareNameP, capturerBrand=null) {
		if (capturerBrand !== PAWN || !this.enPassantTarget.equal(squareNameP)) {
			return [this.getPiece(squareNameP), squareNameP, false];
		}
		const coords = squareCoords(squareNameP);
		if (coords.equal(this.enPassantTarget)) {
			const captureSquare = coords.sum(new Point(0, coords.y === 2 ? 1 : -1));
			const capturedPiece = this.getPieceByCoords(captureSquare);
			return [
				capturedPiece,
				capturedPiece && squareName(captureSquare),
				!!capturedPiece
			];
		}
		return [null, null, false];
	}

	getPieceSquare(piece) {
		const coords = this.getPieceCoords(piece);
		return coords == null ? null : squareName(coords);
	}

	getPieceCoords(piece) {
		for (var i = 0, iLen = this.board.length; i < iLen; i++) {
			const rank = this.board[i];
			for (var j = 0, jLen = rank.length; j < jLen; j++) {
				const p = rank[j];
				if (p === piece) {
					return new Point(j, i);
				}
			}
		}
		return null;
	}

	getPieceByCoords({ x, y }) {
		const rank = this.board[y];
		return rank == null ? null : rank[x];
	}

	*queryAll(selector={}) {
		pieces: for (var piece of this.getPieces(selector.brand)) {
			for (var [val, key] of entries(selector)) {
{'fraction_non_alphanumeric': 0.15425434583714548, 'fraction_numerical': 0.0036596523330283625, 'mean_word_length': 3.824360105913504, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1252334', 'n_tokens_mistral': 2266, 'n_tokens_neox': 2025, 'n_words': 442}