tests/lib/ludorum.js
/** Many games based on board configurations (like connection games) have 
	patterns that can be expressed with regular expressions. The method 
	`asRegExp(line, insideLine, outsideLine)` takes a line (iterable of 
	coordinates) and returns a string with a regular expression. This may be 
	used to tests the whole board string for the line.
	
	_Warning!_ Both `insideLine` and `outsideLine` must be simple regular 
	expressions (e.g. a character or atom). If more complex expressions are
	required they must be provided between parenthesis.
	*/
Many games based on board configurations (like connection games) have
patterns that can be expressed with regular expressions. The method
`asRegExp(line, insideLine, outsideLine)` takes a line (iterable of
coordinates) and returns a string with a regular expression. This may be
used to tests the whole board string for the line.

_Warning!_ Both `insideLine` and `outsideLine` must be simple regular
expressions . If more complex expressions are
required they must be provided between parenthesis.
Many games based on board configurations ( like connection games ) have patterns that can be expressed with regular expressions . The method ` asRegExp ( line insideLine outsideLine ) ` takes a line ( iterable of coordinates ) and returns a string with a regular expression . This may be used to tests the whole board string for the line . _Warning!_ Both ` insideLine ` and ` outsideLine ` must be simple regular expressions . If more complex expressions are required they must be provided between parenthesis .
function asRegExp(line, insideLine, outsideLine) {
		outsideLine = outsideLine || '.';
		var width = this.width,
			squares = Iterable.repeat(false, width * this.height).toArray();
		line.forEach(function (coord) {
			squares[coord[0] * width + coord[1]] = true;
		});
		var result = '', count = 0, current;
		for (var i = 0; i < squares.length; count = 0) {
			current = squares[i];
			do {
				++count;
			} while (++i < squares.length && squares[i] === current);
			if (count < 2) {
				result += current ? insideLine : outsideLine;
			} else {
				result += (current ? insideLine : outsideLine) +'{'+ count +'}';
			}
		}
		return result;
	}
function asRegExp ( line , insideLine , outsideLine ) { outsideLine = outsideLine || '.' ; var width = this . width , squares = Iterable . repeat ( false , width * this . height ) . toArray ( ) ; line . forEach ( function ( coord ) { squares [ coord [ 0 ] * width + coord [ 1 ] ] = true ; } ) ; var result = '' , count = 0 , current ; for ( var i = 0 ; i < squares . length ; count = 0 ) { current = squares [ i ] ; do { ++ count ; } while ( ++ i < squares . length && squares [ i ] === current ) ; if ( count < 2 ) { result += current ? insideLine : outsideLine ; } else { result += ( current ? insideLine : outsideLine ) + '{' + count + '}' ; } } return result ; }
Many games based on board configurations (like connection games) have
patterns that can be expressed with regular expressions.
Many games based on board configurations ( like connection games ) have patterns that can be expressed with regular expressions .