Skip to content

Commit

Permalink
Code cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
yo35 committed Sep 1, 2024
1 parent e32abe1 commit c0424c9
Show file tree
Hide file tree
Showing 34 changed files with 246 additions and 219 deletions.
1 change: 0 additions & 1 deletion demo/movegeneration.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ function run(fen, minDepth, maxDepth, verbose) {
}



// -----------------------------------------------------------------------------
// Command line parsing
// -----------------------------------------------------------------------------
Expand Down
3 changes: 1 addition & 2 deletions demo/pgnparsing.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,12 @@ function run(paths, pathAlignment) {
'Loading: ' + alignRight(duration2, 6) + ' ms');
}

for (const [path, error] of errors.entries()) {
for (const [ path, error ] of errors.entries()) {
displayInvalidPGNError(path, error);
}
}



// -----------------------------------------------------------------------------
// Command line parsing
// -----------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions src/base_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ export type Coordinates = {
* - ...
* - `7` for file H
*/
file: number;
file: number,

/**
* - `0` for rank 1
* - `1` for rank 2
* - ...
* - `7` for rank 8
*/
rank: number;
rank: number,
};


Expand Down
2 changes: 1 addition & 1 deletion src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export abstract class Database {
return {
[Symbol.iterator]() {
return new GameIteratorImpl(gameCount, gameLoader);
}
},
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/date_value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ function computeType(year: number, month?: number, day?: number): false | 'y' |
return isValidYear(year) && isValidMonth(month) ? 'ym' : false;
}
else {
return isValidYear(year) ? 'y': false;
return isValidYear(year) ? 'y' : false;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@ function formatPlayer(key: string, playerName: string | undefined, playerElo: nu
result += ` (${playerElo})`;
}
else if (playerTitle !== undefined) {
result += ` (${trimCollapseAndMarkEmpty(playerTitle)})`;
result += ` (${trimCollapseAndMarkEmpty(playerTitle)})`;
}
return result;
}
Expand Down
58 changes: 29 additions & 29 deletions src/game_pojo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ import { GameResult, GameVariant } from './base_types';
* Represent the player-related headers in a {@link GamePOJO}.
*/
export type PlayerPOJO = {
name?: string;
elo?: number;
title?: string;
name?: string,
elo?: number,
title?: string,
};


