"use strict";

var assert = require('assert');

var Board = function(rows) {
    this.legalMoves = function(turn) {

	var moves = [];

	for (var i=0;i<rows.length;++i) {
	    for (var j=0;j<rows[i].length;++j) {
		if (rows[i][j] === '-') {
		    moves.push({row: i, col: j});
		}
	    }
	}

	return moves;
    };

    return this;
};

var createBoard = function(rows) {
    return new Board(rows);
};

describe('reversi', function() {
    it('should create a board', function() {
	var board = createBoard(['BW','BW']);
	assert(board !== undefined);
    });

    it('should return no valid moves', function() {
	var board = createBoard(['BW',
				 'BW']);

	assert.equal(0, board.legalMoves('B').length);
    });

    it('should return the single valid move', function() {
	var board = createBoard(['BW-',
				 'BBB',
				 'BBB'], 'B');

	assert.equal(1, board.legalMoves().length);
    });

    it('should not return any valid moves', function() {
	var board = createBoard(['BW-',
				 'BBB',
				 'BBB'], 'W');

	assert.equal(0, board.legalMoves().length);
    });
});

@@ -66,24 +66,100 @@
 ion(rows) %7B%0A
+%0A    this.isValidMove = function(i,j) %7B%0A%09return rows%5Bi%5D%5Bj%5D === '-';%0A    %7D;%0A%0A
     this.leg
@@ -236,18 +236,16 @@
 gth;++i)
- %7B
 %0A%09    fo
@@ -280,38 +280,38 @@
 ++j)
- %7B
 %0A%09%09if (
-rows%5Bi%5D%5Bj%5D === '-'
+this.isValidMove(i,j)
 ) 
-%7B
 %0A%09%09 
@@ -346,22 +346,8 @@
 j%7D);
-%0A%09%09%7D%0A%09    %7D%0A%09%7D
 %0A%0A%09r

refactor (naughty with a failing test, but localized)