Skip to content

Commit

Permalink
Merge 204cfc8 into 3182781
Browse files Browse the repository at this point in the history
  • Loading branch information
brozeph committed Sep 12, 2014
2 parents 3182781 + 204cfc8 commit 4d5c792
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 15 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
@@ -1,4 +1,3 @@
language: node_js
node_js:
- 0.8
- 0.10
- 0.10
7 changes: 6 additions & 1 deletion HISTORY.md
@@ -1,3 +1,8 @@
0.2.2 / 2014-09-12
==================

* introducing fix for phantom black Pawn spawn (issue #8)

0.2.1 / 2014-03-11
==================

Expand Down Expand Up @@ -44,4 +49,4 @@
0.1.2 / 2011-06-12
==================

* initial release
* initial release
7 changes: 6 additions & 1 deletion lib/board.js
Expand Up @@ -158,6 +158,11 @@ Board.prototype.move = function (src, dest, simulate) {
} else {
b.getSquare(m.postSquare.file,
m.prevSquare.rank).piece = m.capturedPiece;

// there is no piece on the post square in the event of
// an en-passant, clear anything that me be present as
// a result of the move (fix for issue #8)
m.postSquare.piece = null;
}

if (m.castle) {
Expand Down Expand Up @@ -274,4 +279,4 @@ module.exports = {

// enums
NeighborType : NeighborType
};
};
4 changes: 3 additions & 1 deletion lib/boardValidation.js
Expand Up @@ -132,6 +132,7 @@ BoardValidation.prototype.filterKingAttack = function (kingSquare, moves) {
squares = [];

for (n = 0; n < moves[i].squares.length; n++) {
// simulate move on the board
r = this.board.move(moves[i].src, moves[i].squares[n], true);

// check if king is attacked
Expand All @@ -141,6 +142,7 @@ BoardValidation.prototype.filterKingAttack = function (kingSquare, moves) {
isCheck = this.isSquareAttacked(moves[i].squares[n]);
}

// reverse the move
r.undo();

if (!isCheck) {
Expand Down Expand Up @@ -301,4 +303,4 @@ module.exports = {

return new BoardValidation(g);
}
};
};
6 changes: 4 additions & 2 deletions lib/pieceValidation.js
Expand Up @@ -303,7 +303,8 @@ PawnValidation.prototype.applySpecialValidation = function (opt) {
} else if (opt.origin.rank ===
(opt.piece.side === piece.SideType.White ? 5 : 4)) {
// get squares left & right of pawn
squares = [this.board.getNeighborSquare(opt.origin, board.NeighborType.Left),
squares = [
this.board.getNeighborSquare(opt.origin, board.NeighborType.Left),
this.board.getNeighborSquare(opt.origin, board.NeighborType.Right)];
i = 0;

Expand All @@ -315,6 +316,7 @@ PawnValidation.prototype.applySpecialValidation = function (opt) {
p.side !== opt.piece.side &&
p.moveCount === 1 &&
this.board.lastMovedPiece === p) {

opt.destSquares.push(
this.board.getNeighborSquare(
squares[i],
Expand Down Expand Up @@ -383,4 +385,4 @@ module.exports = {
return null;
}
}
};
};
2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "chess",
"description": "An algebraic notation driven chess engine that can validate board position and produce a list of viable moves (notated).",
"version": "0.2.1",
"version": "0.2.2",
"author": "Joshua Thomas (http://github.com/brozeph)",
"engine": "node >= 0.8.1",
"repository": {
Expand Down
29 changes: 22 additions & 7 deletions test/lib/algebraicGameClient.js
Expand Up @@ -166,7 +166,6 @@ describe('AlgebraicGameClient', function() {
assert.ok(m.move.castle);
});

/*
// test pawn promotion
// adding for issue #6
it('should properly show valid White Pawn promotions', function() {
Expand Down Expand Up @@ -195,20 +194,19 @@ describe('AlgebraicGameClient', function() {
gc.game.board.getSquare('a2').piece = null;
gc.game.board.getSquare('a1').piece = null;
gc.game.board.getSquare('a7').piece = null;
gc.game.board.getSquare('a2').piece = piece.createPawn(piece.SideType.White);
gc.game.board.getSquare('a2').piece = piece.createPawn(piece.SideType.Black);
gc.game.board.getSquare('a2').piece.moveCount = 1;

gc.getStatus(true);
gc.move('h4');
r = gc.getStatus();
r = gc.getStatus(true);

assert.isUndefined(r.notatedMoves['a1'], 'pawn should promote');
assert.isDefined(r.notatedMoves['a1R'], 'pawn promotion to rook');
assert.isDefined(r.notatedMoves['a1N'], 'pawn promotion to Knight');
assert.isDefined(r.notatedMoves['a1B'], 'pawn promotion to Bishop');
assert.isDefined(r.notatedMoves['a1Q'], 'pawn promotion to Queen');
});
//*/

// test pawn promotion
it('should properly recognize White Pawn promotion to Rook', function() {
Expand Down Expand Up @@ -450,7 +448,6 @@ describe('AlgebraicGameClient', function() {
it ('should properly detect checkmate', function () {
var gc = algebraicGameClient.create(),
m = null,
s = gc.game.board.getSquare('a6'),
status = null;

gc.move('e4');
Expand Down Expand Up @@ -558,5 +555,23 @@ describe('AlgebraicGameClient', function() {
status = gc.getStatus();
assert.strictEqual(status.notatedMoves['Kf7'], undefined);
});
//*/
});

// Issue #8 - Ensure no extraneous Black Pawn
it ('should not have a random Black Pawn appear on the board (bug fix test)', function () {
var gc = algebraicGameClient.create(),
m = null,
s = gc.game.board.getSquare('e6');

gc.move('d4');
gc.move('a6');


gc.move('d5');

assert.ok(s.piece === null, 'phantom piece appears before e5');

gc.move('e5');

assert.ok(s.piece === null, 'phantom piece appears after e5');
});
});

0 comments on commit 4d5c792

Please sign in to comment.