Skip to content

Commit

Permalink
clean up some old tests and validate existing metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
EllAchE committed Nov 4, 2023
1 parent 0ea6fb2 commit 8528860
Show file tree
Hide file tree
Showing 10 changed files with 339 additions and 5,067 deletions.
1,923 changes: 0 additions & 1,923 deletions badhistory.json

This file was deleted.

588 changes: 294 additions & 294 deletions historiesShort.json

Large diffs are not rendered by default.

2,616 changes: 0 additions & 2,616 deletions historiestst.json

This file was deleted.

199 changes: 0 additions & 199 deletions history.json

This file was deleted.

40 changes: 21 additions & 19 deletions src/metrics/captures.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Piece, PrettyMove, UAPSymbol } from '../../cjsmin/src/chess';
import { BoardMap, UAPMap } from '../types';
import { UAPMap } from '../types';
import { createUAPMap } from '../utils';
import { Metric } from './metric';

Expand Down Expand Up @@ -129,13 +129,13 @@ export class KDRatioMetric implements Metric {
processGame(game: { move: PrettyMove; board: Piece[] }[]) {
// @ts-ignore initialize with no capture
let previousMove: PrettyMove = {};
for (const { move } of game) {
for (const { move, board } of game) {
if (move.capture) {
this.KDAssistsMap[move.uas].kills++;
this.KDAssistsMap[move.capture.uas].deaths++;

if (previousMove.capture && move.to === previousMove.to) {
this.KDAssistsMap[move.to][move.uas].revengeKills++;
this.KDAssistsMap[move.uas].revengeKills++;
}
previousMove = move;
}
Expand Down Expand Up @@ -203,6 +203,8 @@ export class MateAndAssistMetric implements Metric {

const lastMove = game[game.length - 1].move;

console.log(this.mateAndAssistMap);
console.log(lastMove.uas);
// increment the mate count of the mating piece
this.mateAndAssistMap[lastMove.uas].mates++;
// increment the mated (death) count of the mated king
Expand Down Expand Up @@ -235,19 +237,19 @@ export class MateAndAssistMetric implements Metric {
}

// Not sure what's different from KD Ratio here except for revenge kills, so moving that and will deprecated
export function trackCaptures(boardMap: BoardMap, moves: PrettyMove[]) {
let lastMove: PrettyMove;
let i = 0;
for (const move of moves) {
if (move.capture) {
boardMap[move.to][move.uas].captures++;
boardMap[move.to][move.capture.uas].captured++;
// revenge kills
if (lastMove.capture && move.to === lastMove.to) {
boardMap[move.to][move.uas].revengeKills++;
}
}
lastMove = move;
i++;
}
}
// export function trackCaptures(boardMap: BoardMap, moves: PrettyMove[]) {
// let lastMove: PrettyMove;
// let i = 0;
// for (const move of moves) {
// if (move.capture) {
// boardMap[move.to][move.uas].captures++;
// boardMap[move.to][move.capture.uas].captured++;
// // revenge kills
// if (lastMove.capture && move.to === lastMove.to) {
// boardMap[move.to][move.uas].revengeKills++;
// }
// }
// lastMove = move;
// i++;
// }
// }
2 changes: 1 addition & 1 deletion tests/enPassant.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Chess } from '../cjsmin/src/chess';

const pgnEP = `1. d2d4 f7f5 2. b2b3 e7e6 3. c1b2 d7d5 4. g1f3 f8d6 5. e2e3 g8f6 6. b1d2 e8g8 7. c2c4 c7c6 8. f1d3 b8d7 9. e1g1 f6e4 10. a1c1 g7g5 11. h2h3 d8e8 12. d3e4 d5e4 13. f3g5 e8g6 14. h3h4 h7h6 15. g5h3 d7f6 16. f2f4 e4f3 17. d2f3 f6g4 18. d1e2 d6g3 19. h3f4 g6g7 20. d4d5 g7f7 21. d5e6 c8e6 22. f3e5 g4e5 23. b2e5 g8h7 24. h4h5 f8g8 25. e2f3 g3f4 26. e5f4 g8g4 27. g2g3 a8g8 28. c1c2 b7b5 29. c4b5 e6d5 30. f3d1 f7h5 31. c2h2 g4g3+ 32. f4g3 g8g3+ 33. g1f2 h5h2+ 34. f2e1 g3g2 35. d1d3 d5e4 36. d3d7+ h7g6 37. b5c6 g2e2+ 38. e1d1 e2a2 0-1`;

xdescribe('Game history for en passant move should show valid captured piece', () => {
describe('Game history for en passant move should show valid captured piece', () => {
const chess = new Chess();
it('should return the correct captured piece', () => {
const game = [
Expand Down
4 changes: 1 addition & 3 deletions tests/historyGenerator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Chess } from '../cjsmin/src/chess';
/**
* @beta - this test was generated partially with chatGPT so might be an invalid PGN
*/
xdescribe('Chess', () => {
describe('Chess', () => {
describe('historyGenerator', () => {
it('should generate the correct move history for a given PGN string', () => {
const chess = new Chess();
Expand All @@ -14,8 +14,6 @@ xdescribe('Chess', () => {
const expectedMoves = moveString.split(' ').filter((_, i) => i % 3 !== 0);
expectedMoves.pop(); // remove the result from the end of the array
for (const { move, board } of gen) {
// console.log(board);
console.log(move);
// validate that the piece that was moved is of the same type as the destination square
expect(move.piece).toEqual(board[move.toIndex].type);
expect(move.uas).toEqual(board[move.toIndex].uas);
Expand Down
Loading

0 comments on commit 8528860

Please sign in to comment.