Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JSDoc comments and documentation #184

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
more fixes to true/false. Improved types on some classes
  • Loading branch information
StevenStavrakis committed Jun 3, 2024
commit 2ef1c2ce9e994091c6d851ad0ce9d1b2fb6815f9
4 changes: 2 additions & 2 deletions src/board.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export class Board implements Iterable<[Square, Piece]>, ByRole<SquareSet>, ByCo
/**
* Checks if the given square is occupied by a piece.
* @param {Square} square The square to check.
* @returns {boolean} True if the square is occupied, false otherwise.
* @returns {boolean} `true` if the square is occupied, `false` otherwise.
*/
has(square: Square): boolean {
return this.occupied.has(square);
Expand Down Expand Up @@ -228,7 +228,7 @@ export class Board implements Iterable<[Square, Piece]>, ByRole<SquareSet>, ByCo
* Checks if two boards are equal.
* @param {Board} left The first board.
* @param {Board} right The second board.
* @returns {boolean} True if the boards are equal, false otherwise.
* @returns {boolean} `true` if the boards are equal, `false` otherwise.
*/
export const boardEquals = (left: Board, right: Board): boolean =>
left.white.equals(right.white)
Expand Down
37 changes: 34 additions & 3 deletions src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,22 +313,53 @@ export class RemainingChecks implements ByColor<number> {
* Represents the setup of a chess position.
* @interface Setup
* @property {Board} board The chess board.
* @property {Material | undefined} pockets The material in the pockets (optional).
* @property {Material | undefined} pockets The material in the pockets.
* @property {Color} turn The color of the side to move.
* @property {SquareSet} castlingRights The castling rights.
* @property {Square | undefined} epSquare The en passant square (optional).
* @property {RemainingChecks | undefined} remainingChecks The remaining checks (optional).
* @property {Square | undefined} epSquare A square where en passant is possible.
* @property {RemainingChecks | undefined} remainingChecks The remaining checks.
* @property {number} halfmoves The number of halfmoves since the last pawn advance or capture.
* @property {number} fullmoves The number of fullmoves.
*/
export interface Setup {
/**
* The chess board.
*/
board: Board;
/**
* The material in the pockets.
*/
pockets: Material | undefined;
/**
* The color of the side to move.
*/
turn: Color;
/**
* The castling rights.
*/
castlingRights: SquareSet;
/**
* A square where en passant is possible.
*/
epSquare: Square | undefined;

/**
* The remaining checks. Used in multi-check variants.
*/
remainingChecks: RemainingChecks | undefined;

/**
* The number of halfmoves since the last pawn advance or capture.
*
* A halfmove is when a side makes a move.
*/
halfmoves: number;

/**
* The number of fullmoves.
*
* A fullmove is when both sides make a move.
*/
fullmoves: number;
}

Expand Down
20 changes: 10 additions & 10 deletions src/squareSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export class SquareSet implements Iterable<Square> {
* Two SquareSets are considered to intersect if they have at least one square in common.
*
* @param {SquareSet} other The SquareSet to check for intersection.
* @returns {boolean} True if the current set intersects with the other set, false otherwise.
* @returns {boolean} `true` if the current set intersects with the other set, `false` otherwise.
*/
intersects(other: SquareSet): boolean {
return this.intersect(other).nonEmpty();
Expand All @@ -205,7 +205,7 @@ export class SquareSet implements Iterable<Square> {
* Two SquareSets are considered to be disjoint if they have no squares in common.
*
* @param {SquareSet} other The SquareSet to check for disjointness.
* @returns {boolean} True if the current set is disjoint with the other set, false otherwise.
* @returns {boolean} `true` if the current set is disjoint with the other set, `false` otherwise.
*/
isDisjoint(other: SquareSet): boolean {
return this.intersect(other).isEmpty();
Expand All @@ -217,7 +217,7 @@ export class SquareSet implements Iterable<Square> {
* A SquareSet is a superset of another SquareSet if every square in the other set is also present in the current set.
*
* @param {SquareSet} other The SquareSet to check for supersetness.
* @returns {boolean} True if the current set is a superset of the other set, false otherwise.
* @returns {boolean} `true` if the current set is a superset of the other set, `false` otherwise.
*/
supersetOf(other: SquareSet): boolean {
return other.diff(this).isEmpty();
Expand All @@ -229,7 +229,7 @@ export class SquareSet implements Iterable<Square> {
* A SquareSet is a subset of another SquareSet if every square in the current set is also present in the other set.
*
* @param {SquareSet} other The SquareSet to check for subsetness.
* @returns {boolean} True if the current set is a subset of the other set, false otherwise.
* @returns {boolean} `true` if the current set is a subset of the other set, `false` otherwise.
*/
subsetOf(other: SquareSet): boolean {
return this.diff(other).isEmpty();
Expand Down Expand Up @@ -301,7 +301,7 @@ export class SquareSet implements Iterable<Square> {
* Checks if the current SquareSet is equal to another SquareSet.
*
* @param {SquareSet} other The SquareSet to compare with.
* @returns {boolean} True if the SquareSets are equal, false otherwise.
* @returns {boolean} `true` if the SquareSets are equal, `false` otherwise.
*/
equals(other: SquareSet): boolean {
return this.lo === other.lo && this.hi === other.hi;
Expand All @@ -319,7 +319,7 @@ export class SquareSet implements Iterable<Square> {
/**
* Checks if the SquareSet is empty.
*
* @returns {boolean} True if the SquareSet is empty, false otherwise.
* @returns {boolean} `true` if the SquareSet is empty, `false` otherwise.
*/
isEmpty(): boolean {
return this.lo === 0 && this.hi === 0;
Expand All @@ -328,7 +328,7 @@ export class SquareSet implements Iterable<Square> {
/**
* Checks if the SquareSet is not empty.
*
* @returns {boolean} True if the SquareSet is not empty, false otherwise.
* @returns {boolean} `true` if the SquareSet is not empty, `false` otherwise.
*/
nonEmpty(): boolean {
return this.lo !== 0 || this.hi !== 0;
Expand All @@ -338,7 +338,7 @@ export class SquareSet implements Iterable<Square> {
* Checks if the SquareSet contains a specific square.
*
* @param {Square} square The square to check for presence.
* @returns {boolean} True if the SquareSet contains the square, false otherwise.
* @returns {boolean} `true` if the SquareSet contains the square, `false` otherwise.
*/
has(square: Square): boolean {
return (square >= 32 ? this.hi & (1 << (square - 32)) : this.lo & (1 << square)) !== 0;
Expand All @@ -348,7 +348,7 @@ export class SquareSet implements Iterable<Square> {
* Sets or unsets a square in the SquareSet.
*
* @param {Square} square The square to set or unset.
* @param {boolean} on True to set the square, false to unset it.
* @param {boolean} on `true` to set the square, `false` to unset it.
* @returns {SquareSet} A new SquareSet with the square set or unset.
*/
set(square: Square, on: boolean): SquareSet {
Expand Down Expand Up @@ -426,7 +426,7 @@ export class SquareSet implements Iterable<Square> {
/**
* Checks if the SquareSet contains more than one square.
*
* @returns {boolean} True if the SquareSet contains more than one square, false otherwise.
* @returns {boolean} `true` if the SquareSet contains more than one square, `false` otherwise.
*/
moreThanOne(): boolean {
return (this.hi !== 0 && this.lo !== 0) || (this.lo & (this.lo - 1)) !== 0 || (this.hi & (this.hi - 1)) !== 0;
Expand Down
2 changes: 1 addition & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export const parseUci = (str: string): Move | undefined => {
* @function moveEquals
* @param {Move} left The first move to compare.
* @param {Move} right The second move to compare.
* @returns {boolean} True if the moves are equal, false otherwise.
* @returns {boolean} `true` if the moves are equal, `false` otherwise.
*/
export const moveEquals = (left: Move, right: Move): boolean => {
if (left.to !== right.to) return false;
Expand Down