Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
Logging correction for pawn taking
Browse files Browse the repository at this point in the history
  • Loading branch information
Nixinova committed Feb 11, 2021
1 parent 2675406 commit 853ca8c
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions movePiece.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function hasClicked(cell) {
$endingCell.appendChild(createPiece(piece, colour, endingCell));

console.log('M ' + startingCell + ' -> ' + endingCell);
log(colour, originalPiece, endingCell, { taken: !!endingClasses[0], promoted: canPromote });
log(colour, originalPiece, startingCell, endingCell, { taken: endingClasses[0], promoted: canPromote });
selectedCell = null;

}
Expand All @@ -91,13 +91,21 @@ function hasClicked(cell) {
}
}

function log(colour, piece, endCell, { taken, promoted }) {
function log(colour, piece, startCell, endCell, { taken, promoted }) {
let box = document.getElementById('log');
let pieceID
switch (piece) {
case 'pawn': pieceID = ''; break;
case 'knight': pieceID = 'n'; break;
default: pieceID = piece[0];
}
box.innerHTML += `<span class="${colour}">` + pieceID.toUpperCase() + (taken ? 'x' : '') + endCell.toLowerCase() + (promoted ? '=Q' : '') + '</span>';
box.innerHTML += (
`<span class="${colour}">`
+ pieceID.toUpperCase()
+ (taken && piece === 'pawn' ? startCell[0].toLowerCase() : '')
+ (taken ? 'x' : '')
+ endCell.toLowerCase()
+ (promoted ? '=Q' : '')
+ '</span>'
);
}

0 comments on commit 853ca8c

Please sign in to comment.