function Tipbox(tips, origin) {
	if(origin.row === 1) {
		this.getRow = rowFromIndexReverse;
	} else if(origin.row === 8) {
		this.getRow = rowFromIndex;
	} else {
		throw "UnknownStartPositionException: \"" + origin.row + "\"";
	}
	if(origin.column === 1) {
		this.getColumn = columnFromIndexReverse;
	} else if(origin.column === 12) {
		this.getColumn = columnFromIndex;
	} else {
		throw "UnknownStartPositionException: \"" + origin.column + "\"";
	}
	this.tipCount = parseInt(tips, 10) || 0;
	this.hasTip = function() {
		return this.tipCount > 0;
	}
	this.isEmpty = function() {
		return this.tipCount < 1;
	}
	// Methods takeTip and putTip returns the position of the lower
	// right-most tip and updates 'tipCount' if "successful":
	this.takeTip = function() {
		var tip = new Array(2);
		// Find the "last" tip:
		tip[0] = this.getRow(this.tipCount);
		tip[1] = this.getColumn(this.tipCount);
		if(tip[0] > 0 && tip[1] > 0) {
			this.tipCount--;
		} else {
			tip = undefined;
		}
		return tip;
	}
	this.putTip = function() {
		var temp = this.tipCount + 1;
		var tip = new Array(2);
		// Find the "last" empty position:
		tip[0] = this.getRow(temp);
		tip[1] = this.getColumn(temp);
		if(tip[1] < 13 && tip[0] > 0 && tip[1] > 0) {
			this.tipCount++;
		} else {
			tip = undefined;
		}
		return tip;
	}
	// The following methods allow getting coords without incrementation:
	this.getNextTipPosition =  function() {
		var tip = new Array(2);
		// Find the "last" tip:
		tip[0] = this.getRow(this.tipCount);
		tip[1] = this.getColumn(this.tipCount);
		if(tip[0] < 1 || tip[1] < 1) {
			tip = undefined;
		}
		return tip;
	}
	this.getNextEmptyPosition = function() {
		var temp = this.tipCount + 1;
		var tip = new Array(2);
		// Find the "last" empty position:
		tip[0] = this.getRow(temp);
		tip[1] = this.getColumn(temp);
		if(tip[1] > 12 || tip[0] < 1 || tip[1] < 1) {
			tip = undefined;
		}
		return tip;
	}
	this.increment = function() {
		this.tipCount++;
	}
	this.decrement = function() {
		this.tipCount--;
	}
}
/*
 Tipbox class to track single-tip usage. Tips are taken/placed column-wise
 starting from {row,column} given in 'origin', where row is 1 or 8 and column
 is 1 or 12
*/
Tipbox class to track single-tip usage. Tips are taken/placed column-wise
starting from {row,column} given in 'origin', where row is 1 or 8 and column
is 1 or 12
Tipbox class to track single - tip usage . Tips are taken / placed column - wise starting from { row column } given in ' origin ' where row is 1 or 8 and column is 1 or 12
function Tipbox(tips, origin) {
	if(origin.row === 1) {
		this.getRow = rowFromIndexReverse;
	} else if(origin.row === 8) {
		this.getRow = rowFromIndex;
	} else {
		throw "UnknownStartPositionException: \"" + origin.row + "\"";
	}
	if(origin.column === 1) {
		this.getColumn = columnFromIndexReverse;
	} else if(origin.column === 12) {
		this.getColumn = columnFromIndex;
	} else {
		throw "UnknownStartPositionException: \"" + origin.column + "\"";
	}
	this.tipCount = parseInt(tips, 10) || 0;
	this.hasTip = function() {
		return this.tipCount > 0;
	}
	this.isEmpty = function() {
		return this.tipCount < 1;
	}
	this.takeTip = function() {
		var tip = new Array(2);
		tip[0] = this.getRow(this.tipCount);
		tip[1] = this.getColumn(this.tipCount);
		if(tip[0] > 0 && tip[1] > 0) {
			this.tipCount--;
		} else {
			tip = undefined;
		}
		return tip;
	}
	this.putTip = function() {
		var temp = this.tipCount + 1;
		var tip = new Array(2);
		tip[0] = this.getRow(temp);
		tip[1] = this.getColumn(temp);
		if(tip[1] < 13 && tip[0] > 0 && tip[1] > 0) {
			this.tipCount++;
		} else {
			tip = undefined;
		}
		return tip;
	}
	this.getNextTipPosition =  function() {
		var tip = new Array(2);
		tip[0] = this.getRow(this.tipCount);
		tip[1] = this.getColumn(this.tipCount);
		if(tip[0] < 1 || tip[1] < 1) {
			tip = undefined;
		}
		return tip;
	}
	this.getNextEmptyPosition = function() {
		var temp = this.tipCount + 1;
		var tip = new Array(2);
		tip[0] = this.getRow(temp);
		tip[1] = this.getColumn(temp);
		if(tip[1] > 12 || tip[0] < 1 || tip[1] < 1) {
			tip = undefined;
		}
		return tip;
	}
	this.increment = function() {
		this.tipCount++;
	}
	this.decrement = function() {
		this.tipCount--;
	}
}
function Tipbox ( tips , origin ) { if ( origin . row === 1 ) { this . getRow = rowFromIndexReverse ; } else if ( origin . row === 8 ) { this . getRow = rowFromIndex ; } else { throw "UnknownStartPositionException: \"" + origin . row + "\"" ; } if ( origin . column === 1 ) { this . getColumn = columnFromIndexReverse ; } else if ( origin . column === 12 ) { this . getColumn = columnFromIndex ; } else { throw "UnknownStartPositionException: \"" + origin . column + "\"" ; } this . tipCount = parseInt ( tips , 10 ) || 0 ; this . hasTip = function ( ) { return this . tipCount > 0 ; } this . isEmpty = function ( ) { return this . tipCount < 1 ; } this . takeTip = function ( ) { var tip = new Array ( 2 ) ; tip [ 0 ] = this . getRow ( this . tipCount ) ; tip [ 1 ] = this . getColumn ( this . tipCount ) ; if ( tip [ 0 ] > 0 && tip [ 1 ] > 0 ) { this . tipCount -- ; } else { tip = undefined ; } return tip ; } this . putTip = function ( ) { var temp = this . tipCount + 1 ; var tip = new Array ( 2 ) ; tip [ 0 ] = this . getRow ( temp ) ; tip [ 1 ] = this . getColumn ( temp ) ; if ( tip [ 1 ] < 13 && tip [ 0 ] > 0 && tip [ 1 ] > 0 ) { this . tipCount ++ ; } else { tip = undefined ; } return tip ; } this . getNextTipPosition = function ( ) { var tip = new Array ( 2 ) ; tip [ 0 ] = this . getRow ( this . tipCount ) ; tip [ 1 ] = this . getColumn ( this . tipCount ) ; if ( tip [ 0 ] < 1 || tip [ 1 ] < 1 ) { tip = undefined ; } return tip ; } this . getNextEmptyPosition = function ( ) { var temp = this . tipCount + 1 ; var tip = new Array ( 2 ) ; tip [ 0 ] = this . getRow ( temp ) ; tip [ 1 ] = this . getColumn ( temp ) ; if ( tip [ 1 ] > 12 || tip [ 0 ] < 1 || tip [ 1 ] < 1 ) { tip = undefined ; } return tip ; } this . increment = function ( ) { this . tipCount ++ ; } this . decrement = function ( ) { this . tipCount -- ; } }
Tipbox class to track single-tip usage.
Tipbox class to track single - tip usage .
// Methods takeTip and putTip returns the position of the lower // right-most tip and updates 'tipCount' if "successful": // Find the "last" tip: // Find the "last" empty position: // The following methods allow getting coords without incrementation: // Find the "last" tip: // Find the "last" empty position: