Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Remove unused file; game.putPieces with first test

  • Loading branch information...
commit b4668294dfa22811dcaa21e44bf669a553ff944a 1 parent c26fc7c
@ajlopez authored
Showing with 35 additions and 15 deletions.
  1. +0 −15 lib/board.js
  2. +6 −0 lib/simplechess.js
  3. +29 −0 test/game.js
View
15 lib/board.js
@@ -1,15 +0,0 @@
-
-var simplechess = require('../'),
- assert = require('assert');
-
-// create board
-
-var board = simplechess.createBoard();
-assert.ok(board);
-assert.equal(board.getWidth(), 8);
-assert.equal(board.getHeight(), 8);
-
-var positions = board.getPositions();
-
-assert.ok(positions);
-assert.equal(positions.length, 0);
View
6 lib/simplechess.js
@@ -46,6 +46,12 @@ var simplechess = (function () {
this.getPieceMoves = function (color, piece, x, y) {
return Moves[piece](board, x, y, color);
};
+
+ this.putPieces = function (pieces) {
+ pieces.forEach(function (piece) {
+ board.putContent(piece.x, piece.y, { color: piece.color, piece: piece.piece });
+ });
+ }
this.inCheck = function (color) {
var kingposition = board.findPosition(function(content) { return content.color == color && content.piece == Piece.King; });
View
29 test/game.js
@@ -7,6 +7,9 @@ var simplechess = require('../'),
assert.ok(simplechess.White);
assert.ok(simplechess.Black);
+var White = simplechess.White;
+var Black = simplechess.Black;
+
// Pieces defined
assert.ok(simplechess.Rook);
@@ -40,3 +43,29 @@ for (var k in positions) {
assert.equal(nwhite, 16);
assert.equal(nblack, 16);
+// create game with empty board and put pieces
+
+var board = simplechess.createBoard();
+var game = simplechess.createGame(board);
+
+game.putPieces([{ x: 3, y: 3, color: White, piece: simplechess.Rook },
+ { x: 4, y: 4, color: Black, piece: simplechess.Bishop }]);
+
+var positions = game.getPositions();
+
+assert.ok(positions);
+assert.equal(positions.length, 2);
+
+var nwhite = 0;
+var nblack = 0;
+
+for (var k in positions) {
+ var position = positions[k];
+ if (position.content.color === simplechess.White)
+ nwhite++;
+ else if (position.content.color == simplechess.Black)
+ nblack++;
+}
+
+assert.equal(nwhite, 1);
+assert.equal(nblack, 1);
Please sign in to comment.
Something went wrong with that request. Please try again.