Skip to content

Commit

Permalink
Merge pull request #19 from chesslablab/issue/18-Implement-the-Figuri…
Browse files Browse the repository at this point in the history
…ne-Algebraic-Notation

Implemented Movetext.toFigurine()
  • Loading branch information
programarivm authored Apr 12, 2024
2 parents 8aa1c57 + 428f273 commit 8359e87
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions __tests__/common/Movetext.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { Movetext } from '../../src/common/Movetext';

describe('toFigurine()', () => {
it('is 1.e4 e5 2.Nf3 Nc6', () => {
const string = '1.e4 e5 2.Nf3 Nc6';
const expected = '1.e4 e5 2.♘f3 ♘c6';
expect(Movetext.toFigurine(string)).toEqual(expected);
});
});

describe('toRows()', () => {
it('is 1.e4', () => {
const string = '1.e4';
Expand Down
10 changes: 10 additions & 0 deletions src/common/Movetext.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import { Nag } from './Nag.js';

export class Movetext {
static toFigurine = (str) => {
str = str.replaceAll('R', '♖');
str = str.replaceAll('N', '♘');
str = str.replaceAll('B', '♗');
str = str.replaceAll('Q', '♕');
str = str.replaceAll('K', '♔');

return str;
}

static description = (str) => {
if (str.startsWith('{')) {
let match = str.match(/{([^}]+)}/g)[0];
Expand Down

0 comments on commit 8359e87

Please sign in to comment.