Skip to content

Commit

Permalink
add default separator param to ascii function
Browse files Browse the repository at this point in the history
  • Loading branch information
kwkr committed Sep 25, 2023
1 parent 6ff1821 commit 8780ab1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
22 changes: 22 additions & 0 deletions __tests__/ascii.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,26 @@ describe('ASCII Board', () => {

expect(chess.ascii()).toBe(output.join('\n'))
})

it('Draws an ASCII board with a custom separator', () => {
const output = [
' +------------------------+',
' 8 | r . . . . r k . |',
' 7 | . . . . n q p p |',
' 6 | . p . p . . . . |',
' 5 | . . p P p p . . |',
' 4 | b P P . P . . . |',
' 3 | R . B . N Q . . |',
' 2 | P . . . . P P P |',
' 1 | . R . . . . K . |',
' +------------------------+',
' a b c d e f g h',
]

const chess = new Chess(
'r4rk1/4nqpp/1p1p4/2pPpp2/bPP1P3/R1B1NQ2/P4PPP/1R4K1 w - - 0 28'
)

expect(chess.ascii("\r\n")).toBe(output.join('\r\n'))
})
})
8 changes: 4 additions & 4 deletions src/chess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2106,8 +2106,8 @@ export class Chess {
return null
}

ascii() {
let s = ' +------------------------+\n'
ascii(separator = '\n') {
let s = ` +------------------------+${separator}`
for (let i = Ox88.a8; i <= Ox88.h1; i++) {
// display the rank
if (file(i) === 0) {
Expand All @@ -2125,11 +2125,11 @@ export class Chess {
}

if ((i + 1) & 0x88) {
s += '|\n'
s += `|${separator}`
i += 8
}
}
s += ' +------------------------+\n'
s += ` +------------------------+${separator}`
s += ' a b c d e f g h'

return s
Expand Down

0 comments on commit 8780ab1

Please sign in to comment.