Skip to content

Commit

Permalink
move cjsmin into src repo
Browse files Browse the repository at this point in the history
  • Loading branch information
EllAchE committed Apr 1, 2024
1 parent c34a945 commit 5b9dfa4
Show file tree
Hide file tree
Showing 30 changed files with 178 additions and 153 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"start": "tsc --build && node dist/src/index.js",
"test": "tsc --build && jest ./dist",
"scratch": "tsc --build && node dist/src/scratch.js",
"run-zst-decompressor": "tsc --build && node dist/src/zst_decompressor.js"
"run-zst-decompressor": "tsc --build && node dist/src/zst_decompressor.js",
"rq": "tsc --build && node dist/src/queue.js"
}
}
2 changes: 1 addition & 1 deletion src/aggregate_analysis.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { readFileSync } from 'fs';
import { UASymbol } from '../cjsmin/src/chess';
import { UASymbol } from './cjsmin/src/chess';

/**
*
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * as cjsmin from '../cjsmin';
export * as cjsmin from './cjsmin';
export * from './constants';
export * as metrics from './metrics';
export * from './types';
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as fs from 'fs';
import * as path from 'path';
import * as lockfile from 'proper-lockfile';
import { Chess } from '../cjsmin/src/chess';
import { Chess } from './cjsmin/src/chess';
import { gameChunks } from './fileReader';
import {
KDRatioMetric,
Expand Down
74 changes: 34 additions & 40 deletions src/metrics/captures.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import { max } from 'd3';
import {
ALL_SQUARES,
Piece,
PrettyMove,
UASymbol,
} from '../../cjsmin/src/chess';
import { ALL_SQUARES, Piece, PrettyMove, UASymbol } from '../cjsmin/src/chess';
import { BoardAndPieceMap, UAPMap } from '../types';
import { createBoardAndPieceMap, createBoardMap, createUAPMap } from '../utils';
import { Metric } from './metric';
Expand All @@ -15,7 +9,7 @@ export class KillStreakMetric implements Metric {
killStreaks: number;
};
};
maxKillStreakGame: string[]
maxKillStreakGame: string[];
maxKillStreak: number;
maxKillStreakPiece: UASymbol[];

Expand All @@ -39,14 +33,14 @@ export class KillStreakMetric implements Metric {
maxKillStreak: this.maxKillStreak,
maxKillStreakPiece: this.maxKillStreakPiece,
maxKillStreakGame: this.maxKillStreakGame,
}
};
}

logResults(): void {
console.log('Kill streak map', this.killStreakMap);
console.log(`Max Kill Streak: ${this.maxKillStreak}`);
console.log(`Max Kill Streak Piece: ${this.maxKillStreakPiece}`);
console.log(`Game(s) with max kill streak(s): ${this.maxKillStreakGame}`)
console.log(`Game(s) with max kill streak(s): ${this.maxKillStreakGame}`);
}

getMaxKillStreak(
Expand Down Expand Up @@ -92,23 +86,17 @@ export class KillStreakMetric implements Metric {
streakLength
);
this.checkMaxes(streakPiece, gameLink, streakLength);

}
}

checkMaxes(
streakPiece: UASymbol,
gameLink: string,
streakLength: number,
) {

checkMaxes(streakPiece: UASymbol, gameLink: string, streakLength: number) {
// update maxes
if (streakLength > this.maxKillStreak) {
this.maxKillStreak = streakLength;
this.maxKillStreakPiece = [streakPiece as UASymbol];
this.maxKillStreakGame = [gameLink];
}
else if (streakLength === this.maxKillStreak) {
this.maxKillStreakPiece.push(streakPiece as UASymbol)
} else if (streakLength === this.maxKillStreak) {
this.maxKillStreakPiece.push(streakPiece as UASymbol);
this.maxKillStreakGame.push(gameLink);
}
}
Expand All @@ -117,9 +105,10 @@ export class KillStreakMetric implements Metric {
game: { move: PrettyMove; board: Piece[] }[],
metadata?: string[]
) {
const gameLink = metadata.find((item) => item.startsWith('[Site "'))
?.replace('[Site "', '')
?.replace('"]', '');
const gameLink = metadata
.find((item) => item.startsWith('[Site "'))
?.replace('[Site "', '')
?.replace('"]', '');

this.getMaxKillStreak(game, 0, gameLink);
this.getMaxKillStreak(game, 1, gameLink);
Expand Down Expand Up @@ -155,18 +144,24 @@ export class KDRatioMetric implements Metric {
console.log(
`Piece with the highest KD ratio: ${this.pieceWithHighestKDRatio}`
);
console.log('Kills, deaths, and revenge kills for each unambiguous piece:'),
console.log(
'Kills, deaths, and revenge kills for each unambiguous piece:'
),
console.table(this.KDMap);
console.log(
'Kill Death Ratios for each unambiguous piece: ' +
JSON.stringify(this.kdRatios, null, 2)
);
console.log('\n')
console.log("KDRs TAKING INTO ACCOUNT PIECE VALUES (Pawn 1 point, Knight 3 points, Bishop 3 points, Rook 5 points, Queen 9 points, King 4 points): ")
console.log('\n');
console.log(
'KDRs TAKING INTO ACCOUNT PIECE VALUES (Pawn 1 point, Knight 3 points, Bishop 3 points, Rook 5 points, Queen 9 points, King 4 points): '
);
console.log(
`Piece with the highest KD ratio (taking into account piece values): ${this.pieceWithHighestKDRatioValues}`
);
console.log('Kills, Deaths, and for each unambiguous piece (taking into account piece values):'),
console.log(
'Kills, Deaths, and for each unambiguous piece (taking into account piece values):'
),
console.table(this.KDValuesMap);
console.log(
'Kill Death Ratios for each unambiguous piece (taking into account piece values): ' +
Expand Down Expand Up @@ -228,7 +223,6 @@ export class KDRatioMetric implements Metric {
this.kdRatiosValues = KDRatiosValues;
this.pieceWithHighestKDRatioValues = pieceWithHighestKDRatioValues;


return {
maxKDRatio,
pieceWithHighestKDRatio,
Expand Down Expand Up @@ -280,7 +274,7 @@ export class KDRatioMetric implements Metric {
this.KDValuesMap[move.uas].valueKills += 5;
} else if (move.capture.type === 'q') {
this.KDValuesMap[move.uas].valueKills += 9;
}
}

// identify a revenge kill if the previous move and the current move contained a capture, and the square moved to in the previous move is the same as the square moved to in this move
if (previousMove.capture && move.to === previousMove.to) {
Expand Down Expand Up @@ -347,21 +341,18 @@ export class MateAndAssistMetric implements Metric {
aggregate() {
return {
mateAndAssistMap: this.mateAndAssistMap,
matedCounts: this.matedCounts
matedCounts: this.matedCounts,
};
}

logResults() {

}
logResults() {}

// One edge case currently unaccounted for is when pieces "share" a mate, or check. This can be at most 2 due to discovery
// checks (currently we disregard this by just saying the last piece to move is the "mating piece")
processGame(
game: { move: PrettyMove; board: Piece[] }[],
metadata?: string[]
) {

) {
// Take no action if the game didn't end in checkmate
if (!game[game.length - 1].move.originalString.includes('#')) {
return;
Expand All @@ -372,11 +363,14 @@ export class MateAndAssistMetric implements Metric {
// increment the mate count of the mating piece
this.mateAndAssistMap[lastMove.uas].mates++;
if (lastMove.uas === 'k' || lastMove.uas === 'K') {
console.log(`code identified a king as having a mate (caused by discovered check). move: ${lastMove.originalString}`)
const gameLink = metadata.find((item) => item.startsWith('[Site "'))
?.replace('[Site "', '')
?.replace('"]', '');
console.log(`game: ${gameLink}`)
console.log(
`code identified a king as having a mate (caused by discovered check). move: ${lastMove.originalString}`
);
const gameLink = metadata
.find((item) => item.startsWith('[Site "'))
?.replace('[Site "', '')
?.replace('"]', '');
console.log(`game: ${gameLink}`);
}

// increment the mated (death) count of the mated king
Expand Down
28 changes: 13 additions & 15 deletions src/metrics/distances.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Piece, PrettyMove, UASymbol } from '../../cjsmin/src/chess';
import { Piece, PrettyMove, UASymbol } from '../cjsmin/src/chess';
import { UAPMap } from '../types';
import { createUAPMap } from '../utils';
import { Metric } from './metric';

export class MoveDistanceMetric implements Metric {
distanceMap: UAPMap<{
distanceMap: UAPMap<{
distance: number;
}>;
avgDistanceMap: UAPMap<{
avgDistanceMap: UAPMap<{
avgDistance: number;
}>;
pieceWithHighestAvg: UASymbol;
Expand All @@ -24,7 +24,7 @@ export class MoveDistanceMetric implements Metric {
gameCollectiveDistance: {
distance: number;
linkArray: string[];
}
};
gamesProcessed: number;

constructor() {
Expand Down Expand Up @@ -84,11 +84,10 @@ export class MoveDistanceMetric implements Metric {
gameMaxCollectiveDistance: this.gameCollectiveDistance,
totalDistancesByPiece: this.distanceMap,
avgDistancesByPiece: this.avgDistanceMap,
}
};
}

logResults(): void {

// distance facts
console.log('DISTANCE FACTS:');
console.log(
Expand All @@ -99,7 +98,8 @@ export class MoveDistanceMetric implements Metric {
);

console.log(`Piece that moved the furthest: ${this.pieceMaxes.uasArray}`);
console.log(`Game in which that/those piece(s) (${this.pieceMaxes.uasArray}) moved the furthest: ${this.pieceMaxes.linkArray}`
console.log(
`Game in which that/those piece(s) (${this.pieceMaxes.uasArray}) moved the furthest: ${this.pieceMaxes.linkArray}`
);
console.log(
`Distance that/those piece(s) moved in the game: ${this.pieceMaxes.distance}`
Expand Down Expand Up @@ -155,9 +155,10 @@ export class MoveDistanceMetric implements Metric {
}
}

const gameLink = metadata.find((item) => item.startsWith('[Site "'))
?.replace('[Site "', '')
?.replace('"]', '');
const gameLink = metadata
.find((item) => item.startsWith('[Site "'))
?.replace('[Site "', '')
?.replace('"]', '');
let singleGameCollective = 0;

// add the single game aggregates to the state object
Expand All @@ -177,13 +178,10 @@ export class MoveDistanceMetric implements Metric {
}

// find the game in which the most collective distance was moved
if (
singleGameCollective > this.gameCollectiveDistance.distance
) {
if (singleGameCollective > this.gameCollectiveDistance.distance) {
this.gameCollectiveDistance.distance = singleGameCollective;
this.gameCollectiveDistance.linkArray = [gameLink];
} else if (singleGameCollective === this.gameCollectiveDistance.distance
) {
} else if (singleGameCollective === this.gameCollectiveDistance.distance) {
this.gameCollectiveDistance.linkArray.push(gameLink);
}

Expand Down
2 changes: 1 addition & 1 deletion src/metrics/metric.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Piece, PrettyMove } from '../../cjsmin/src/chess';
import { Piece, PrettyMove } from '../cjsmin/src/chess';

export interface Metric {
processGame(
Expand Down
2 changes: 1 addition & 1 deletion src/metrics/misc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Chess, Piece, PrettyMove } from '../../cjsmin/src/chess';
import { Chess, Piece, PrettyMove } from '../cjsmin/src/chess';
import { Metric } from './metric';

// calculates how many games in the dataset
Expand Down
Loading

0 comments on commit 5b9dfa4

Please sign in to comment.