From 7041543bd00f8852a6210f1cda295af8efaf4db4 Mon Sep 17 00:00:00 2001 From: Sage Vaillancourt Date: Mon, 28 Dec 2020 18:01:05 -0500 Subject: [PATCH] Correct pawn movement --- src/index.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/index.js b/src/index.js index f3bb390..38c16c3 100644 --- a/src/index.js +++ b/src/index.js @@ -188,16 +188,17 @@ class Board extends React.Component { let shift = pieceIsBlack ? -1 : 1; let startLine = pieceIsBlack ? 6 : 1; - if (y === startLine) { - return [ - [x, y + shift], - [x, y + (shift * 2)], - ]; - } else { - return [ - [x, y + shift], - ]; + if (this.squareAt(x, y + shift) == null) { + moves.push([x, y + shift]); + if (y === startLine && this.squareAt(x, y + (shift * 2)) == null) { + moves.push([x, y + (shift * 2)]); + } } + [x + 1, x - 1].forEach((x) => { + if (this.isEnemyOf(piece, x, y + shift)) { + moves.push([x, y + shift]); + } + }); } else if (isRook(piece)) { // Down for (i = y + 1; i < 8; i++) {