From ea505681b52b5b42bdf3bd46bb8613e34503af75 Mon Sep 17 00:00:00 2001 From: Joshua Thomas Date: Thu, 26 Mar 2015 08:18:25 -0700 Subject: [PATCH 01/11] adding node v0.12 to build verification --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index bc9dff3..b4b603f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ language: node_js node_js: - 0.10 + - 0.12 From 4545a0f89264c5bc68b6a59d398dda7bc97e5106 Mon Sep 17 00:00:00 2001 From: Joshua Thomas Date: Thu, 26 Mar 2015 08:18:47 -0700 Subject: [PATCH 02/11] beginning to define what is in v0.2.6 --- HISTORY.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/HISTORY.md b/HISTORY.md index ae8fefd..32fb536 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,9 @@ +0.2.6 / 2015-03-26 +================== + + * adding Node v0.12 build target for Travis-CI + * fixing issue where Pawn double-square move was incorrectly restricted in some scenarios where capture would have been evaded + 0.2.5 / 2014-10-30 ================== From 504ce0416a0513721a71000b55f9e6daef31e212 Mon Sep 17 00:00:00 2001 From: Joshua Thomas Date: Thu, 26 Mar 2015 08:19:06 -0700 Subject: [PATCH 03/11] tightening up jshint and fixing issues found --- .jshintrc | 10 +++++----- lib/algebraicGameClient.js | 1 - lib/board.js | 2 +- lib/boardValidation.js | 1 - lib/game.js | 3 +-- lib/gameValidation.js | 3 +-- lib/pieceValidation.js | 6 ++++-- lib/simpleGameClient.js | 3 +-- 8 files changed, 13 insertions(+), 16 deletions(-) diff --git a/.jshintrc b/.jshintrc index fe77ca4..504c55b 100644 --- a/.jshintrc +++ b/.jshintrc @@ -1,11 +1,11 @@ { "bitwise" : true, - "camelcase" : false, + "camelcase" : true, "curly" : true, "eqeqeq" : true, "forin" : true, "immed" : true, - "indent" : false, + "indent" : true, "latedef" : true, "maxdepth" : 5, "maxparams" : 5, @@ -14,8 +14,8 @@ "noempty" : true, "node" : true, "nonew" : true, - "strict" : false, + "strict" : true, "trailing" : true, "undef" : true, - "unused" : false -} \ No newline at end of file + "unused" : true +} diff --git a/lib/algebraicGameClient.js b/lib/algebraicGameClient.js index 8515384..0a171c5 100644 --- a/lib/algebraicGameClient.js +++ b/lib/algebraicGameClient.js @@ -1,5 +1,4 @@ var piece = require('./piece.js'), - board = require('./board.js'), game = require('./game.js'), gameValidation = require('./gameValidation.js'); diff --git a/lib/board.js b/lib/board.js index 02d19ca..4146b4c 100644 --- a/lib/board.js +++ b/lib/board.js @@ -156,7 +156,7 @@ Board.prototype.move = function (src, dest, n) { }, p = src.piece, sq = null, - undo = function (b, m, s) { + undo = function (b, m) { return function () { m.prevSquare.piece = m.postSquare.piece; m.postSquare.piece = m.capturedPiece; diff --git a/lib/boardValidation.js b/lib/boardValidation.js index 0e72966..260c73f 100644 --- a/lib/boardValidation.js +++ b/lib/boardValidation.js @@ -50,7 +50,6 @@ BoardValidation.prototype.evaluateCastle = function (validMoves) { } } }, - isAttacked = false, r = null, rank = this.game.getCurrentSide() === piece.SideType.White ? 1 : 8, squares = { diff --git a/lib/game.js b/lib/game.js index 8c5a029..4aa8933 100644 --- a/lib/game.js +++ b/lib/game.js @@ -8,7 +8,6 @@ var crypto = require('crypto'), piece = require('./piece.js'), - Square = require('./square.js'), board = require('./board.js'); // types @@ -64,7 +63,7 @@ var addToHistory = function (g) { var denotePromotionInHistory = function (g) { 'use strict'; - return function (sq) { + return function () { var latest = g.moveHistory[g.moveHistory.length - 1]; if (latest) { diff --git a/lib/gameValidation.js b/lib/gameValidation.js index 8794d2b..2d28b63 100644 --- a/lib/gameValidation.js +++ b/lib/gameValidation.js @@ -6,7 +6,6 @@ */ var piece = require('./piece.js'), - board = require('./board.js'), boardValidation = require('./boardValidation.js'); // base ctor @@ -95,4 +94,4 @@ module.exports = { return new GameValidation(g); } -}; \ No newline at end of file +}; diff --git a/lib/pieceValidation.js b/lib/pieceValidation.js index 5ecbb9f..a96aa44 100644 --- a/lib/pieceValidation.js +++ b/lib/pieceValidation.js @@ -28,7 +28,7 @@ var PieceValidation = function (b) { }; // methods -PieceValidation.prototype.applySpecialValidation = function (opt) { +PieceValidation.prototype.applySpecialValidation = function () { 'use strict'; // do nothing... }; @@ -145,7 +145,7 @@ var KingValidation = function (b) { sys.inherits(KingValidation, PieceValidation); // methods -KingValidation.prototype.applySpecialValidation = function (opt) { +KingValidation.prototype.applySpecialValidation = function () { 'use strict'; // check for castle @@ -295,6 +295,8 @@ PawnValidation.prototype.applySpecialValidation = function (opt) { board.NeighborType.Below ); + // Source of issue #15 - Pawn should be able to double-square move to avoid + // a piece that is currently able to capture it if (!sq.piece) { opt.destSquares.push(sq); } diff --git a/lib/simpleGameClient.js b/lib/simpleGameClient.js index df83727..878977a 100644 --- a/lib/simpleGameClient.js +++ b/lib/simpleGameClient.js @@ -1,5 +1,4 @@ var piece = require('./piece.js'), - board = require('./board.js'), game = require('./game.js'), gameValidation = require('./gameValidation.js'); @@ -135,4 +134,4 @@ module.exports = { updateGameClient(gc); return gc; } -}; \ No newline at end of file +}; From 2a912293f3f2b90437c6d8a9f9f7ffd91e738598 Mon Sep 17 00:00:00 2001 From: Joshua Thomas Date: Thu, 26 Mar 2015 08:30:30 -0700 Subject: [PATCH 04/11] adding jshint to unit tests as well --- .jshintrc | 10 +++++++++- package.json | 2 +- test/lib/algebraicGameClient.js | 18 ++++++++++++++++-- test/lib/board.js | 2 ++ test/lib/boardValidation.js | 27 +++++++++++++-------------- test/lib/game.js | 3 +-- test/lib/gameValidation.js | 6 +++--- test/lib/pieceValidation.js | 27 ++++++++++++++------------- test/lib/simpleGameClient.js | 4 ++-- 9 files changed, 61 insertions(+), 38 deletions(-) diff --git a/.jshintrc b/.jshintrc index 504c55b..a328609 100644 --- a/.jshintrc +++ b/.jshintrc @@ -17,5 +17,13 @@ "strict" : true, "trailing" : true, "undef" : true, - "unused" : true + "unused" : true, + "globals" : { + "after" : true, + "before" : true, + "assert" : true, + "describe" : true, + "it" : true, + "requireWithCoverage": true + } } diff --git a/package.json b/package.json index 30a9afa..d28c74e 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ ], "main": "./lib/main.js", "scripts": { - "pretest": "jshint ./lib/*.js ; rm -rf lib-cov ; jscoverage lib lib-cov", + "pretest": "jshint ./lib/*.js ; jshint ./test/**/*.js ; rm -rf lib-cov ; jscoverage lib lib-cov", "test": "./node_modules/.bin/mocha --check-leaks -R spec -r ./test/common.js ./test/lib", "posttest": "NODE_CHESS_COVERAGE=true ./node_modules/.bin/mocha --check-leaks -R mocha-lcov-reporter -r ./test/common.js ./test/lib | ./node_modules/coveralls/bin/coveralls.js" }, diff --git a/test/lib/algebraicGameClient.js b/test/lib/algebraicGameClient.js index e81b145..51447e2 100644 --- a/test/lib/algebraicGameClient.js +++ b/test/lib/algebraicGameClient.js @@ -1,8 +1,12 @@ +/* jshint sub : true */ + var piece = requireWithCoverage('piece'), algebraicGameClient = requireWithCoverage('algebraicGameClient'); describe('AlgebraicGameClient', function() { + 'use strict'; + // test create and getStatus it('should have proper status once board is created', function() { var gc = algebraicGameClient.create(), @@ -519,7 +523,6 @@ describe('AlgebraicGameClient', function() { // Issue #4 - Ensure proper checkmate detection with Knight it ('should properly detect checkmate', function () { var gc = algebraicGameClient.create(), - m = null, status = null; gc.move('e4'); @@ -631,7 +634,6 @@ describe('AlgebraicGameClient', function() { // 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'); @@ -646,4 +648,16 @@ describe('AlgebraicGameClient', function() { assert.ok(s.piece === null, 'phantom piece appears after e5'); }); + + // Issue #15 - Ensure Pawn can move two spaces correctly on the first move + it ('should not block first move of two squares by Pawns incorrectly (bug fix test)', function () { + var gc = algebraicGameClient.create(); + + gc.move('e2'); + gc.move('a5'); + + console.log(gc.getStatus()); + + //gc.move('Ba6'); + }); }); diff --git a/test/lib/board.js b/test/lib/board.js index 4921586..eed1abb 100644 --- a/test/lib/board.js +++ b/test/lib/board.js @@ -3,6 +3,8 @@ var piece = requireWithCoverage('piece'); describe('Board', function() { + 'use strict'; + describe('#create()', function() { // ensure 64 squares it('should return 64 squares', function() { diff --git a/test/lib/boardValidation.js b/test/lib/boardValidation.js index 6ebaa44..b654905 100644 --- a/test/lib/boardValidation.js +++ b/test/lib/boardValidation.js @@ -1,21 +1,20 @@ var - piece = requireWithCoverage('piece'), - board = requireWithCoverage('board'), game = requireWithCoverage('game'), - pieceValidation = requireWithCoverage('pieceValidation'), boardValidation = requireWithCoverage('boardValidation'); -var getValidSquares = function(sq, validMoves) { - var i = 0; +describe('BoardValidation', function() { + 'use strict'; + + var getValidSquares = function(sq, validMoves) { + var i = 0; - for (; i < validMoves.length; i++) { - if (validMoves[i].src === sq) { - return validMoves[i].squares; + for (; i < validMoves.length; i++) { + if (validMoves[i].src === sq) { + return validMoves[i].squares; + } } - } -}; + }; -describe('BoardValidation', function() { // validate error creating BoardValidation when board is null it('should fail if validation object is created without a valid board', function() { var bv = boardValidation.create(null); @@ -333,14 +332,14 @@ describe('BoardValidation', function() { b.move('d2', 'd4'); b.move('d7', 'd5'); - bv.start(function(err, validMoves) { + bv.start(function() { assert.ok(b.getSquare('d4').piece !== null); }); b.move('b1', 'c3'); - bv.start(function(err, validMoves) { + bv.start(function() { assert.ok(b.getSquare('d4').piece !== null, 'pawn has disappeared during validation'); }); }); -}); \ No newline at end of file +}); diff --git a/test/lib/game.js b/test/lib/game.js index ad3adcc..77fbeac 100644 --- a/test/lib/game.js +++ b/test/lib/game.js @@ -1,9 +1,8 @@ var - piece = requireWithCoverage('piece'), - board = requireWithCoverage('board'), game = requireWithCoverage('game'); describe('Game', function() { + 'use strict'; // make sure there is no move history when game is created it('should have no move history when game is created', function() { diff --git a/test/lib/gameValidation.js b/test/lib/gameValidation.js index ca065ab..5ed102a 100644 --- a/test/lib/gameValidation.js +++ b/test/lib/gameValidation.js @@ -1,10 +1,10 @@ var - piece = requireWithCoverage('piece'), - board = requireWithCoverage('board'), game = requireWithCoverage('game'), gameValidation = requireWithCoverage('gameValidation'); describe('GameValidation', function() { + 'use strict'; + // validate check it('should properly indicate check', function() { var g = game.create(), @@ -244,4 +244,4 @@ describe('GameValidation', function() { assert.strictEqual(result.isStalemate, false); }); }); -}); \ No newline at end of file +}); diff --git a/test/lib/pieceValidation.js b/test/lib/pieceValidation.js index e1c7b09..06b4538 100644 --- a/test/lib/pieceValidation.js +++ b/test/lib/pieceValidation.js @@ -3,30 +3,31 @@ var piece = requireWithCoverage('piece'), pieceValidation = requireWithCoverage('pieceValidation'); -checkForSquare = function(f, r, s) { - var i = 0; +describe('PieceValidation', function() { + 'use strict'; - for (; i < s.length; i++) { - if (s[i].file === f && s[i].rank === r) { - return true; - } - } + function checkForSquare (f, r, s) { + var i = 0; - return false; -}; + for (; i < s.length; i++) { + if (s[i].file === f && s[i].rank === r) { + return true; + } + } -describe('PieceValidation', function() { + return false; + } // ensure invalid piece error is returned it('should throw exception if validation is created for wrong piece', function() { var b = board.create(), pv = pieceValidation.create(piece.PieceType.Bishop, b); - pv.start(b.getSquare('a', 2), function(err, squares) { + pv.start(b.getSquare('a', 2), function(err) { assert.strictEqual(err, 'piece is invalid'); }); - pv.start(null, function(err, squares) { + pv.start(null, function(err) { assert.strictEqual(err, 'piece is invalid'); }); }); @@ -420,4 +421,4 @@ describe('PieceValidation', function() { assert.strictEqual(sumRanks, 2+3+4+5+6+7); }); }); -}); \ No newline at end of file +}); diff --git a/test/lib/simpleGameClient.js b/test/lib/simpleGameClient.js index 91bd0cf..6d9b76f 100644 --- a/test/lib/simpleGameClient.js +++ b/test/lib/simpleGameClient.js @@ -1,8 +1,8 @@ var - piece = requireWithCoverage('piece'), simpleGameClient = requireWithCoverage('simpleGameClient'); describe('SimpleGameClient', function() { + 'use strict'; // test create and getStatus it('should properly create simple game client', function() { @@ -66,4 +66,4 @@ describe('SimpleGameClient', function() { assert.ok(b.getSquare('c5').piece === null, 'Phantom piece appears after move from c5 to c6'); }); -}); \ No newline at end of file +}); From 4987acc127f69e755808479fcc472488dc8c8a17 Mon Sep 17 00:00:00 2001 From: Joshua Thomas Date: Thu, 26 Mar 2015 08:50:26 -0700 Subject: [PATCH 05/11] minor stylistic changes to make file more readable --- lib/pieceValidation.js | 108 +++++++++++++++++++---------------------- 1 file changed, 50 insertions(+), 58 deletions(-) diff --git a/lib/pieceValidation.js b/lib/pieceValidation.js index a96aa44..2cb3330 100644 --- a/lib/pieceValidation.js +++ b/lib/pieceValidation.js @@ -10,7 +10,8 @@ board in its current state. */ -var sys = require('util'), +var + sys = require('util'), piece = require('./piece.js'), board = require('./board.js'); @@ -36,14 +37,16 @@ PieceValidation.prototype.applySpecialValidation = function () { PieceValidation.prototype.start = function (src, callback) { 'use strict'; - var err = null, + var + err = null, opt = { destSquares : [], piece : src ? src.piece : null, origin : src }, findMoveOptions = function (b, r, n) { - var block = false, + var + block = false, capture = false, currentSquare = b.getNeighborSquare(opt.origin, n), i = 0; @@ -169,22 +172,19 @@ KnightValidation.prototype.applySpecialValidation = function (opt) { 'use strict'; // add knight move options - var aboveLeft = this.board.getNeighborSquare( + var + aboveLeft = this.board.getNeighborSquare( opt.origin, - board.NeighborType.AboveLeft - ), + board.NeighborType.AboveLeft), aboveRight = this.board.getNeighborSquare( opt.origin, - board.NeighborType.AboveRight - ), + board.NeighborType.AboveRight), belowLeft = this.board.getNeighborSquare( opt.origin, - board.NeighborType.BelowLeft - ), + board.NeighborType.BelowLeft), belowRight = this.board.getNeighborSquare( opt.origin, - board.NeighborType.BelowRight - ), + board.NeighborType.BelowRight), squares = [], i = 0, p = null; @@ -192,45 +192,41 @@ KnightValidation.prototype.applySpecialValidation = function (opt) { if (aboveLeft) { squares.push(this.board.getNeighborSquare( aboveLeft, - board.NeighborType.Above - )); + board.NeighborType.Above)); + squares.push(this.board.getNeighborSquare( aboveLeft, - board.NeighborType.Left - )); + board.NeighborType.Left)); } if (aboveRight) { squares.push(this.board.getNeighborSquare( aboveRight, - board.NeighborType.Above - )); + board.NeighborType.Above)); + squares.push(this.board.getNeighborSquare( aboveRight, - board.NeighborType.Right - )); + board.NeighborType.Right)); } if (belowLeft) { squares.push(this.board.getNeighborSquare( belowLeft, - board.NeighborType.Below - )); + board.NeighborType.Below)); + squares.push(this.board.getNeighborSquare( belowLeft, - board.NeighborType.Left - )); + board.NeighborType.Left)); } if (belowRight) { squares.push(this.board.getNeighborSquare( belowRight, - board.NeighborType.Below - )); + board.NeighborType.Below)); + squares.push(this.board.getNeighborSquare( belowRight, - board.NeighborType.Right - )); + board.NeighborType.Right)); } for (i = 0; i < squares.length; i++) { @@ -263,15 +259,16 @@ PawnValidation.prototype.applySpecialValidation = function (opt) { 'use strict'; // check for capture - var squares = [ - this.board.getNeighborSquare(opt.origin, - opt.piece.side === piece.SideType.White ? - board.NeighborType.AboveLeft : - board.NeighborType.BelowLeft), - this.board.getNeighborSquare(opt.origin, - opt.piece.side === piece.SideType.White ? - board.NeighborType.AboveRight : - board.NeighborType.BelowRight)], + var + squares = [ + this.board.getNeighborSquare(opt.origin, + opt.piece.side === piece.SideType.White ? + board.NeighborType.AboveLeft : + board.NeighborType.BelowLeft), + this.board.getNeighborSquare(opt.origin, + opt.piece.side === piece.SideType.White ? + board.NeighborType.AboveRight : + board.NeighborType.BelowRight)], i = 0, sq = null, p = null; @@ -292,11 +289,8 @@ PawnValidation.prototype.applySpecialValidation = function (opt) { opt.destSquares[0], opt.piece.side === piece.SideType.White ? board.NeighborType.Above : - board.NeighborType.Below - ); + board.NeighborType.Below); - // Source of issue #15 - Pawn should be able to double-square move to avoid - // a piece that is currently able to capture it if (!sq.piece) { opt.destSquares.push(sq); } @@ -324,9 +318,7 @@ PawnValidation.prototype.applySpecialValidation = function (opt) { squares[i], p.side === piece.SideType.Black ? board.NeighborType.Above : - board.NeighborType.Below - ) - ); + board.NeighborType.Below)); } } } @@ -371,20 +363,20 @@ module.exports = { 'use strict'; switch (p) { - case piece.PieceType.Bishop: - return new BishopValidation(b); - case piece.PieceType.King: - return new KingValidation(b); - case piece.PieceType.Knight: - return new KnightValidation(b); - case piece.PieceType.Pawn: - return new PawnValidation(b); - case piece.PieceType.Queen: - return new QueenValidation(b); - case piece.PieceType.Rook: - return new RookValidation(b); - default: - return null; + case piece.PieceType.Bishop: + return new BishopValidation(b); + case piece.PieceType.King: + return new KingValidation(b); + case piece.PieceType.Knight: + return new KnightValidation(b); + case piece.PieceType.Pawn: + return new PawnValidation(b); + case piece.PieceType.Queen: + return new QueenValidation(b); + case piece.PieceType.Rook: + return new RookValidation(b); + default: + return null; } } }; From 2ee76ee829383d7baec019119772b9b1793fa925 Mon Sep 17 00:00:00 2001 From: Joshua Thomas Date: Thu, 26 Mar 2015 09:05:51 -0700 Subject: [PATCH 06/11] minor tweaks to make code more readable --- lib/algebraicGameClient.js | 41 ++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/lib/algebraicGameClient.js b/lib/algebraicGameClient.js index 0a171c5..4606bcb 100644 --- a/lib/algebraicGameClient.js +++ b/lib/algebraicGameClient.js @@ -1,4 +1,5 @@ -var piece = require('./piece.js'), +var + piece = require('./piece.js'), game = require('./game.js'), gameValidation = require('./gameValidation.js'); @@ -6,13 +7,16 @@ var piece = require('./piece.js'), var getNotationPrefix = function (src, dest, movesForPiece) { 'use strict'; - var containsDest = function (squares) { + var + containsDest = function (squares) { var n = 0; + for (n = 0; n < squares.length; n++) { if (squares[n] === dest) { return true; } } + return false; }, i = 0, @@ -61,7 +65,8 @@ var getValidMovesByPieceType = function (pieceType, validMoves) { var notate = function (validMoves, gameClient) { 'use strict'; - var algebraicNotation = {}, + var + algebraicNotation = {}, i = 0, isPromotion = false, movesForPiece = [], @@ -224,7 +229,8 @@ AlgebraicGameClient.prototype.getStatus = function (forceUpdate) { AlgebraicGameClient.prototype.move = function (notation, isFuzzy) { 'use strict'; - var move = null, + var + move = null, notationRegex = /[BKQNR]{0,1}[a-h]{0,1}[1-8]{0,1}[x]{0,1}[a-h]{1}[1-8]{1}/, p = null, promo = '', @@ -267,18 +273,18 @@ AlgebraicGameClient.prototype.move = function (notation, isFuzzy) { // apply pawn promotion if (promo) { switch (promo) { - case 'B': - p = piece.createBishop(side); - break; - case 'N': - p = piece.createKnight(side); - break; - case 'Q': - p = piece.createQueen(side); - break; - case 'R': - p = piece.createRook(side); - break; + case 'B': + p = piece.createBishop(side); + break; + case 'N': + p = piece.createKnight(side); + break; + case 'Q': + p = piece.createQueen(side); + break; + case 'R': + p = piece.createRook(side); + break; } if (p) { @@ -303,7 +309,8 @@ module.exports = { create : function (opts) { 'use strict'; - var g = game.create(), + var + g = game.create(), gc = new AlgebraicGameClient(g, opts); updateGameClient(gc); From cfeccb498f5fb6418c2f243633eb3ab5b00519e3 Mon Sep 17 00:00:00 2001 From: Joshua Thomas Date: Thu, 26 Mar 2015 09:26:02 -0700 Subject: [PATCH 07/11] updating history to denote jshint changes --- HISTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/HISTORY.md b/HISTORY.md index 32fb536..c232c71 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -2,6 +2,7 @@ ================== * adding Node v0.12 build target for Travis-CI + * enhanced jshint coverage for entire project * fixing issue where Pawn double-square move was incorrectly restricted in some scenarios where capture would have been evaded 0.2.5 / 2014-10-30 From 95900e53b5864e0a4ff30aa0c99a7de1d1a9d487 Mon Sep 17 00:00:00 2001 From: Joshua Thomas Date: Thu, 26 Mar 2015 09:26:21 -0700 Subject: [PATCH 08/11] created unit test that demonstrates failure case for #15 --- test/lib/algebraicGameClient.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/test/lib/algebraicGameClient.js b/test/lib/algebraicGameClient.js index 51447e2..06a2171 100644 --- a/test/lib/algebraicGameClient.js +++ b/test/lib/algebraicGameClient.js @@ -651,13 +651,16 @@ describe('AlgebraicGameClient', function() { // Issue #15 - Ensure Pawn can move two spaces correctly on the first move it ('should not block first move of two squares by Pawns incorrectly (bug fix test)', function () { - var gc = algebraicGameClient.create(); + var gc = algebraicGameClient.create(), + status; - gc.move('e2'); + gc.move('e4'); gc.move('a5'); - console.log(gc.getStatus()); + gc.move('Ba6'); + + status = gc.getStatus(); - //gc.move('Ba6'); + assert.isDefined(status.notatedMoves['b5'], 'Pawn able to advance two squares'); }); }); From 4e296b198c2f7cba6ab46aa6c080e220efd76c41 Mon Sep 17 00:00:00 2001 From: Joshua Thomas Date: Thu, 26 Mar 2015 09:26:59 -0700 Subject: [PATCH 09/11] minor tweaks to enhance readability of code --- lib/boardValidation.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/boardValidation.js b/lib/boardValidation.js index 260c73f..01b5e53 100644 --- a/lib/boardValidation.js +++ b/lib/boardValidation.js @@ -24,7 +24,8 @@ of what is possible anyway). */ -var piece = require('./piece.js'), +var + piece = require('./piece.js'), board = require('./board.js'), pieceValidation = require('./pieceValidation.js'); @@ -41,7 +42,8 @@ var BoardValidation = function (g) { BoardValidation.prototype.evaluateCastle = function (validMoves) { 'use strict'; - var getValidSquares = function (sq) { + var + getValidSquares = function (sq) { var i = 0; for (i = 0; i < validMoves.length; i++) { @@ -120,7 +122,8 @@ BoardValidation.prototype.evaluateCastle = function (validMoves) { BoardValidation.prototype.filterKingAttack = function (kingSquare, moves) { 'use strict'; - var i = 0, + var + i = 0, isCheck = false, n = 0, r = null, @@ -168,7 +171,8 @@ BoardValidation.prototype.isSquareAttacked = function (sq) { return false; } - var setAttacked = function (c) { + var + setAttacked = function (c) { return function (err, squares) { if (!err) { var i = 0; @@ -224,7 +228,8 @@ BoardValidation.prototype.isSquareAttacked = function (sq) { return context.attacked; }; - return isAttacked(this.board, board.NeighborType.Above) || + return ( + isAttacked(this.board, board.NeighborType.Above) || isAttacked(this.board, board.NeighborType.AboveRight) || isAttacked(this.board, board.NeighborType.Right) || isAttacked(this.board, board.NeighborType.BelowRight) || @@ -241,7 +246,7 @@ BoardValidation.prototype.isSquareAttacked = function (sq) { isAttackedByKnight(this.board, board.NeighborType.KnightBelowLeft) || isAttackedByKnight(this.board, board.NeighborType.KnightLeftBelow) || isAttackedByKnight(this.board, board.NeighborType.KnightAboveLeft) || - isAttackedByKnight(this.board, board.NeighborType.KnightLeftAbove); + isAttackedByKnight(this.board, board.NeighborType.KnightLeftAbove)); }; // begin evaluation of the valid moves for an entire board From 6b7156ba72a2981f4166c148037a93f35bb842f2 Mon Sep 17 00:00:00 2001 From: Joshua Thomas Date: Thu, 26 Mar 2015 09:27:17 -0700 Subject: [PATCH 10/11] introducing fix for #15 --- lib/pieceValidation.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/pieceValidation.js b/lib/pieceValidation.js index 2cb3330..0d28d97 100644 --- a/lib/pieceValidation.js +++ b/lib/pieceValidation.js @@ -273,6 +273,7 @@ PawnValidation.prototype.applySpecialValidation = function (opt) { sq = null, p = null; + // check for capture for (i = 0; i < squares.length; i++) { // check for enemy piece on square p = squares[i] ? squares[i].piece : null; @@ -283,7 +284,7 @@ PawnValidation.prototype.applySpecialValidation = function (opt) { // check for double square first move if (opt.piece.moveCount === 0 && - opt.destSquares.length === 1 && + opt.destSquares.length && // Fix for issue #15 (originally looked for length of 1) opt.destSquares[0].piece === null) { // Fix for issue #1 sq = this.board.getNeighborSquare( opt.destSquares[0], From df52b4fafcc5c825448c7ba2c927e3535334215c Mon Sep 17 00:00:00 2001 From: Joshua Thomas Date: Thu, 26 Mar 2015 09:27:40 -0700 Subject: [PATCH 11/11] 0.2.6 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d28c74e..c576daa 100644 --- a/package.json +++ b/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.5", + "version": "0.2.6", "author": "Joshua Thomas (http://github.com/brozeph)", "engine": "node >= 0.8.1", "repository": {