Skip to content

Commit

Permalink
adding additional Knight check support
Browse files Browse the repository at this point in the history
  • Loading branch information
brozeph committed Jan 22, 2014
1 parent 8250cc0 commit c1b40da
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 7 deletions.
5 changes: 5 additions & 0 deletions HISTORY.md
@@ -1,3 +1,8 @@
0.1.8 / 2014-01-22
==================

* additional verification of Knight check related to issue #4

0.1.7 / 2014-01-21
==================

Expand Down
4 changes: 4 additions & 0 deletions lib/board.js
Expand Up @@ -20,6 +20,10 @@ var NeighborType = {
KnightAboveRight : { offset : 17 },
KnightBelowLeft : { offset : -17 },
KnightBelowRight : { offset : -15 },
KnightLeftAbove : { offset : 6 },
KnightLeftBelow : { offset : -10 },
KnightRightAbove : { offset : 10 },
KnightRightBelow : { offset : -6 },
Left : { offset : -1 },
Right : { offset : 1 }
};
Expand Down
6 changes: 5 additions & 1 deletion lib/boardValidation.js
Expand Up @@ -234,9 +234,13 @@ BoardValidation.prototype.isSquareAttacked = function (sq) {

// fix for issue #4
isAttackedByKnight(this.board, board.NeighborType.KnightAboveRight) ||
isAttackedByKnight(this.board, board.NeighborType.KnightRightAbove) ||
isAttackedByKnight(this.board, board.NeighborType.KnightBelowRight) ||
isAttackedByKnight(this.board, board.NeighborType.KnightRightBelow) ||
isAttackedByKnight(this.board, board.NeighborType.KnightBelowLeft) ||
isAttackedByKnight(this.board, board.NeighborType.KnightAboveLeft);
isAttackedByKnight(this.board, board.NeighborType.KnightLeftBelow) ||
isAttackedByKnight(this.board, board.NeighborType.KnightAboveLeft) ||
isAttackedByKnight(this.board, board.NeighborType.KnightLeftAbove);
};

// begin evaluation of the valid moves for an entire board
Expand Down
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.1.7",
"version" : "0.1.8",
"author" : "Joshua Thomas <joshua.thomas@gmail.com>",
"engine" : "node >= 0.8.1",
"repository" : {
Expand Down
22 changes: 17 additions & 5 deletions test/lib/gameValidation.js
Expand Up @@ -5,7 +5,6 @@ var
gameValidation = requireWithCoverage('gameValidation');

describe('GameValidation', function() {
/*
// validate check
it('should properly indicate check', function() {
var g = game.create(),
Expand All @@ -25,8 +24,22 @@ describe('GameValidation', function() {
assert.strictEqual(result.isStalemate, false);
});
});
*/
it('should properly indicate check due to Knight', function () {

// validate Knight check (part 1)
it('should properly indicate check due to Knight (part 1)', function () {
var g = game.create(),
b = g.board,
v = gameValidation.create(g);

b.move(b.getSquare('b1'), b.getSquare('c7'));

v.start(function (err, result) {
assert.strictEqual(result.isCheck, true);
});
});

// validate Knight check (part 2)
it('should properly indicate check due to Knight (part 2)', function () {
var g = game.create(),
b = g.board,
v = gameValidation.create(g);
Expand All @@ -41,7 +54,7 @@ describe('GameValidation', function() {
assert.strictEqual(result.isCheck, true);
});
});
/*

// validate checkmate
it('should properly indicate checkmate', function() {
var g = game.create(),
Expand Down Expand Up @@ -231,5 +244,4 @@ describe('GameValidation', function() {
assert.strictEqual(result.isStalemate, false);
});
});
*/
});

0 comments on commit c1b40da

Please sign in to comment.