Expand All @@ -42,53 +42,53 @@ export type PlayerPOJO = {
export type GamePOJO = {

// Headers
white?: PlayerPOJO;
black?: PlayerPOJO;
event?: string;
round?: number;
subRound?: number;
subSubRound?: number;
date?: string;
site?: string;
annotator?: string;
eco?: string;
opening?: string;
openingVariation?: string;
openingSubVariation?: string;
termination?: string;
result?: GameResult;
white?: PlayerPOJO,
black?: PlayerPOJO,
event?: string,
round?: number,
subRound?: number,
subSubRound?: number,
date?: string,
site?: string,
annotator?: string,
eco?: string,
opening?: string,
openingVariation?: string,
openingSubVariation?: string,
termination?: string,
result?: GameResult,

// Moves
variant?: GameVariant;
initialPosition?: string;
mainVariation?: VariationPOJO;
variant?: GameVariant,
initialPosition?: string,
mainVariation?: VariationPOJO,
};


/**
* Represent a {@link AbstractNode} in a {@link GamePOJO}.
*/
export type AbstractNodePOJO = {
comment?: string;
isLongComment?: boolean;
nags?: number[];
tags?: Record<string, string>;
comment?: string,
isLongComment?: boolean,
nags?: number[],
tags?: Record<string, string>,
};


/**
* Represent a {@link Node} in a {@link GamePOJO}.
*/
export type NodePOJO = string | AbstractNodePOJO & {
notation: string;
variations?: VariationPOJO[];
notation: string,
variations?: VariationPOJO[],
};


/**
* Represent a {@link Variation} in a {@link GamePOJO}.
*/
export type VariationPOJO = NodePOJO[] | AbstractNodePOJO & {
nodes: NodePOJO[];
isLongVariation?: boolean;
nodes: NodePOJO[],
isLongVariation?: boolean,
};
22 changes: 12 additions & 10 deletions src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,17 +201,18 @@ export function variantWithCanonicalStartPosition(variant: GameVariant): boolean

const NAG_SYMBOLS = new Map<number, string>();

NAG_SYMBOLS.set( 1, '!', ); // good move
NAG_SYMBOLS.set( 2, '?', ); // bad move
NAG_SYMBOLS.set( 3, '!!', ); // very good move
NAG_SYMBOLS.set( 4, '??', ); // very bad move
NAG_SYMBOLS.set( 5, '!?', ); // interesting move
NAG_SYMBOLS.set( 6, '?!', ); // questionable move
/* eslint-disable @stylistic/no-multi-spaces, @stylistic/space-in-parens */
NAG_SYMBOLS.set( 1, '!' ); // good move
NAG_SYMBOLS.set( 2, '?' ); // bad move
NAG_SYMBOLS.set( 3, '!!' ); // very good move
NAG_SYMBOLS.set( 4, '??' ); // very bad move
NAG_SYMBOLS.set( 5, '!?' ); // interesting move
NAG_SYMBOLS.set( 6, '?!' ); // questionable move
NAG_SYMBOLS.set( 7, '\u25a1' ); // Only move
NAG_SYMBOLS.set( 8, '\u25a1' ); // Only move (ChessBase)
NAG_SYMBOLS.set( 9, '\u2612' ); // Worst move (Chess.com)
NAG_SYMBOLS.set( 10, '=', ); // equal position
NAG_SYMBOLS.set( 11, '=', ); // equal position (ChessBase)
NAG_SYMBOLS.set( 10, '=' ); // equal position
NAG_SYMBOLS.set( 11, '=' ); // equal position (ChessBase)
NAG_SYMBOLS.set( 13, '\u221e' ); // unclear position
NAG_SYMBOLS.set( 14, '\u2a72' ); // White has a slight advantage
NAG_SYMBOLS.set( 15, '\u2a71' ); // Black has a slight advantage
Expand All @@ -232,8 +233,9 @@ NAG_SYMBOLS.set(140, '\u2206' ); // With idea...
NAG_SYMBOLS.set(141, '\u2207' ); // Aimed against...
NAG_SYMBOLS.set(142, '\u2313' ); // Better is...
NAG_SYMBOLS.set(143, '\u2264' ); // Worse is...
NAG_SYMBOLS.set(145, 'RR', ); // Editorial comment
NAG_SYMBOLS.set(146, 'N', ); // Novelty
NAG_SYMBOLS.set(145, 'RR' ); // Editorial comment
NAG_SYMBOLS.set(146, 'N' ); // Novelty
/* eslint-enable */


/**
Expand Down
2 changes: 1 addition & 1 deletion src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/
export namespace i18n {

/* eslint-disable prefer-const */
/* eslint-disable prefer-const, @stylistic/indent, @stylistic/no-multi-spaces */
// WARNING: all those constants must be declared with "let" to allow them to be re-defined if necessary by consumer codes.

// FEN parsing error messages
Expand Down
15 changes: 4 additions & 11 deletions src/position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export class Position {
private _impl: PositionImpl;



// -------------------------------------------------------------------------
// Constructor & reset/clear
// -------------------------------------------------------------------------
Expand Down Expand Up @@ -267,7 +266,6 @@ export class Position {
}



// -------------------------------------------------------------------------
// FEN & ASCII conversion
// -------------------------------------------------------------------------
Expand Down Expand Up @@ -367,7 +365,6 @@ export class Position {
}



// -------------------------------------------------------------------------
// Accessors
// -------------------------------------------------------------------------
Expand Down Expand Up @@ -579,7 +576,6 @@ export class Position {
}



// -------------------------------------------------------------------------
// Legality
// -------------------------------------------------------------------------
Expand Down Expand Up @@ -621,7 +617,6 @@ export class Position {
}



// -------------------------------------------------------------------------
// Move generation
// -------------------------------------------------------------------------
Expand Down Expand Up @@ -841,7 +836,6 @@ export class Position {
}



// -------------------------------------------------------------------------
// Algebraic notation
// -------------------------------------------------------------------------
Expand Down Expand Up @@ -914,7 +908,6 @@ export class Position {
}



// -------------------------------------------------------------------------
// UCI
// -------------------------------------------------------------------------
Expand Down Expand Up @@ -971,17 +964,17 @@ export class Position {
* @see {@link Position.isMoveLegal}
*/
export type RegularMoveFactory = {
status: 'regular';
(): MoveDescriptor;
status: 'regular',
(): MoveDescriptor,
};


/**
* @see {@link Position.isMoveLegal}
*/
export type PromotionMoveFactory = {
status: 'promotion';
(promotion: Piece): MoveDescriptor;
status: 'promotion',
(promotion: Piece): MoveDescriptor,
};


Expand Down
4 changes: 2 additions & 2 deletions src/private_game/node_variation_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ function getTagKeys(data: AbstractNodeData) {
*/
function filterTags(data: AbstractNodeData, filter: (tagKey: string, tagValue: string) => boolean) {
const result = new Map<string, string>();
for (const [tagKey, tagValue] of data.tags.entries()) {
for (const [ tagKey, tagValue ] of data.tags.entries()) {
if (filter(tagKey, tagValue)) {
result.set(tagKey, tagValue);
}
Expand All @@ -668,7 +668,7 @@ function filterTags(data: AbstractNodeData, filter: (tagKey: string, tagValue: s
*/
function getTagRecords(data: AbstractNodeData) {
const result: Record<string, string> = {};
for (const [tagKey, tagValue] of data.tags.entries()) {
for (const [ tagKey, tagValue ] of data.tags.entries()) {
result[tagKey] = tagValue;
}
return result;
Expand Down
14 changes: 7 additions & 7 deletions src/private_pgn/pgn_read_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ function parseVariant(value: string): GameVariant | undefined {


interface InitialPositionFactory {
fen?: string;
fenTokenCharacterIndex?: number;
fenTokenLineIndex?: number;
variant?: GameVariant;
variantTokenCharacterIndex?: number;
variantTokenLineIndex?: number;
fen?: string,
fenTokenCharacterIndex?: number,
fenTokenLineIndex?: number,
variant?: GameVariant,
variantTokenCharacterIndex?: number,
variantTokenLineIndex?: number,
}


Expand Down Expand Up @@ -202,7 +202,7 @@ function doParseGame(stream: TokenStream) {
const game = new Game(); // the result
let endOfGameEncountered = false;
let atLeastOneTokenFound = false;
let node: Node | Variation | null = null; // current node (or variation) to which the next move should be appended
let node: Node | Variation | null = null; // current node (or variation) to which the next move should be appended
const nodeStack: (Node | Variation)[] = []; // when starting a variation, its parent node (btw., always a "true" node, not a variation) is stacked here
const initialPositionFactory: InitialPositionFactory = {};

Expand Down
4 changes: 2 additions & 2 deletions src/private_pgn/pgn_write_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function writeAnnotations(node: AbstractNode, skipLineAfterCommentIfLong: boolea

// Prepare tags
const tags = node.tags();
const tagValues: Map<string, string> = new Map();
const tagValues = new Map<string, string>();
let nonEmptyTagFound = false;
for (const tagKey of tags) {
const tagValue = trimAndCollapseSpaces(node.tag(tagKey)!.replace(/[[\]]/g, '')); // Square-brackets are erased in tag values in PGN.
Expand Down Expand Up @@ -211,7 +211,7 @@ export interface PGNWriteOptions {
/**
* If `true`, a PGN tag `[PlyCount "..."]` corresponding to the number of half-moves is added to each game in the generated PGN string. `false` by default.
*/
withPlyCount?: boolean;
withPlyCount?: boolean,
}


Expand Down
Loading

0 comments on commit c0424c9

Please sign in to comment.