function Player(stone, config) {

	this.stoneMine = stone;
	this.stoneOther = (stone == 1) ? 2 : 1;
	
	this.config = config;
	if(this.config == null)
		this.config = {};
	if(this.config.absScoreWeight == undefined)
		this.config.absScoreWeight = 1.0;
		
	if(this.config.myLibertiesDiffWeight == undefined)
		this.config.myLibertiesDiffWeight = 0.1;

	if(this.config.otherLibertiesDiffWeight == undefined)
		this.config.otherLibertiesDiffWeight = 0.1;
		
	if(this.config.touchingWeight == undefined)
		this.config.touchingWeight = 0.1;
	if(this.config.eyesWeight == undefined)
		this.config.eyesWeight = 0.1;//0.4;
	if(this.config.aliveWeight == undefined)
		this.config.aliveWeight = 0.01;//0.9;
	if(this.config.randomWeight == undefined)
		this.config.randomWeight = 0.0000001;
}


//returns null (pass) or a position
Player.prototype.chooseMove = function(board) {
	var player = this;

	//rate all positions
	board.eachInt(function(i) {
		i.rating = player.evalMove(board, i);
	});

	//choose best position
	var pos = null;
	var bestRating = -1;
	board.eachInt(function(i) {
		if(i.rating > bestRating) {
			pos = i.pos;
			bestRating = i.rating;
		}
	});
	return pos;
};

//evalMove must be non-destructive
Player.prototype.evalMove = function(board, i) {
	var rating = -1;

	//don't even think about occupied intersections
	if(i.stone != 0) {
		return rating;
	}
	
	
	var nextBoard = board.clone();
	
	var startingAbsScore = board.scoreByStone[this.stoneMine] - board.scoreByStone[this.stoneOther];
	var startingAbsEyes = board.eyesByStone[this.stoneMine] - board.eyesByStone[this.stoneOther];
	var startingAbsAlive = board.aliveCountByStone[this.stoneMine] - board.aliveCountByStone[this.stoneOther];
	var startingMyLiberties = board.libertiesByStone[this.stoneMine];
	var startingOtherLiberties = board.libertiesByStone[this.stoneOther];
	
	var nextAbsScore;
	var nextAbsEyes;
	var nextAbsAlive;
	//if we can make the move, evaluate it
	if(nextBoard.makeMove(i.pos, this.stoneMine)) {
		//rate based on score
		nextAbsScore = nextBoard.scoreByStone[this.stoneMine] - nextBoard.scoreByStone[this.stoneOther];
		nextAbsEyes = nextBoard.eyesByStone[this.stoneMine] - nextBoard.eyesByStone[this.stoneOther];
		nextAbsAlive = nextBoard.aliveCountByStone[this.stoneMine] - nextBoard.aliveCountByStone[this.stoneOther];
	
		if(nextAbsScore >= startingAbsScore) {
			rating = 0;
			rating = (nextAbsScore - startingAbsScore) * this.config.absScoreWeight;
			//rate based on liberties count
			rating += (nextBoard.libertiesByStone[this.stoneMine] - startingMyLiberties)
				* this.config.myLibertiesDiffWeight;
			rating += (startingOtherLiberties - nextBoard.libertiesByStone[this.stoneOther])
				* this.config.otherLibertiesDiffWeight;
			//rate based on how many stones it's touching before this move (either color)
			rating += nextBoard.getTouching(i, true).length * this.config.touchingWeight;
			//rate based on eyes
			rating += (nextAbsEyes - startingAbsEyes) * this.config.eyesWeight;
			//rate based on alive
			//alert('startingAbsAlive:' + startingAbsAlive + ', nextAbsAlive:' + nextAbsAlive + ', this.config.aliveWeight:' + this.config.aliveWeight);
			rating += (nextAbsAlive - startingAbsAlive) * this.config.aliveWeight;
			//rate based on a little random
			rating -= Math.random() * this.config.randomWeight;
			//? longer chains are better
			//? 'alive' stones (2+ eyes)
			//? 'nearly alive' stones (one eye)
			//? how do you know if a stone is dead, or a territory is fully captured?
			//?     no way to make 2 full eyes inside
			//?     minimum territory size of 8? 
		}
	}
	
	return rating;
};
